Reputation: 22406
I'd like preceding-sibling-or-self
functionality in my xpath and I'm using ../(self::*|preceding-sibling::*)
and it's giving me Expression must evaluate to a node-set.
, so I must be doing it wrong.
This bombs no matter what context node you are on or what the xml looks like. I want to use this functionality after a /
so I need the right syntax for that.
The xpath expression (self::*|preceding-sibling::*)
does not give an error, so it has to do with the place in the xpath which I'm trying to use it.
EDIT:
My mistake is actually more basic. You can't even do ../(.|.)
without that error. In general, I want to go to a node, then look through a set of nodes from there. The error seems to correlate with trying to use the union operator |
after a slash /
.
Upvotes: 5
Views: 4496
Reputation: 22406
In XPath, if you want to use the union operator, you must use it at the beginning of the path.
(self::*|preceding-sibling::*)/Child
is ok.
If you need to do Something/(self::*|preceding-sibling::*)/Child
, you have to expand the left part out like this:
(Something/self::*|Something/preceding-sibling::*)/Child
Upvotes: 7