2014-09-30 161 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>