This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pnumRows" select="3"/>
<xsl:variable name="vnumCells" select="count(/*/*/NAME)"/>
<xsl:variable name="vcellsPerRow"
select="ceiling($vnumCells div $pnumRows)"/>
<xsl:template match="node2">
<table>
<xsl:apply-templates select="NAME[position() mod $vcellsPerRow = 1]"/>
</table>
</xsl:template>
<xsl:template match="NAME">
<tr>
<xsl:apply-templates mode="copy" select=
". | following-sibling::*[not(position() >= $vcellsPerRow)]"/>
</tr>
</xsl:template>
<xsl:template match="NAME" mode="copy">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
when performed on any XML document with the specified format, such as the following:
<node1>
<node2>
<NAME>name1</NAME>
<NAME>name2</NAME>
<NAME>name3</NAME>
<NAME>name4</NAME>
<NAME>name5</NAME>
<NAME>name6</NAME>
<NAME>name7</NAME>
<NAME>name8</NAME>
<NAME>name9</NAME>
<NAME>name10</NAME>
</node2>
</node1>
produces the wanted result: a table with three rows, where the first two rows have the same number of cells and the last row may be shorter:
<table>
<tr>
<td>name1</td>
<td>name2</td>
<td>name3</td>
<td>name4</td>
</tr>
<tr>
<td>name5</td>
<td>name6</td>
<td>name7</td>
<td>name8</td>
</tr>
<tr>
<td>name9</td>
<td>name10</td>
</tr>
</table>