简体   繁体   中英

remove root tag from xml using xslt

I have an xml file like this

<root>
<level1>data</level1>
<level1>data</level1>
.
.
.
<level1>data</level1>
<level1>data</level1>
</root>

I want to remove the root tag using xslt. can anyone help me? my problem is that I have multi level 1 data.

thanks for any help

If you're sure that's what you want to do, you could do it simply by:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/root">
    <xsl:copy-of select="node()"/>
</xsl:template>

</xsl:stylesheet>

However, I cannot stress this strongly enough: the result in your example will be an XML fragment , not a well-formed XML document .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM