In XSLT 2.0,
<xsl:for-each select="1 to /sm/MaxLevel">
<th>Level<xsl:value-of select="."/></th>
</xsl:for-each>
In 1.0 this is ridiculously difficult. Either (a) write a template that outputs Level1 and then calls itself to output the remaining levels, passing two parameters: the current level and the level at which to stop; or (b), if there are sufficient nodes in the input document, do
<xsl:for-each select="//node()[position() < /sm/MaxLevel]">
<th>Level<xsl:value-of select="position()"/></th>
</xsl:for-each>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference