我正在尝试编写 XSLT 映射以将父值复制到子节点,ContainerCode - > Serialshippingcontianercode 值我们需要传递给新标签下的子节点<identification>
,但如果该标签已经存在,则无需复制该段,因为其下存在其他值。我现有的 XSLT 正在将 containercode 值复制到所有段。请帮助我。
我附上了以下示例输入和输出。请检查。
输入:
<StandardBusinessDocument>
<receivingAdvice>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>ContainerCode123</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>ContainerCode456</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>ContainerCode2nd</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>686</IdentificationValue>
<IdentificationType>SUPP</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** 期望输出:**
<StandardBusinessDocument>
<receivingAdvice>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>ContainerCode123</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<IdentificationValue>ContainerCode456</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
<ContainmentLine number="2">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>Value1</IdentificationValue>
<IdentificationType>New1</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>ContainerCode123</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
<LogisticUnitLineItem>
<logisticUnitIdentification>
<ContainerCode>
<serialShippingContainerCode>ContainerCode2nd</serialShippingContainerCode>
</ContainerCode>
</logisticUnitIdentification>
<ContainmentLine number="1">
<containedItemIdentification>
<gtin>00000000000000</gtin>
<Identification>
<IdentificationValue>686</IdentificationValue>
<IdentificationType>SUPP</IdentificationType>
</Identification>
<Identification>
<IdentificationValue>ContainerCode2nd</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</Identification>
</containedItemIdentification>
</ContainmentLine>
</LogisticUnitLineItem>
</receivingAdvice>
</StandardBusinessDocument>
** 我使用的 XSLT 如下:**
<?xml version="1.0" encoding="UTF-8"?>
<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="LogisticUnitLineItem">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="serialShippingContainerCode" select="logisticUnitIdentification/ContainerCode/serialShippingContainerCode/text()" tunnel="yes"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="Identification[last()]">
<xsl:param name="serialShippingContainerCode" tunnel="yes"/>
<!-- Copy just the current node -->
<xsl:copy-of select="."/>
<xsl:copy>
<IdentificationValue>
<xsl:value-of select="$serialShippingContainerCode"/>
</IdentificationValue>
<IdentificationType>PAL</IdentificationType>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>