我想知道我們是否有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