Java XSLT:转换递归和可重复的Xml
接收一个递归的xml文件是一个像这样的遗留应用程序Java XSLT:转换递归和可重复的Xml,java,xml,xslt,Java,Xml,Xslt,接收一个递归的xml文件是一个像这样的遗留应用程序 <ResponseXml> <AccountData> <AccountInformation> <AccountNumber>123465</AccountNumber> <BankCode>456</BankCode> <OwnerInformation> <FirstName>
<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>
123465
456
希曼苏
亚达夫
78910
123
我的
妻子
必须将其格式化为:
<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>
123465
456
希曼苏
亚达夫
78910
123
我的
妻子
作为XSLT转换的新手,我遇到了多个问题:
递归部分的部分解。它不排除根元素
由于您使用的是标识模板,因此您必须覆盖该模板,以便对任何要执行操作的元素执行操作。在这种情况下,如果您只需要删除
ResponseXml
和AccountData
元素,那么您只需为它们创建一个空模板
<xsl:template match="ResponseXml | AccountData">
<xsl:apply-templates/>
</xsl:template>
将上述行添加到XSL后,它将不会输出这两个元素 请展示您迄今为止所做的尝试。@JimGarrison我已经添加了部分解决方案来处理xml的递归部分。但是我不知道如何排除每个孩子
元素。你认为我处理这个问题的方法正确吗?谢谢。有没有关于复制子元素的想法?@HimanshuYadav我忽略了这样一个事实,即它不会输出子元素。我已经更新了答案,以显示如何删除元素并继续处理子元素。
<xsl:template match="ResponseXml | AccountData">
<xsl:apply-templates/>
</xsl:template>