UnitTest( xslt-for-loop.asp )

Output

HELLO WORLD - I'm at position 1
HELLO WORLD - I'm at position 2
HELLO WORLD - I'm at position 3
HELLO WORLD - I'm at position 4
HELLO WORLD - I'm at position 5
HELLO WORLD - I'm at position 6
HELLO WORLD - I'm at position 7
HELLO WORLD - I'm at position 8
HELLO WORLD - I'm at position 9
HELLO WORLD - I'm at position 10

Sources

/xslt-for-loop.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>Evolved - Unit Test - XSLT FOR LOOP</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( xslt-for-loop.asp )</h1>
            </div>
            <div id="container-bd">
 
<h2>Output</h2>
<div class="code"><pre><%
 
dim Xml, Xslt
 
set Xml = Server.createObject("MSXML2.DomDocument.6.0")
set Xslt = Server.createObject("MSXML2.DomDocument.6.0")
 
Xml.async = false
Xml.load( Server.mapPath("xslt-for-loop.xml") )
if( Xml.parseError.errorCode <> 0 ) then
    Response.write( Xml.parseError.reason )
end if
 
Xslt.async = false
Xslt.setProperty "AllowDocumentFunction", true
Xslt.setProperty "AllowXsltScript", true
Xslt.load( Server.mapPath("xslt-for-loop.xsl") )
if( Xslt.parseError.errorCode <> 0 ) then
    Response.write( Xslt.parseError.reason )
end if
 
Response.write( Xml.transformNode(Xslt) )
 
set Xslt = nothing
set Xml = nothing
 
%></pre></div>
 
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
                <h3>xslt-for-loop.xsl</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "xslt-for-loop.xsl" ) ), "xml" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>
 

xslt-for-loop.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:forLoop="urn:schemas-evolved-com-br:xslt:forLoop"
>
    <xsl:output method="xml"
        omit-xml-declaration="yes"
        encoding="UTF-8"
        indent="yes" />
 
    <forLoop:templates>
        <forLoop:helloworld/>
    </forLoop:templates>
 
    <xsl:template match="forLoop:helloworld" mode="for-loop-template">
        <xsl:param name="i"/>
HELLO WORLD - I'm at position <xsl:value-of select="$i"/>
    </xsl:template>
 
    <xsl:template match="/">
        <xsl:call-template name="for_loop">
            <xsl:with-param name="idTemplate" select="'helloworld'"/>
            <xsl:with-param name="i" select="1"/>
            <xsl:with-param name="k" select="10"/>
        </xsl:call-template>
    </xsl:template>
 
 
 
 
<!-- Evolved XSLT helpers -->
 
    <xsl:variable name="for_loop_templates" select="document('')//forLoop:templates" />
 
    <xsl:template name="for_loop">
        <xsl:param name="idTemplate"/>
        <xsl:param name="i"/>
        <xsl:param name="k"/>
 
        <xsl:if test="$k >= $i">
            <xsl:apply-templates select="$for_loop_templates/forLoop:*[local-name() = $idTemplate]" mode="for-loop-template">
                <xsl:with-param name="i" select="$i"/>
            </xsl:apply-templates>
            <xsl:call-template name="for_loop">
                <xsl:with-param name="idTemplate" select="$idTemplate"/>
                <xsl:with-param name="i" select="$i + 1"/>
                <xsl:with-param name="k" select="$k"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
 
</xsl:transform>