我试图用我在网上看到的递归习惯用法来创建类似于for-loop的东西。我的实现是用一个参数来告诉打印什么。我使用Eclipse的内置XSL transformator,我不能为我的生活为什么它给出了一个StackOverflowException:XSL - 为什么这个递归永远?
<!--
Loops recursively to print something the number of times specified with
the max parameter.
The print parameter tells what to print.
-->
<xsl:template name="loop">
<xsl:param name="count" select="1"/>
<xsl:param name="max" />
<xsl:param name="print" />
<xsl:if test="not($count = $max)">
<xsl:value-of select="$print" />
<xsl:call-template name="loop">
<xsl:with-param name="count">
<xsl:value-of select="$count + 1" />
</xsl:with-param>
<xsl:with-param name="max">
<xsl:value-of select="$max"/>
</xsl:with-param>
<xsl:with-param name="print">
<xsl:value-of select="$print" />
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
而且,为什么$count < $max
放弃无效的XPath表达式?
在此先感谢。
问得好,+1。请参阅我的回答以获得详细的解释并回答您的两个问题。 :) – 2010-10-23 16:29:55