如何将 XML 文档的树结构分解为所需的一种..? [英] How to break the tree structure of the XML document to desired one ..?
本文介绍了如何将 XML 文档的树结构分解为所需的一种..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编写 XSLT 代码以实现我想要的输出对我来说是一个巨大的挑战.
这是我的 XML 输入 .. 我正在测试 ..
It has been a great challenge for me to code XSLT to bring my desired output ..
Here is my XML input .. which I am testing on ..
<aaa id="1">
<bbb id="2">text1</bbb>
<ccc>text2</ccc>
<ddd id="3">
<eee att="4d">text3</eee>
<fff>
<ggg att="3d">
<yyy>text4</yyy>
<iii attr="jj"/>
</ggg>
</fff>
<sss>
<ttt info="Y">
<nnn delete="N">
<mmm>text5</mmm>
</nnn>
</ttt>
</sss>
</ddd>
</aaa>
所需的输出:
<root>
<aaa id="1"/>
<bbb id="2">text1</bbb>
<ccc>text2</ccc>
<ddd id="3"/>
<eee att="4d">text3</eee>
<fff/>
<ggg att="3d"/>
<yyy>text4</yyy>
<iii attr="jj"/>
<sss/>
<ttt info="Y"/>
<nnn delete="N"/>
<mmm>text5</mmm>
</root>
我无法编写通用代码..我的意思是,我的代码必须能够为具有不同标签名称的不同 XML 文件提供类似的输出..
I am not able to write generalised code .. I mean, My code must be able to give similar output for different XML file with different tag names ..
推荐答案
类似的事情?
<xsl:template match="/">
<root>
<xsl:apply-templates select="*"/>
</root>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*|text()"/>
</xsl:copy>
<xsl:apply-templates select="*"/>
</xsl:template>
这篇关于如何将 XML 文档的树结构分解为所需的一种..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文