我想知道我们是否有XSL 2.0中的某些东西,相当于Java中的List。我想递归地调用一个模板10次,并传入一个名为'mylist'的输入变量。在模板中,我想要做的操作,如添加项目列表,从列表中删除项目,迭代列表中的项目等。我可以看到像'序列'的东西,但我不知道它是否可以用来添加,删除,迭代等。请分享你的想法来实现这一点。XSL - 列表等效实现
我尝试使用序列的帮助下面的响应,我面临一些语法问题,如声明一个空序列。我想要使用insert-before或concat sequnce函数来打印序列1 2 3 4 5 6 7 8 9 10。请帮我修复语法。
<xsl:stylesheet version="2.0"
xmlns:locator="http://ntr.lxnx.org"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="output">
<xsl:call-template name="calculate-data">
<xsl:with-param
name="sequence"
select=""/>
<xsl:with-param
name="count"
select="1"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="output"></xsl:value-of>
</xsl:template>
<xsl:variable name="main-root" as="document-node()" select="/"/>
<xsl:template name="calculate-data">
<xsl:param name="sequence"/>
<xsl:param name="count" select="0"/>
<xsl:if test="$count != 10">
fn:insert-before($count as item()*,0 as xs:integer,$sequence as item()*)
<xsl:call-template name="calculate-data">
<xsl:with-param
name="sequence"
select="$sequence"/>
<xsl:with-param
name="count"
select="$count + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
您可以迭代序列。您将能够将模板应用于XSLT 3.0中的序列.-关于添加/删除:注意XSLT是一种声明性语言,这些函数将生成一个新实例。 – 2011-04-27 20:49:36
Rachel,也许你可以提供一个你想要的输入/输出类型的小例子?我问的原因是XSL通常不被用作过程语言,所以在迭代时更改列表中的值通常不是解决问题的理想方法。相反,你会指定你想要的最终结果是什么,而不是如何得到结果。 – Erica 2011-04-28 01:32:25
@Erica:你的观点非常真实。我有兴趣使用序列来实现解决方案,因为我想了解更多信息。感谢您的答复。 – Rachel 2011-04-29 01:28:51