2017-03-05 75 views
0

我在迭代XSLT中的鍵值時遇到問題。我有這樣一行:嘗試基於XSLT中的鍵迭代一組元素

<xsl:key name="group" match="Orders" use="number" /> 

,並在此之後:

<xsl:variable name="orderNodes">  
    <xsl:copy-of select="key('group', number)" /> 
</xsl:variable> 

我想這個迭代:

<xsl:for-each select="$orderNodes/Orders"> 
    <xsl:value-of select="number" /> 
</xsl:for-each> 

但我得到一個錯誤:

ERROR: 'Could not compile stylesheet' 
FATAL ERROR: 'Could not compile stylesheet' 
      :Error checking type of the expression 'FilterParentPath(variable-ref(groupNodes/result-tree), step("child", 14))'. 
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet 

我做錯了什麼?

回答

0

你有xsl:variable name="orderNodes"但你嘗試使用$group這沒有任何意義。

至於使用一個變量,首先考慮你是否真的需要一個副本或不能僅僅選擇與例如輸入節點<xsl:variable name="group" select="key('group', number)"/>,然後使用例如$group/number應與XSLT的任何版本,並沒有任何錯誤XSLT處理器工作。

如果您真的需要一個與原始代碼相同的副本,請注意,使用XSLT 1.0處理器創建結果樹片段,然後需要首先將其轉換爲節點集,以便能夠選擇節點它:

<xsl:variable name="group-rtf">  
    <xsl:copy-of select="key('group', number)" /> 
</xsl:variable> 

<xsl:variable name="group" select="exsl:node-set($group-rtf)" xmlns:exsl="http://exslt.org/common"/> 

<xsl:for-each select="$group/Orders/number">... 
+0

我更新了我的代碼中的錯誤。 – ttdol2506