XSLT

Convert attributes to elements in XSLT

I was working on some reporting stuff and thought I had an issue where I needed to have elements instead of attributes. I found that the following XSLT would do that conversion for me.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
 
<xsl:template match="@*">
<xsl:element name="{name()}"><xsl:value-of select="."/></xsl:element>
</xsl:template>

<xsl:template match="/ | @* |node()">
<xsl:copy>
<xsl:apply-templates select="* | @* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

view rawgistfile1.xslt hosted with ❤ by GitHub

Turns out that I didn’t need it, but I figured it would be handy to keep around.

XSLT

Related Blog