<xsl:template match="/">
<xsl:apply-templates select="//*[not(*)]"/>
</xsl:template>
<xsl:template match="*">
<row>
<xsl:for-each select="ancestor-or-self::*">
<xsl:attribute name="{name()}">
<xsl:value-of select="@name"/>
</xsl:attribute>
</xsl:for-each>
</row>
</xsl:template>
Not tested
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference