XSLT:从 1 到 60 循环 [英] XSLT : Looping from 1 to 60
问题描述
在 XSLT 中从 1 到 60 循环的最佳方式是什么?我在网上研究,有一些模板可以做到这一点,有没有其他方法,例如内置函数?
What is the best way to loop in XSLT from 1 to 60? I research in net, there are some templates to do this, is there any other way for example like a built-in function?
推荐答案
在 XSLT 2.0 中,
In XSLT 2.0,
<xsl:for-each select="1 to 60">...</xsl:for-each>
但我猜您一定在使用 XSLT 1.0,否则您就不会问了.
But I guess that you must be using XSLT 1.0, otherwise you wouldn't be asking.
在 XSLT 1.0 中,您应该使用递归:一个模板,它使用每次调用时递增的计数器调用自身,并在达到所需值时终止递归.
In XSLT 1.0 you should use recursion: a template that calls itself with a counter that's incremented on each call, and the recursion terminates when the required value is reached.
或者在 XSLT 1.0 中有一个解决方法:如果您的源文档包含至少 60 个节点,您可以这样做
Alternatively there's a workaround in XSLT 1.0: provided your source document contains at least 60 nodes, you can do
<xsl:for-each select="(//node())[60 >= position()]">...</xsl:for-each>
这篇关于XSLT:从 1 到 60 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!