[英]XSLT: Transforming Recursive and Repeatable Xml
像这样的传统应用程序接收递归xml
<ResponseXml>
<AccountData>
<AccountInformation>
<AccountNumber>123465</AccountNumber>
<BankCode>456</BankCode>
<OwnerInformation>
<FirstName>Himanshu</FirstName>
<LastName>Yadav</LastName>
</OwnerInformation>
<AccountInformation>
<AccountNumber>78910</AccountNumber>
<BankCode>123</BankCode>
<OwnerInformation>
<FirstName>My</FirstName>
<LastName>Wife</LastName>
</OwnerInformation>
</AccountInformation>
</AccountInformation>
</AccountData>
</ResponseXml>
它必须格式化为:
<BillingInformation>
<AccountNumber>123465</AccountNumber>
<BankCode>456</BankCode>
</BillingInformation>
<ClientInfo>
<FirstName>Himanshu</FirstName>
<LastName>Yadav</LastName>
</ClientInfo>
<BillingInformation2>
<AccountNumber>78910</AccountNumber>
<BankCode>123</BankCode>
</BillingInformation2>
<ClientInfo>
<FirstName>My</FirstName>
<LastName>Wife</LastName>
</ClientInfo>
作为XSLT转换的新手,我遇到了多个问题:
到目前为止尝试过。
递归部分的部分解决方案。 它不排除根元素<ResponseXml><AccountData>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="AccountInformation">
<BillingInformation>
<xsl:apply-templates select="*[name()!='AccountInformation']"/>
</BillingInformation>
<xsl:apply-templates select="AccountInformation"/>
</xsl:template>
<xsl:template match="AccountInformation/AccountInformation">
<BillingInformation2>
<xsl:apply-templates/>
</BillingInformation2>
</xsl:template>
由于您使用的是身份模板,因此您必须为要操作的任何元素覆盖该模板。 在这种情况下,如果您只需要删除ResponseXml
和AccountData
元素,则只需为它们都创建一个空模板。
<xsl:template match="ResponseXml | AccountData">
<xsl:apply-templates/>
</xsl:template>
将上述行添加到XSL后,它将不会输出这两个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.