我試圖用我在網上看到的遞歸習慣用法來創建類似於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