I am new to XSLT transformation and got stuck with this recursive mapping.
<
This should do the job:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Copy everything -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Template handling the top-level 'Element1' -->
<xsl:template match="Element1">
<Information>
<!-- Apply the copy template to all sub-elements except 'Element1' -->
<xsl:apply-templates select="*[name()!='Element1']"/>
</Information>
<!-- Apply the templates to the 'Element1' sub-elements -->
<xsl:apply-templates select="Element1"/>
</xsl:template>
<!-- Template handling the inner 'Element1' -->
<xsl:template match="Element1/Element1">
<Metadata>
<xsl:apply-templates/>
</Metadata>
</xsl:template>
</xsl:stylesheet>
As Tim notes the result is not a valid XML because it has two root elements. To generate an extra root
element to make the output valid XML add this template:
<xsl:template match="/">
<root>
<xsl:apply-templates></xsl:apply-templates>
</root>
</xsl:template>