This will work with any level of items cd.
You need to change the bit to create the structure <html>(s <head/><body>...</body>), it may be in the template match='node'.
He will skip empty trailing <td/>, which is not needed for rendering.
XSL
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="node">
<xsl:element name="table">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="cd">
<xsl:element name="tr">
<xsl:for-each select="ancestor::cd">
<xsl:element name="td"/>
</xsl:for-each>
<xsl:element name="td">
<xsl:value-of select="./data/@value" />
</xsl:element>
</xsl:element>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Output
<table>
<tr><td>cd1-0</td></tr>
<tr><td/><td>cd1-1</td></tr>
<tr><td/><td>cd1-2</td></tr>
<tr><td>cd2-0</td></tr>
</table>
source
share