XML
<?xml-stylesheet type="text/xsl" href="script.xsl"?>
<elements>
<stack>
<name>Ray</name>
<status>0</status>
</stack>
<!-- Comment 1 -->
<things>
<!-- Comment 2 -->
<thing>
<color>red</color>
<!-- State Comment -->
<state>solid</state>
<!-- Weight Comment -->
<weight>45</weight>
<unit>34</unit>
<!-- Comment 3 -->
</thing>
</things>
<favs>
<stick>ready</stick>
<!-- Comment 4-->
</favs>
</elements>
EXPECTED OUTPUT
<elements>
<stack>
<name>Ray</name>
<status>0</status>
</stack>
<!-- Comment 1 -->
<mainElements>
<!-- Comment 2 -->
<specialThing>
<!-- Weight Comment -->
<PropertyOne>45</PropertyOne>
<PropertyTwo>red</PropertyTwo>
<!-- State Comment -->
<PropertyThree>solid</PropertyThree>
</specialThing>
<!-- Comment 3 -->
</mainElements>
<favs>
<stick>ready</stick>
<!-- Comment 4-->
</favs>
</elements>
CURRENT XSL
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="things">
<mainElements>
<xsl:apply-templates select="thing"/>
</mainElements>
</xsl:template>
<xsl:template match="thing">
<specialThing>
<xsl:apply-templates select="weight"/>
<xsl:apply-templates select="color"/>
<xsl:apply-templates select="state"/>
</specialThing>
</xsl:template>
<xsl:template match="weight">
<PropertyOne>
<xsl:value-of select="."/>
</PropertyOne>
</xsl:template>
<xsl:template match="color">
<PropertyTwo>
<xsl:value-of select="."/>
</PropertyTwo>
</xsl:template>
<xsl:template match="state">
<PropertyThree>
<xsl:value-of select="."/>
</PropertyThree>
</xsl:template>
</xsl:stylesheet>
I was not able to indent the output properly as i mentioned in the output. But the main thing i want to achieve is to maintain the comments of the tags which are maintained in the output.
eg: the tag named weight is renamed to "PropertyOne" and the value is also maintained in the output. But the comment above the same is missing. I want to keep the comment of the same in the output also. How can i achieve that?