我有以下 XSL:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:param name='width' select ="270"/>
<xsl:param name='height' select="180"/>
<xsl:variable name="counter" select="0" />
<xsl:template name="while">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<line x1="{$counter}" y1="0.5" x2="{$counter}" y2="10.5" stroke="black" stroke-width="1" />
<xsl:variable name="counter" select="$counter + 10" />
<xsl:if test="$counter < $width">
<xsl:call-template name="while"/>
</xsl:if>
</svg>
</xsl:template>
</xsl:stylesheet>
我试图在宽度上每 10 个像素绘制一条线,就像标尺标记一样。
当我运行这段代码时,它陷入了循环。我无法调试,我只是得到堆栈溢出异常。我推测要么我的计数器值没有增加 10,要么我对检查计数器 < width 是否不正确的评估。
有人可以给我指出正确的方向吗?
最佳答案
我认为您在调用模板时需要传递参数。
类似于:
<xsl:template name="loop">
<xsl:param name="count" select="1"/>
<xsl:if test="$count > 0">
<xsl:call-template name="loop">
<xsl:with-param name="count" select="$count - 1"/>
</xsl:call-template>
<xsl:value-of select="$count"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
关于c# - 在 XSLT 中迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363534/