You haven't given enough information to provide concrete code, but in XSLT 2.0 you can do
Code:
<xsl:for-each select="1 to $N">
....
</xsl:for-each>
In XSLT 1.0 the usual trick for doing this is
Code:
<xsl:for-each select="(//node())[position <= $N]">
....
</xsl:for-each>
which works so long as there are at least $N nodes in your input document.