The Complete Example A Stylesheet That Emulates a for Loop
page 73 xsl:variable name=testPassed
xsl:choose xsl:when test=starts-withoperator, =
xsl:if test=i = testValue xsl:texttruexsl:text
xsl:if xsl:when
xsl:when test=starts-withoperator, = xsl:if test=i = testValue
xsl:texttruexsl:text xsl:if
xsl:when xsl:when test=starts-withoperator, =
xsl:if test=i = testValue xsl:texttruexsl:text
xsl:if xsl:when
xsl:when test=starts-withoperator, = xsl:if test=i = testValue
xsl:texttruexsl:text xsl:if
xsl:when xsl:when test=starts-withoperator,
xsl:if test=i testValue xsl:texttruexsl:text
xsl:if xsl:when
xsl:when test=starts-withoperator, xsl:if test=i testValue
xsl:texttruexsl:text xsl:if
xsl:when xsl:otherwise
xsl:message terminate=yes xsl:textSorry, the for-loop emulator only xsl:text
xsl:texthandles six operators xsl:text xsl:value-of select=newline
xsl:text | | = | = | = | =. xsl:text xsl:textThe value xsl:text
xsl:value-of select=operator xsl:text is not allowed.xsl:text
xsl:value-of select=newline xsl:message
xsl:otherwise xsl:choose
xsl:variable xsl:if test=testPassed=true
-- Put your logic here, whatever it might be. For the purpose -- -- of our example, well just write some text to the output stream. --
xsl:textIteration xsl:textxsl:value-of select=iteration xsl:text: i=xsl:text
xsl:value-of select=ixsl:value-of select=newline -- Your logic should end here; dont change the rest of this --
-- template -- -- Now for the important part: we increment the index variable and --
-- loop. Notice that were passing the incremented value, not -- -- changing the variable itself. --
xsl:call-template name=for-loop xsl:with-param name=i select=i + increment
xsl:with-param name=increment select=increment xsl:with-param name=operator select=operator
xsl:with-param name=testValue select=testValue xsl:with-param name=iteration select=iteration + 1
page 74 xsl:call-template
xsl:if xsl:template
xsl:template match= xsl:call-template name=for-loop
xsl:with-param name=i select=10 xsl:with-param name=increment select=-2
xsl:with-param name=operator select= xsl:with-param name=testValue select=0
xsl:call-template xsl:template
xsl:stylesheet
If you want to modify the
for
loop to do something useful, put your code between these comments:
-- Put your logic here, whatever it might be. For the purpose -- -- of our example, well just write some text to the output stream. --
xsl:textIteration xsl:textxsl:value-of select=iteration xsl:text: i=xsl:text
xsl:value-of select=ixsl:value-of select=newline -- Your logic should end here; dont change the rest of this --
-- template --