2014-09-30 80 views
0

最後一個孩子後,添加XML節點,我需要一個重複的節點 的最後一個子節點我有節點參數的XML是ripetitive後添加一個節點 我需要的最後一個節點後添加一個節點參數重複性節點

這是我的文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<SyncPulseTask releaseID="10.1.3" xmlns="http://schema.infor.com/InforOAGIS/2"> 
<ApplicationArea> 
    <Sender> 
     <LogicalID>infor.engine.pulse</LogicalID> 
     <ConfirmationCode>OnError</ConfirmationCode> 
    </Sender> 
    <CreationDateTime>2014-09-29T15:47:05.080Z</CreationDateTime> 
</ApplicationArea> 
<DataArea> 
    <Sync> 
     <TenantID>infor</TenantID> 
     <ActionCriteria> 
      <ActionExpression actionCode="Add"/> 
     </ActionCriteria> 
    </Sync> 
    <PulseTask> 
     <DocumentID> 
      <ID variationID="1">756</ID> 
     </DocumentID> 
     <CreationDateTime>2014-09-29T15:47:04Z</CreationDateTime> 
     <LastModificationDateTime>2014-09-29T15:47:05Z</LastModificationDateTime> 
     <Status> 
      <Code>NEW</Code> 
     </Status> 
     <EscalationLevel>0</EscalationLevel> 
     <Priority>MEDIUM</Priority> 
     <Description>Generate Pulse BOD</Description> 
     <Source> 
      <Type>WORKFLOW</Type> 
      <Name>LN_DA_ProjectContractLine</Name> 
      <Version>46.0</Version> 
     </Source> 
     <Parameter sequence="1"> 
      <Name>Contract</Name> 
      <Value>CON000089</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="2"> 
      <Name>ContractAmount</Name> 
      <Value>1.0</Value> 
      <DataType>DECIMAL</DataType> 
      <Label>Contract Amount</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="3"> 
      <Name>ContractCurrency</Name> 
      <Value>GBP</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Currency</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="4"> 
      <Name>ContractLine</Name> 
      <Value>0030</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Line</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="5"> 
      <Name>ContractManager</Name> 
      <Value>RDKORTE</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Manager</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="6"> 
      <Name>ContractManagerName</Name> 
      <Value>Ron de Korte</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Manager Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="7"> 
      <Name>ExternalSalesRepName</Name> 
      <Value>Jan Slag</Value> 
      <DataType>STRING</DataType> 
      <Label>External Sales Rep Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="8"> 
      <Name>ExternalSalesRepresentative</Name> 
      <Value>JSLAG</Value> 
      <DataType>STRING</DataType> 
      <Label>External Sales Representative</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="9"> 
      <Name>InternalSalesRepName</Name> 
      <Value>James Rea</Value> 
      <DataType>STRING</DataType> 
      <Label>Internal Sales Rep Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="10"> 
      <Name>InternalSalesRepresentative</Name> 
      <Value>JREA</Value> 
      <DataType>STRING</DataType> 
      <Label>Internal Sales Representative</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="11"> 
      <Name>LogicalId</Name> 
      <Value>lid://infor.ln.infor_ln_10_3_1_company_512</Value> 
      <DataType>STRING</DataType> 
      <Label>Logical Id</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="12"> 
      <Name>SalesOffice</Name> 
      <Value>SBASUK</Value> 
      <DataType>STRING</DataType> 
      <Label>Sales Office</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="13"> 
      <Name>SoldToBPName</Name> 
      <Value>BAES CS&amp;S</Value> 
      <DataType>STRING</DataType> 
      <Label>Sold To BPName</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="14"> 
      <Name>SoldToBusinessPartner</Name> 
      <Value>K0999</Value> 
      <DataType>STRING</DataType> 
      <Label>Sold To Business Partner</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="15"> 
      <Name>SoldToContact</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Sold To Contact</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="16"> 
      <Name>SoldToContactName</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Sold To Contact Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="17"> 
      <Name>Status</Name> 
      <Value>20</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="18"> 
      <Name>StatusBeforeOnHold</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Status Before On Hold</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="19"> 
      <Name>StatusOld</Name> 
      <Value>0</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status Old</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="20"> 
      <Name>StatusOldName</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Status Old Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="21"> 
      <Name>StatusPreviousOld</Name> 
      <Value>0</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status Previous Old</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="22"> 
      <Name>SubmitUser</Name> 
      <Value>infor20</Value> 
      <DataType>STRING</DataType> 
      <Label>Submit User</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="23"> 
      <Name>TaskUser</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Task User</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="24"> 
      <Name>WF_Reason</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>WF Reason</Label> 
      <ReadOnlyIndicator>false</ReadOnlyIndicator> 
     </Parameter> 
     <DistributionPerson> 
      <ID>768</ID> 
      <PersonReference> 
       <IDs> 
        <ID>[email protected]</ID> 
       </IDs> 
       <Name>Mike Tollan</Name> 
       <SystemUserIndicator>true</SystemUserIndicator> 
      </PersonReference> 
     </DistributionPerson> 
    </PulseTask> 
</DataArea> 
</SyncPulseTask>` 

,這就是我將不得不

`<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<SyncPulseTask releaseID="10.1.3" xmlns="http://schema.infor.com/InforOAGIS/2"> 
<ApplicationArea> 
    <Sender> 
     <LogicalID>infor.engine.pulse</LogicalID> 
     <ConfirmationCode>OnError</ConfirmationCode> 
    </Sender> 
    <CreationDateTime>2014-09-29T15:47:05.080Z</CreationDateTime> 
</ApplicationArea> 
<DataArea> 
    <Sync> 
     <TenantID>infor</TenantID> 
     <ActionCriteria> 
      <ActionExpression actionCode="Add"/> 
     </ActionCriteria> 
    </Sync> 
    <PulseTask> 
     <DocumentID> 
      <ID variationID="1">756</ID> 
     </DocumentID> 
     <CreationDateTime>2014-09-29T15:47:04Z</CreationDateTime> 
     <LastModificationDateTime>2014-09-29T15:47:05Z</LastModificationDateTime> 
     <Status> 
      <Code>NEW</Code> 
     </Status> 
     <EscalationLevel>0</EscalationLevel> 
     <Priority>MEDIUM</Priority> 
     <Description>Generate Pulse BOD</Description> 
     <Source> 
      <Type>WORKFLOW</Type> 
      <Name>LN_DA_ProjectContractLine</Name> 
      <Version>46.0</Version> 
     </Source> 
     <Parameter sequence="1"> 
      <Name>Contract</Name> 
      <Value>CON000089</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="2"> 
      <Name>ContractAmount</Name> 
      <Value>1.0</Value> 
      <DataType>DECIMAL</DataType> 
      <Label>Contract Amount</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="3"> 
      <Name>ContractCurrency</Name> 
      <Value>GBP</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Currency</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="4"> 
      <Name>ContractLine</Name> 
      <Value>0030</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Line</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="5"> 
      <Name>ContractManager</Name> 
      <Value>RDKORTE</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Manager</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="6"> 
      <Name>ContractManagerName</Name> 
      <Value>Ron de Korte</Value> 
      <DataType>STRING</DataType> 
      <Label>Contract Manager Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="7"> 
      <Name>ExternalSalesRepName</Name> 
      <Value>Jan Slag</Value> 
      <DataType>STRING</DataType> 
      <Label>External Sales Rep Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="8"> 
      <Name>ExternalSalesRepresentative</Name> 
      <Value>JSLAG</Value> 
      <DataType>STRING</DataType> 
      <Label>External Sales Representative</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="9"> 
      <Name>InternalSalesRepName</Name> 
      <Value>James Rea</Value> 
      <DataType>STRING</DataType> 
      <Label>Internal Sales Rep Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="10"> 
      <Name>InternalSalesRepresentative</Name> 
      <Value>JREA</Value> 
      <DataType>STRING</DataType> 
      <Label>Internal Sales Representative</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="11"> 
      <Name>LogicalId</Name> 
      <Value>lid://infor.ln.infor_ln_10_3_1_company_512</Value> 
      <DataType>STRING</DataType> 
      <Label>Logical Id</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="12"> 
      <Name>SalesOffice</Name> 
      <Value>SBASUK</Value> 
      <DataType>STRING</DataType> 
      <Label>Sales Office</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="13"> 
      <Name>SoldToBPName</Name> 
      <Value>BAES CS&amp;S</Value> 
      <DataType>STRING</DataType> 
      <Label>Sold To BPName</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="14"> 
      <Name>SoldToBusinessPartner</Name> 
      <Value>K0999</Value> 
      <DataType>STRING</DataType> 
      <Label>Sold To Business Partner</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="15"> 
      <Name>SoldToContact</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Sold To Contact</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="16"> 
      <Name>SoldToContactName</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Sold To Contact Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="17"> 
      <Name>Status</Name> 
      <Value>20</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="18"> 
      <Name>StatusBeforeOnHold</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Status Before On Hold</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="19"> 
      <Name>StatusOld</Name> 
      <Value>0</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status Old</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="20"> 
      <Name>StatusOldName</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Status Old Name</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="21"> 
      <Name>StatusPreviousOld</Name> 
      <Value>0</Value> 
      <DataType>INTEGER</DataType> 
      <Label>Status Previous Old</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="22"> 
      <Name>SubmitUser</Name> 
      <Value>infor20</Value> 
      <DataType>STRING</DataType> 
      <Label>Submit User</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="23"> 
      <Name>TaskUser</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>Task User</Label> 
      <ReadOnlyIndicator>true</ReadOnlyIndicator> 
     </Parameter> 
     <Parameter sequence="24"> 
      <Name>WF_Reason</Name> 
      <Value/> 
      <DataType>STRING</DataType> 
      <Label>WF Reason</Label> 
      <ReadOnlyIndicator>false</ReadOnlyIndicator> 
     </Parameter> 
     <AssignedPerson> 
      <PersonReference> 
       <IDs> 
        <ID>[email protected]</ID> 
       </IDs> 
      </PersonReference> 
     </AssignedPerson>   
     <DistributionPerson> 
      <ID>768</ID> 
      <PersonReference> 
       <IDs> 
        <ID>[email protected]</ID> 
       </IDs> 
       <Name>Mike Tollan</Name> 
       <SystemUserIndicator>true</SystemUserIndicator> 
      </PersonReference> 
     </DistributionPerson> 
    </PulseTask> 
</DataArea> 
</SyncPulseTask>` 

基本上我甲腎上腺素編輯添加AssignedPerson節點 我該怎麼做?

謝謝

+0

我相信你可以調整大小下來一點(在[這裏](HTTP的精神: //stackoverflow.com/help/mcve))。另外,請包含您當前的XSLT代碼。 – 2014-09-30 11:01:00

回答

0

既然你有一個默認的命名空間,你應該前綴這一點,說「測試」,後來在XPath中使用這個前綴

xmlns:test="http://schema.infor.com/InforOAGIS/2" 

首先,你需要一個身份模板

<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

然後,覆蓋DistributionPerson節點以包含所需的節點:

<xsl:template match="test:DistributionPerson"> 
    <AssignedPerson> 
     <PersonReference> 
      <xsl:apply-templates select="test:PersonReference/test:IDs"/> 
     </PersonReference> 
    </AssignedPerson> 
    <xsl:copy> 
     <xsl:apply-templates/> 
    </xsl:copy> 
</xsl:template> 

樣式

<xsl:stylesheet version="1.0" 
    xmlns="http://schema.infor.com/InforOAGIS/2" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:test="http://schema.infor.com/InforOAGIS/2" 
    exclude-result-prefixes="test"> 

    <xsl:output method="xml" indent="yes"/> 
    <xsl:strip-space elements="*"/> 


    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="test:DistributionPerson"> 
     <AssignedPerson> 
      <PersonReference> 
       <xsl:apply-templates select="test:PersonReference/test:IDs"/> 
      </PersonReference> 
     </AssignedPerson> 
     <xsl:copy> 
      <xsl:apply-templates/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 
+0

您也可以在XSLT中第二次添加名稱空間作爲默認值。這樣你就不需要在XSL元素中有名稱空間屬性。 – 2014-09-30 11:15:11

+0

嗨,我不需要覆蓋,我需要添加AssignedPerson節點之間的最後一個參數節點和DistributionPerson節點 – zanza67 2014-09-30 11:17:32

+0

@MarkVeenstra,好點。我正在編輯我的答案。 zanza67,我的意思是覆蓋。 – 2014-09-30 11:23:57

0
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:agis="http://schema.infor.com/InforOAGIS/2" exclude-result-prefixes="agis"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <xsl:template match="@* | node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="agis:Parameter[last()]"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()" /> 
     </xsl:copy> 
     <AssignedPerson> 
      <PersonReference> 
       <IDs> 
        <ID><xsl:value-of select="following-sibling::agis:DistributionPerson/agis:PersonReference/agis:IDs/agis:ID" /></ID> 
       </IDs> 
      </PersonReference> 
     </AssignedPerson> 
    </xsl:template> 
</xsl:stylesheet> 
+1

請注意,這個'[last()]'不適用於libxslt。 – 2014-09-30 11:22:06

1

試試這樣說:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns="http://schema.infor.com/InforOAGIS/2" 
xmlns:a="http://schema.infor.com/InforOAGIS/2" 
exclude-result-prefixes="a"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="a:Parameter[not(following-sibling::a:Parameter)]"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    <AssignedPerson> 
     <PersonReference> 
      <IDs> 
       <ID>[email protected]</ID> 
      </IDs> 
     </PersonReference> 
    </AssignedPerson>   
</xsl:template> 

</xsl:stylesheet>