Exclude certain elements from selection in XPath

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

Answering to add that in XPath 2.0, you can use except:

/root/(* except a)

For XPath 1.0, Tomalak pointed out, this is the standard way to do it:

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

By the way, if someone lands here trying to use this in XSLT 2.0 in a xsl:template/@match attribute it won't work because @match takes patterns which although look like XPath expressions, are not XPath expressions. The solution for XPath 1.0 would work in this case.


I realize this is an old question, but I recently ran into a similar problem and used the following xpath to solve it:

/root/*[not(name()='a')]

Tags:

Xml

Xpath