I'm trying to transform my XML to an HTML table but still quite confused with how to do row-column mapping using templates. My XML definition is:
<Table>
<Parent>
<Head>Header 1</Head>
<Children>
<Node>Node 1</Node>
<Node>Node 2</Node>
<Node>Node 3</Node>
</Children>
</Parent>
<Parent>
<Head>Header 2</Head>
<Children>
<Node>Node 4</Node>
<Node>Node 5</Node>
<Node>Node 6</Node>
</Children>
</Parent>
</Table>
Expected HTML output:
<table>
<tr>
<td>Header 1</td>
<td>Header 2</td>
</tr>
<tr>
<td>Node 1</td>
<td>Node 4</td>
</tr>
<tr>
<td>Node 2</td>
<td>Node 5</td>
</tr>
<tr>
<td>Node 3</td>
<td>Node 6</td>
</tr>
</table>
I've used template matching but can't figure out how to do the mapping by position. This is my current XSLT code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Table">
<table>
<tr>
<xsl:apply-templates select="Parent"/>
</tr>
<xsl:apply-templates select="Parent/Children"/>
</table>
</xsl:template>
<xsl:template match="Parent">
<td>
<xsl:value-of select="Head"/>
</td>
</xsl:template>
<xsl:template match="Parent/Children">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="Parent/Children/Node">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
</xsl:stylesheet>