仅复制标签的值而不是排序时的所有标签
Copying only tags' values rather than all tags on sorting
我有 xml 需要按 2 个标签排序:Type 和 NonRecurringCharges。 Type标签的值不是唯一的(我的xml中有2个Product)。任何产品中都可能缺少 NonRecurringCharges 标签。我有一个 XLT 模板,但它排序和复制标签的值而不是标签。
希望有人能提供帮助。
XML:
<ContractSummary>
<OrderInfo>
<IsMobileOnly>false</IsMobileOnly>
</OrderInfo>
<Offerings>
<Type>Product</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>OneTimeService</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>Product</Type>
<Name Language="ZFR">Enlvement</Name>
</Offerings></ContractSummary>
XSLT:
<xsl:template match="ContractSummary">
<xsl:copy>
<xsl:apply-templates select="@* | *[not(self::Offerings)]" />
<xsl:apply-templates select="Offerings">
<xsl:sort select="Type" />
<xsl:sort select="NonRecurringCharges" />
</xsl:apply-templates>
</xsl:copy> </xsl:template>
结果,我有 xml:
<ContractSummary>falseOneTimeServiceCable AccessPostPaidCAAC0001ProductEnlvementProductCable AccessPostPaidCAAC0001</ContractSummary>
我需要xml:
<ContractSummary>
<OrderInfo>
<IsMobileOnly>false</IsMobileOnly>
</OrderInfo>
<Offerings>
<Type>OneTimeService</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>Product</Type>
<Name Language="ZFR">Enlvement</Name>
</Offerings>
<Offerings>
<Type>Product2</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings></ContractSummary>
添加身份转换作为基本步骤,例如在 XSLT 3 中通过声明 <xsl:mode on-no-match="shallow-copy"/>
或在 XSLT 1 和 2 中通过添加模板
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
我有 xml 需要按 2 个标签排序:Type 和 NonRecurringCharges。 Type标签的值不是唯一的(我的xml中有2个Product)。任何产品中都可能缺少 NonRecurringCharges 标签。我有一个 XLT 模板,但它排序和复制标签的值而不是标签。
希望有人能提供帮助。
XML:
<ContractSummary>
<OrderInfo>
<IsMobileOnly>false</IsMobileOnly>
</OrderInfo>
<Offerings>
<Type>Product</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>OneTimeService</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>Product</Type>
<Name Language="ZFR">Enlvement</Name>
</Offerings></ContractSummary>
XSLT:
<xsl:template match="ContractSummary">
<xsl:copy>
<xsl:apply-templates select="@* | *[not(self::Offerings)]" />
<xsl:apply-templates select="Offerings">
<xsl:sort select="Type" />
<xsl:sort select="NonRecurringCharges" />
</xsl:apply-templates>
</xsl:copy> </xsl:template>
结果,我有 xml:
<ContractSummary>falseOneTimeServiceCable AccessPostPaidCAAC0001ProductEnlvementProductCable AccessPostPaidCAAC0001</ContractSummary>
我需要xml:
<ContractSummary>
<OrderInfo>
<IsMobileOnly>false</IsMobileOnly>
</OrderInfo>
<Offerings>
<Type>OneTimeService</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings>
<Offerings>
<Type>Product</Type>
<Name Language="ZFR">Enlvement</Name>
</Offerings>
<Offerings>
<Type>Product2</Type>
<Name Language="NL">Cable Access</Name>
<NonRecurringCharges>
<Type>PostPaid</Type>
<ThirdPartyFinancingId>CAAC0001</ThirdPartyFinancingId>
</NonRecurringCharges>
</Offerings></ContractSummary>
添加身份转换作为基本步骤,例如在 XSLT 3 中通过声明 <xsl:mode on-no-match="shallow-copy"/>
或在 XSLT 1 和 2 中通过添加模板
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>