【发布时间】:2016-01-18 08:22:18
【问题描述】:
我正在尝试编写 XSLT 代码以将前缀命名空间添加到除少数节点之外的所有节点。
示例 XML:
<BatchPrepareDeliverArchive xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="schema">
<BatchInformation>
<RqUId>424000000071256187550913330</RqUId>
<BatchFeedId>CMLTREXT4240</BatchFeedId>
<BatchCount>7</BatchCount>
</BatchInformation>
<BatchDeliverArchive>
<Transactions>
<Transaction>
<TransactionUUID>90022016-01-140000001</TransactionUUID>
<CustomerData>
<GBD_Transactions>
<GBD_Transaction>
<Common_Data>
<Transaction_ID>90022016-01-140000001</Transaction_ID>
</Common_Data>
<Templates>
<Template>
<Template_Name>A21_LETTER_FINAL_NOTICE_OF_CANCELLATION_TPA</Template_Name>
<Transaction_ID>90022016-01-140000001</Transaction_ID>
</Template>
</Templates>
</GBD_Transaction>
</GBD_Transactions>
</CustomerData>
<DocInfo>
<Name>OPERATION NAME</Name>
</DocInfo>
</Transaction>
</Transactions>
</BatchDeliverArchive>
</BatchPrepareDeliverArchive>
我想为所有节点添加 urn 前缀,除了 GBD_Transactions 及其子元素。
我想出了这个 XSLT:
<xsl:stylesheet version="1.0" xmlns:urn="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="urn:{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:element name="urn:{local-name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
所有节点都在此处进行转换,这不是预期的输出。 非常感谢您对此的任何帮助!
【问题讨论】: