I want to globally rename every node in an XML element by appending the existing name with a suffix.
The current XSLT I wrote below works, but loses element values. How do I keep the values?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="suffix" select="'_Ver1'"/>
<xsl:template match="node()">
<xsl:element name="{concat(local-name(.), $suffix)}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
It’s because
node()also includes text nodes. If your input XML had any line-breaks, you may have noticed elements like<_Ver1/>in your output.Try something like this instead:
I’ve added a template for
text()and also acopy-offor any attributes that might be in the XML.