在XSL里执行类似for(i=0;i<x;i++)的循环
http://dotnet.aspx.cc/article/4052da03-51e0-464b-8418-3c1354920f8f/read.aspx
在XSL里,可以实现与一般编程语言类似的for循环的功能,下面就是实现这一功能的例子:
XSLLoop.xml
<?
xml version="1.0" encoding="GB2312"
?>
<? xml-stylesheet type="text/xsl" href="http://dotnet.aspx.cc/Exam/XSLLoop.xsl" ?>
< net_lover > 孟子E章 </ net_lover >
<? xml-stylesheet type="text/xsl" href="http://dotnet.aspx.cc/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://dotnet.aspx.cc" >
<!-- {PS..0} -->
<!-- {PS..1} -->
< xsl:variable name ="varStart" select ="0" />
<!-- {PS..2} -->
< xsl:variable name ="varEnd" select ="35" />
<!-- {PS..3} -->
< 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" >
<!-- {PS..4} -->
< a target ="_blank" href ="http://dotnet.aspx.cc/?{$varStart}" _fcksavedurl ="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 >
< xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform"
xmlns:copyRight ="http://dotnet.aspx.cc" >
<!-- {PS..0} -->
<!-- {PS..1} -->
< xsl:variable name ="varStart" select ="0" />
<!-- {PS..2} -->
< xsl:variable name ="varEnd" select ="35" />
<!-- {PS..3} -->
< 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" >
<!-- {PS..4} -->
< a target ="_blank" href ="http://dotnet.aspx.cc/?{$varStart}" _fcksavedurl ="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 >
&lt;strong&gt;结果如下:&lt;/strong&gt;
0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34