I am trying to write an XSLT to check if <identification>, which has <identificationType> as Type10 or not, if it exist and <identificationValue> length is less than or equal to 5 then Identificationvalue we need to replace with <serialShippingContainerCode>, if identificationType=Type10 not exist then we need to create one with identificationvalue taking from Serialshippingcontainercode.
XSLT i have used is only copying header to child if it not exist, Please assist here once
Input:
<StandardBusinessDocument>
<receivingAdvice>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>121212345890</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>Type8</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>4567</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value2</IdentificationValue>
<IdentificationType>Type8</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>1309089485</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>86432509</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>6867</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** Desired Output:**
<StandardBusinessDocument>
<receivingAdvice>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>121212345890</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>Type8</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>121212345890</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value2</IdentificationValue>
<IdentificationType>Type8</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>121212345890</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>1309089485</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>86432509</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>1309089485</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** XSLT I used is below:**
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Identification[last()][not(contains(IdentificationType, 'Type10'))]">
<xsl:copy-of select="."/>
<xsl:copy>
<IdentificationValue>
<xsl:value-of select="ancestor::LogisticUnitLineItem/logisticUnitIdentification/ContainerCode/serialShippingContainerCode"/>
</IdentificationValue>
<IdentificationType>Type10</IdentificationType>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>