在XSL里执行类似for(i=0;i〈x;i++)的循环

在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 >

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 &lt; $varEnd" >
      
<!-- {PS..4} -->
      
< 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 &lt; ($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 >
  &amp;lt;strong&amp;gt;结果如下:&amp;lt;/strong&amp;gt; 

0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值