zanza67
zanza67

Reputation: 223

adding xml node after last child for repetitive node

I need to add a node after the last child node of a repetitive node I have an XML with node Parameter that is ripetitive I need to add a node after the last node of Parameter

This is my file:

<?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>`

and this is what i would have

`<?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>`

basically i need to add the AssignedPerson node how can i do that?

thank you

Upvotes: 0

Views: 1122

Answers (3)

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

Since you have a default namespace, you should prefix this, say "test" and use this prefix later in xpath

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

First, you need an identity template

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

Then, override the DistributionPerson node to include the node that you want:

<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>

Stylesheet

<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>

Upvotes: 0

michael.hor257k
michael.hor257k

Reputation: 116993

Try it this way:

<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>

Upvotes: 1

Mark Veenstra
Mark Veenstra

Reputation: 4739

<?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>

Upvotes: 0

Related Questions