I have a simple XML, that I want to add a new root to. The current root is <myFields>
and I want to add <myTable>
so it would look like.
<myTable>
<myFields>
.
.
</myFields>
</myTable>
I have a simple XML, that I want to add a new root to. The current root is <myFields>
and I want to add <myTable>
so it would look like.
<myTable>
<myFields>
.
.
</myFields>
</myTable>
Something like this should work for you...
<xsl:template match="/">
<myTable>
<xsl:apply-templates/>
</myTable>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
you helped get me close enough
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="myTable">
<xsl:copy-of select="*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
This is probably the shortest solution :) :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<myTable>
<xsl:copy-of select="node()" />
</myTable>
</xsl:template>
</xsl:stylesheet>
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<myTable>
<xsl:call-template name="identity"/>
</myTable>
</xsl:template>
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Note: Copy everything (also PIs before root element), and add myTable
befere root element.