i am trying to write XSLT mapping copy parent value to child nodes, ContainerCode — > Serialshippingcontianercode value we need to pass to its subnodes under new tag , i have written XSLT but it is giving empty values for that segment, not giving any values for that segment.Please help me on this..
i attached sample input and output as below. Please check.
Input:
<?xml version="1.0" encoding="UTF-8"?><StandardBusinessDocument>
<receivingAdvice >
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>1234</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>45678</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>686</IdentificationValue>
<IdentificationType>SUPP</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** Desired Output:**
<?xml version="1.0" encoding="UTF-8"?><StandardBusinessDocument>
<receivingAdvice >
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>ContainerCode123</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>ContainerCode123</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>ContainerCode123</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>secondcontianercode</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>686</IdentificationValue>
<IdentificationType>SUPP</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>secondcontianercode</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** XSLT I used is below:**
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LogisticUnitLineItem">
<xsl:copy>
<xsl:apply-templates select="ContainmentLine"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LogisticUnitLineItem">
<xsl:copy>
<Identification>
<IdentificationValue><xsl:value-of select="/serialShippingContainerCode"/></IdentificationValue>
<IdentificationType>PAL</IdentificationType>
<xsl:apply-templates select="Identification"/>
</Identification>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Please assist here.
New contributor
CHAR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.