XPath problem
I have the following XPath problem: How to select the first preceding node,
whether it is an ancestor, a preceding-sibling or a "preceding-siblings child"?
As I understand, the axis 'preceding' selects everyhting except any ancestors.
Let's say we have the following document:
<a>
<b/>
<c/>
<d/>
</a>
<e>
<f/>
<g/>
</e>
If the context node is <f/>, preceding::*[position()=1] does
not select <e> but <d/>. And if I use the ancestor axis, it
always selects an ancestor (as it is supposed to) even if it weren't the first
preceding node (e.g. the context were <g/>). I guess the problem boils down
to figuring out whether the first ancestor is also the first preceding node,
or is there some other nodes in between.
When I was travelling "downwards" in the document, the problem was
easy to solve. So what's the catch?
|