xpath expression to select by absolute index

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello everybody !

I'm looking for a while some way to select subnode element by its
position within whole document rather then in its parent.

Let's consider following xml:

<root>
<parent>
<subnode id="x1" value="y1"></subnode>
<subnode id="x2" value="y2"></subnode>
<subnode id="x3" value="y3"></subnode>
</parent>
<parent>
<subnode id="x4" value="y1"></subnode>
<subnode id="x5" value="y2"></subnode>
</parent>
</root>

I would want to use xpath like this

/root/parent/subnode[4]

to select element subnode with attribute x4.
However it doesn't work. Usage of 4 is an abbreviation for usage
position()=4. As I read, position has a contextual nature, so it works
in context of parent element.
Any help would be appreciated.

BR/Tomek

.