XPath: select child elements that do *not* have a specific name

Xpath

Xpath Problem Overview


<a>
   <b/>
   <c/>
   <d/>
   <b/>
   <e/>
</a>

How do I select those children of "a" that are not "b"?

Xpath Solutions


Solution 1 - Xpath

/a/*[not(self::b)]

Solution 2 - Xpath

With XPath 2.0 you can even do

/a/(* except b)

Solution 3 - Xpath

Xpath will look:

a/*[name(.) !='b']

So, select children of 'a' whose name is not equal 'b'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomasView Question on Stackoverflow
Solution 1 - XpathAakashMView Answer on Stackoverflow
Solution 2 - XpathMartin HonnenView Answer on Stackoverflow
Solution 3 - XpathDewfyView Answer on Stackoverflow