2013-09-25 29 views
0

考慮以下情況下指定的子元素值:的XPath選擇具有在列表

<xsl:variable name="list"> 
    <row> 
    <webid>2</webid> 
    </row> 
    <row> 
    <webid>3</webid> 
    </row> 
    <row> 
    <webid>4</webid> 
    </row> 
</xsl:variable> 

<!--pseudo code, not sure if it will work in real time--> 
<xsl:variable name="addr" select="addresses/item[not(id=$list/webid)]"/> 

我要過濾哪些還沒有在$list webid collection一個id這些地址的項目。我發佈的表達是否會做?請指教。

回答

2

在XSLT 1.0這樣的一個變量聲明爲一個結果樹片段,而不是一個節點集,你可以用它做的唯一事情是copy-ofvalue-of - 你不能導航到它與XPath表達式。你需要或者

  1. 使用的擴展功能,例如exslt:node-set打開RTF進入設置或
  2. 一個真正的節點使用技巧與document('')訪問樣式表本身作爲一個XML文檔

選項2僅適用於您的示例,其中變量值爲靜態XML。如果您有一個變量,其值是使用xsl:命令或屬性值模板構建的,例如

<xsl:variable name="allNames"> 
    <xsl:for-each select="name"> 
    <person name="{.}" /> 
    </xsl:for-each> 
</xsl:variable> 

那麼你必須使用node-set函數。 document('')方法將爲您提供名稱屬性的實際xsl:for-each元素和文字值{.},而不是評估它的結果。

選項1

添加xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt"<xsl:stylesheet>標記,然後用

<xsl:variable name="addr" select="addresses/item[ 
    not(id=exslt:node-set($list)/row/webid)]"/> 

選項2

<xsl:variable name="addr" select="addresses/item[ 
    not(id=document('')//xsl:variable[name='list']/row/webid)]"/> 
0

我把沒有(地址/項目[ID = $ list/webid])