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

    技术2022-05-11  24

    <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

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

    http://lucky_elove.www1.dotnetplayground.com/

    在XSL里,可以实现与一般编程语言类似的for循环的功能,下面就是实现这一功能的例子:

    XSLLoop.xml">查看例子

    XSLLoop.xml

    <?xml version="1.0" encoding="GB2312"?><?xml-stylesheet type="text/<A href="http://www.66of.com" target=_blank>XSL</A>" href="http://lucky_elove.www1.dotnetplayground.com/Exam/<A href="http://www.66of.com" target=_blank>XSL</A>Loop.<A href="http://www.66of.com" target=_blank>XSL</A>"?><net_lover>孟子E章</net_lover>

    XSLLoop.XSL

    <?xml version="1.0" encoding="GB2312"?><<A href="http://www.66of.com" target=_blank>XSL</A>:stylesheet version="1.0" xmlns:<A href="http://www.66of.com" target=_blank>XSL</A>="http://www.w3.org/1999/<A href="http://www.66of.com" target=_blank>XSL</A>/Trans<A href="http://www.66of.com" target=_blank>for</A>m" xmlns:copyRight="http://lucky_elove.www1.dotnetplayground.com/"> <!-- 下面的三个变量可以由XML中取得,做为例子,这里直接定义了初始值 --> <!-- 定义初始值 --> <<A href="http://www.66of.com" target=_blank>XSL</A>:variable name="varStart" select="0"/> <!-- 定义结束值 --> <<A href="http://www.66of.com" target=_blank>XSL</A>:variable name="varEnd" select="35"/> <!-- 定义<A href="http://www.66of.com" target=_blank>循环</A>步长 --> <<A href="http://www.66of.com" target=_blank>XSL</A>:variable name="varStep" select="2"/> <<A href="http://www.66of.com" target=_blank>XSL</A>:template match="/"> <<A href="http://www.66of.com" target=_blank>XSL</A>:call-template name="MyLoopFun"> <<A href="http://www.66of.com" target=_blank>XSL</A>:with-param name="varStart" select="$varStart"> </<A href="http://www.66of.com" target=_blank>XSL</A>:with-param> </<A href="http://www.66of.com" target=_blank>XSL</A>:call-template> </<A href="http://www.66of.com" target=_blank>XSL</A>:template> <<A href="http://www.66of.com" target=_blank>XSL</A>:template name="MyLoopFun"> <<A href="http://www.66of.com" target=_blank>XSL</A>:param name="varStart"/> <<A href="http://www.66of.com" target=_blank>XSL</A>:if test="$varStart &lt; $varEnd"> <!-- 输出格式定义 --> <a target="_blank" href="http://lucky_elove.www1.dotnetplayground.com/?{$varStart}" rel="nofollow"> <<A href="http://www.66of.com" target=_blank>XSL</A>:attribute name="title"><<A href="http://www.66of.com" target=_blank>XSL</A>:value-of select="$varStart"/></<A href="http://www.66of.com" target=_blank>XSL</A>:attribute> <<A href="http://www.66of.com" target=_blank>XSL</A>:value-of select="$varStart"/> </a> <<A href="http://www.66of.com" target=_blank>XSL</A>:if test="$varStart &lt; ($varEnd - $varStep)"> , </<A href="http://www.66of.com" target=_blank>XSL</A>:if> <<A href="http://www.66of.com" target=_blank>XSL</A>:call-template name="MyLoopFun"> <<A href="http://www.66of.com" target=_blank>XSL</A>:with-param name="varStart"> <<A href="http://www.66of.com" target=_blank>XSL</A>:value-of select="$varStart + $varStep"/> </<A href="http://www.66of.com" target=_blank>XSL</A>:with-param> </<A href="http://www.66of.com" target=_blank>XSL</A>:call-template> </<A href="http://www.66of.com" target=_blank>XSL</A>:if> </<A href="http://www.66of.com" target=_blank>XSL</A>:template></<A href="http://www.66of.com" target=_blank>XSL</A>:stylesheet>

    结果如下:

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

    <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

    最新回复(0)