Template Design A Stylesheet That Generates a Stylesheet That Emulates a for Loop

page 76 This approach works, but were doing an awful lot of work to create some fairly simple elements. For all the XSLT elements were generating with xsl:element elements, we have to declare the namespace for each one. The obvious way of handling this would be to generate a namespace declaration on the xsl:stylesheet element: xsl:attribute name=xmlns:xsl http:www.w3.org1999XSLTransform xsl:attribute Unfortunately, the XSLT specification states in section 7.1.3 that this isnt legal. What we did in our previous example was add the namespace attribute to all XSLT elements we need to generate. The XSLT processor is not required to use the namespace prefix we specified in the xsl:element , by the way. To help us get around this awkward problem, the XSLT specification provides the xsl:namespace-alias element. This provision allows us to define an alias for the XSLT namespace or any other namespace we want to use; well use the normal XSLT namespace for the stylesheet elements we use, and well use the alias for the stylesheet elements we generating. Heres how our new stylesheet looks: ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http:www.w3.org1999XSLTransform xmlns:xslout=can be anything, doesnt matter xsl:output method=xml indent=yes xsl:namespace-alias stylesheet-prefix=xslout result-prefix=xsl xsl:template match=||text|comment|processing-instruction xsl:copy xsl:apply-templates select=||text|comment|processing-instruction xsl:copy xsl:template xsl:template match=for-loop xslout:call-template name=for-loop xslout:with-param name=i select={index-variable} xslout:with-param name=increment select={increment} xslout:with-param name=operator xsl:attribute name=select xsl:textxsl:text xsl:value-of select=operator xsl:textxsl:text xsl:attribute xslout:with-param xslout:with-param name=testValue select={test-value} xslout:call-template xsl:template xsl:template match=for-loop mode=generate-template xslout:variable name=newline xslout:text xslout:text xslout:variable xslout:template name=for-loop xslout:param name=i select=index-variable xslout:param name=increment select=increment xslout:param name=operator select=operator xslout:param name=testValue select=test-value xslout:param name=iteration select=1 xslout:variable name=testPassed xslout:choose xslout:when test=starts-withoperator, = xslout:if test=i = testValue xslout:texttruexslout:text