xpath選擇不包含屬性值列表的節點

[英]xpath to select nodes excluding by attribute value list


I would like to know if there is shorter approach to selecting a list of nodes ignoring the ones that have an attribute value specified in a list

我想知道是否有更短的方法來選擇節點列表,而忽略在列表中指定屬性值的節點

Working example:

工作的例子:

/item[not(@uid='id1') and not(@uid='id2')]

Desired alternative:

理想的選擇:

/item[not(@uid in('id1','id2'))]

4 个解决方案

#1


21  

You can either use regex - if your xpath implementation supports it - or write

您可以使用regex(如果您的xpath實現支持的話),也可以編寫

/item[not(@uid='id1' or @uid='id2')]

which might be a bit shorter.

可能會更短一點。

#2


5  

If the list of attribute names is very long, the following is a good way to handle this situation:

如果屬性名列表很長,下面是處理這種情況的好方法:

//item[not(contains('|attr1|attr2|attr3|attr4|attr5|attr6|attrN|', 
                    concat('|', @uid, '|')
                    )
           )]

#3


3  

Maybe something like this??

也許是這樣的嗎? ?

/item[not(contains('id1 id2', @uid))]

#4


0  

At least in Xpath 2 general comparisons on sequences are performed pairwise and existentially, so you can write:

至少在Xpath 2中,序列上的一般比較是成對的和存在的,所以您可以這樣寫:

/item[not(@uid = ('id1','id2'))]

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/07/16/725e65c70eecbf34c9175a04777a6853.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com