查看例子
XSLLoop.xml
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="http://lucky_elove.www1.dotnetplayground.com/Exam/XSLLoop.xsl"?>
<net_lover>孟子E章</net_lover>
XSLLoop.xsl
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:copyRight="http://lucky_elove.www1.dotnetplayground.com/">
<!-- 下面的三个变量可以由XML中取得,做为例子,这里直接定义了初始值 -->
<!-- 定义初始值 -->
<xsl:variable name="varStart" select="0"/>
<!-- 定义结束值 -->
<xsl:variable name="varEnd" select="35"/>
<!-- 定义循环步长 -->
<xsl:variable name="varStep" select="2"/>
<xsl:template match="/">
<xsl:call-template name="MyLoopFun">
<xsl:with-param name="varStart" select="$varStart">
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="MyLoopFun">
<xsl:param name="varStart"/>
<xsl:if test="$varStart < $varEnd">
<!-- 输出格式定义 -->
<a target="_blank" href="http://lucky_elove.www1.dotnetplayground.com/?{$varStart}">
<xsl:attribute name="title"><xsl:value-of select="$varStart"/></xsl:attribute>
<xsl:value-of select="$varStart"/>
</a>
<xsl:if test="$varStart < ($varEnd - $varStep)"> , </xsl:if>
<xsl:call-template name="MyLoopFun">
<xsl:with-param name="varStart">
<xsl:value-of select="$varStart + $varStep"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
结果如下:
0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34