Xslt 在重复节点的最后一个子节点之后添加xml节点

Xslt 在重复节点的最后一个子节点之后添加xml节点,xslt,Xslt,我需要在重复节点的最后一个子节点之后添加一个节点 我有一个带有节点参数的XML,它是ripetive 我需要在参数的最后一个节点之后添加一个节点 这是我的档案: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <SyncPulseTask releaseID="10.1.3" xmlns="http://schema.infor.com/InforOAGIS/2"> <ApplicationArea>

我需要在重复节点的最后一个子节点之后添加一个节点 我有一个带有节点参数的XML,它是ripetive 我需要在参数的最后一个节点之后添加一个节点

这是我的档案:

<?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>mike.tollan@sharelnk30.net</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>mike.tollan@sharelnk30.net</ID>
                </IDs>
            </PersonReference>
        </AssignedPerson>           
        <DistributionPerson>
            <ID>768</ID>
            <PersonReference>
                <IDs>
                    <ID>mike.tollan@sharelnk30.net</ID>
                </IDs>
                <Name>Mike Tollan</Name>
                <SystemUserIndicator>true</SystemUserIndicator>
            </PersonReference>
        </DistributionPerson>
    </PulseTask>
</DataArea>
</SyncPulseTask>`
基本上,我需要添加AssignedPerson节点 我该怎么做


谢谢你

因为你有一个默认的名称空间,你应该给它加前缀,说“test”,然后在xpath中使用这个前缀

xmlns:test="http://schema.infor.com/InforOAGIS/2"
首先,您需要一个标识模板

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


试着这样做:

<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>mike.tollan@sharelnk30.net</ID>
            </IDs>
        </PersonReference>
    </AssignedPerson>         
</xsl:template>

</xsl:stylesheet>

迈克。tollan@sharelnk30.net

我相信您可以将其缩小一点(本着的精神)。另外,请包括您当前的XSLT代码。您还可以在XSLT中第二次添加名称空间作为默认名称空间。这样,您就不需要在XSL元素中具有namespace属性。嗨,我不需要覆盖,我需要在最后一个参数节点和DistributionPerson之间添加AssignedPerson节点node@MarkVeenstra,说得好。我现在正在编辑我的答案。zanza67,我的意思是覆盖。@zanza67请澄清:在最后一个
参数
之后是否总是有
DistributionPerson
?欢迎使用Stackoverflow。如果您认为此答案有用,请勾选左侧箭头下方的复选标记,使其显示为绿色。通过这种方式,其他用户可以知道这是公认的答案。请注意,此
[last()]
不适用于libxslt。
<?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>
<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>mike.tollan@sharelnk30.net</ID>
            </IDs>
        </PersonReference>
    </AssignedPerson>         
</xsl:template>

</xsl:stylesheet>