Search code examples
xmlxpathcontainsxmlnodelist

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

Solution

  • 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.