I have xml like follows,
<table>
<tbody>
<tr>
<th>Test table head col 1</th>
<th><span>Test table head col 2</span></th>
<th><span>Test table head col 3</span></th>
</tr>
<tr>
<td>Row 1 Column 1</td>
<td>Row 1 Column 2</td>
<td>Row 1 Column 3</td></tr>
<tr>
<td>Row 2 Column 1</td>
<td>Row 2 Column 2</td>
<td>Row 2 Column 3</td>
</tr>
<tr>
<td>Row 3 Column 1</td>
<td>Row 3 Column 2</td>
<td>Row 3 Column 4</td>
</tr>
</tbody>
</table>
using XSLT I have to get the following output from above xml,
<table>
<thead>
<row>
<entry namest="1">
<p type="Table head">Test table head col 1</p>
</entry>
<entry namest="2">
<p type="Table head">Test table head col 2</p>
</entry>
<entry namest="3">
<p type="Table head">Test table head col 3</p>
</entry>
</row>
</thead>
<tbody>
<row>
<entry namest="1" align="left">
<p type="Table text">Row 1 Column 1</p>
</entry>
<entry namest="2" align="left">
<p type="Table text">Row 1 Column 2</p>
</entry>
<entry namest="3" align="left">
<p type="Table text">Row 1 Column 3</p>
</entry>
</row>
<row>
<entry namest="1" align="left">
<p type="Table text">Row 2 Column 1</p>
</entry>
<entry namest="2" align="left">
<p type="Table text">Row 2 Column 2</p>
</entry>
<entry namest="3" align="left">
<p type="Table text">Row 2 Column 3</p>
</entry>
</row>
<row>
<entry namest="1" align="left">
<p type="Table text">Row 3 Column 1</p>
</entry>
<entry namest="2" align="left">
<p type="Table text">Row 3 Column 2</p>
</entry>
<entry namest="3" align="left">
<p type="Table text">Row 3 Column 4</p>
</entry>
</row>
</tbody>
</table>
to get that output I've written following xsl,
<xsl:template match="tbody/tr[1]">
<thead>
<row>
<xsl:for-each select="th">
<entry namest="{position()}">
<p type="Table head"><xsl:apply-templates/></p>
</entry>
</xsl:for-each>
</row>
</thead>
</xsl:template>
<xsl:template match="tbody/tr[not(position()=1)]">
<tbody>
<row>
<xsl:for-each select="td">
<entry namest="{position()}" align="left">
<p type="Table text"><xsl:apply-templates/></p>
</entry>
</xsl:for-each>
</row>
</tbody>
</xsl:template>
But it adds <tbody> to every <tr> nodes. How can I modify my code to add only one <tbody> element to cover <tr> elements from second element to final element as my expected output ?