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之计数循环

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.