XSLT之计数循环

如下代码定义了一个循环模板的例子:

<xsl:template name=”for-loop”>
<xsl:param name=”i”/>
<xsl:param name=”count”/>
<xsl:if test=”$i &lt;= $count”>
<xsl:value-of select=”$i” disable-output-escaping = “yes” />
</xsl:if>
<xsl:if test=”$i &lt;= $count”>
<xsl:call-template name=”for-loop”>
<xsl:with-param name=”i”>
<xsl:value-of select=”$i + 1″/>
</xsl:with-param>
<xsl:with-param name=”count”>
<xsl:value-of select=”$count”/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>

调用方法:

<xsl:call-template name=”for-loop”>
<xsl:with-param name=”i”>1</xsl:with-param>
<xsl:with-param name=”count”>10</xsl:with-param>
</xsl:call-template>

结果输出1-10这10个数字。

2 thoughts on “XSLT之计数循环

  1. diyism August 7, 2007 / 12:45 pm

    没必要这么复杂, 可以:
    随意指定循环次数(不大于//*的所有个数):

    hello

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s