Reputation: 255
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'))]
Upvotes: 24
Views: 25223
Reputation: 16917
At least in Xpath 2 general comparisons on sequences are performed pairwise and existentially, so you can write:
/item[not(@uid = ('id1','id2'))]
Upvotes: 0
Reputation: 243449
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, '|')
)
)]
Upvotes: 8
Reputation: 2146
You can either use regex - if your xpath implementation supports it - or write
/item[not(@uid='id1' or @uid='id2')]
which might be a bit shorter.
Upvotes: 28