I've looked at this question: http://stackoverflow.com/questions/453191/select-first-instance-only-with-xpath
But if I have a node-set like this:
<container value="">
<data id="1"></data>
<data id="2">test</data>
<container>
<data id="1">test</data>
<data id="3">test</data>
</container>
</container>
Now my scenario is that this node-set is deep inside a document, and I have a pointer to the inner container. So I have to prefix my XPath with "/container/container" (the path is actually longer, but for this example this should do).
EDIT: What I want is a "data" node with an id of 1, which should come from the lowest node first or the closest ancestor. So, if I can't find it on the "current" (/container/container) I should look at the ancestors and get the nearest one (or in the end, not find anything). I have tried this:
/container/container/ancestor-or-self::container/data[@id="1"]
Which brings back a result set with two nodes. I thought I could use last() to get the deepest one, so I tacked that on the end, but to no avail. :)
Thanks for any help.