<p>I have a simple xml document that looks like the following snippet. I need to write a XSLT transform that basically 'unpivots' this document based on some of the attributes.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;root xmlns:z="foo"&gt;
    &lt;z:row A="1" X="2" Y="n1" Z="500"/&gt;
    &lt;z:row A="2" X="5" Y="n2" Z="1500"/&gt;
&lt;/root&gt;
</code></pre>

<p>This is what I expect the output to be -</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;root xmlns:z="foo"&gt;
    &lt;z:row A="1" X="2"  /&gt;
    &lt;z:row A="1" Y="n1" /&gt;
    &lt;z:row A="1" Z="500"/&gt;
    &lt;z:row A="2" X="5" /&gt;
    &lt;z:row A="2" Y="n2"/&gt;
    &lt;z:row A="2" Z="1500"/&gt;
&lt;/root&gt;
</code></pre>

<p>Appreciate your help.</p>

Here is a bit of a brute force way:
```
```
<xsl:template match="z:row">
    <xsl:element name="z:row">
        <xsl:attribute name="A">
            <xsl:value-of select="@A"/>
        </xsl:attribute>
        <xsl:attribute name="X">
            <xsl:value-of select="@X"/>
        </xsl:attribute>
    </xsl:element>
    <xsl:element name="z:row">
        <xsl:attribute name="A">
            <xsl:value-of select="@A"/>
        </xsl:attribute>
        <xsl:attribute name="Y">
            <xsl:value-of select="@Y"/>
        </xsl:attribute>
    </xsl:element>
    <xsl:element name="z:row">
        <xsl:attribute name="A">
            <xsl:value-of select="@A"/>
        </xsl:attribute>
        <xsl:attribute name="Z">
            <xsl:value-of select="@Z"/>
        </xsl:attribute>
    </xsl:element>
</xsl:template>

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