No additional namespaces are required below. The solution contains a template called iterate , which is called internally and which updates $length and $i respectively:
XSLT
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <root> <xsl:call-template name="iterate"/> </root> </xsl:template> <xsl:template name="iterate"> <xsl:param name="length" select="5"/> <xsl:param name="i" select="1"/> <pos><xsl:value-of select="$i"/></pos> <xsl:if test="$length > 1"> <xsl:call-template name="iterate"> <xsl:with-param name="length" select="$length - 1"/> <xsl:with-param name="i" select="$i + 1"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
Exit
<?xml version="1.0" encoding="UTF-8"?> <root> <pos>1</pos> <pos>2</pos> <pos>3</pos> <pos>4</pos> <pos>5</pos> </root>
source share