Thomas
Thomas

Reputation: 17422

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

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

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

Upvotes: 65

Views: 48729

Answers (3)

Martin Honnen
Martin Honnen

Reputation: 167716

With XPath 2.0 you can even do

/a/(* except b)

Upvotes: 17

Dewfy
Dewfy

Reputation: 23644

Xpath will look:

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

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

Upvotes: 3

AakashM
AakashM

Reputation: 63378

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

Upvotes: 105

Related Questions