开发者

How to break the tree structure of the XML document to desired one ..?

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>

The desired output :

<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>

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 ..


Something like this?

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜