xpath to select nodes excluding by attribute value list

Aitorito picture Aitorito · Jul 16, 2012 · Viewed 21k times · Source

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'))]

Answer

Arne picture Arne · Jul 16, 2012

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.