Skip to main content

XPath: not(=) !=

No replies
Joined: 2003-06-09
Points: 0

I've been doing some XPath in the last couple of days (with Jaxen) and it's a powerful tool for extracting information from XHTML. On the down side, the code you end up writing is vulnerable to slight variations in the source documents. This aside, I fell into a couple of traps that wasted my time; I hope someone benefits from my mistakes.

One thing that got me is that x != 'y' is not equivalent to not(x = 'y'). I pored over my XPath statement wondering why I wasn't getting any results when I remembered that XPath operates on sets, not on individual elements - a realisation that made me feel somewhat foolish. x != 'y' means "there exists at least one node in x that does not equal 'y'" whereas not(x = 'y') means "there are no nodes in x that exactly equal 'y'". A subtle distinction, and enough to give you wildly different results. This is relevant to XSLT XPath too.