簡體   English   中英

XSLT 1.0 not(包含在for-each中

[英]XSLT 1.0 not(contains in for-each

我想包括以下內容:

not(contains(country/product/@genericname, 'Color Purple'))

for-each

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')]">

我嘗試了這個:

<xsl:for-each select="not(contains(country/product/@genericname, 'Stylus Pro')) and country[@name = $country]/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')]">

但是,我得到了這個錯誤: The value is not a node-set 我沒有看到語法錯誤。

處理器:Saxon6.5.5

@ michael.hor257k

我修改了您的代碼段,讓我的參數看上去更適合每個人。

<xsl:param name="country">GB</xsl:param>
<xsl:for-each select="country[@name = $country]/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(country/product/@genericname, 'Stylus Pro'))]">

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<countries>
    <country name="GB">
        <product genericname="Yellow line" id="12345" />
        <product genericname="Red line" id="6789" type="device" />
        <product genericname="This is Stylus Pro" id="256464" />
    </country>
</countries>

編輯

這是正確的方法,謝謝,這是錯誤的道路。

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(**@genericname**, 'Stylus Pro'))]">

不是國家/產品/ @通用名稱

謝謝

not(contains())必須位於謂詞中 (方括號內)。 在謂詞之外,您需要具有通往節點的路徑。 發布您的XML代碼示例,以獲得更具體的答案。

我猜這可能是您想要的:

<xsl:for-each select="country[@name = 'GB']/product[@category = 'inkjet' and contains(@classification, 'consumer') or contains(@classification, 'businessinkjet')] [not(contains(@genericname, 'Color Purple'))]">

請注意,路徑指向product ,並且謂詞限制了要包括在選擇中的產品類別。


編輯:

XSLT對上下文非常敏感。

[not(contains(@genericname, 'Stylus Pro'))]

與以下內容有很大的不同:

[not(contains(country/product/@genericname, 'Stylus Pro'))] 

第一個查看當前節點genericname屬性。 在以下情況下:

select="country[...]/product[...]"

當前節點是product

第二個對象查看名為product的節點的genericname屬性,該節點是country的子級,而country是當前節點的子級。 此屬性不存在-因此,它當然不包含搜索字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM