Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath to select nodes excluding by attribute value list

Tags:

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'))] 
like image 316
Aitorito Avatar asked Jul 16 '12 07:07

Aitorito


2 Answers

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.

like image 65
Arne Avatar answered Oct 19 '22 17:10

Arne


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, '|')                     )            )] 
like image 39
Dimitre Novatchev Avatar answered Oct 19 '22 18:10

Dimitre Novatchev