>how to approach the simple problem of i=i+1?
That isn't your problem, that's what your solution to the problem would be in a procedural language.
The simplest way of doing fixed-size groups in XSLT is probably:
<xsl:for-each select="row[position() mod $N = 1]">
<tr>
<xsl:for-each select=". | following-sibling::row[position() < $N]">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
The more general solution (needed for example if your criteria for starting a new group depend on the data you encounter) involves recursion, which is a technique you need to master to become a proficient XSLT programmer. Read all about it in your favourite XSLT textbook...
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference