<div n="a">
. . .
. . .
<spec>red</spec>
<div n="d">
. . .
</div>
<spec>green</spec>
. . .
<div n="b">
. . .
<spec>blue</spec>
. . .
</div>
<div n="c">
<spec>yellow</spec>
</div>
. . .
. . .
. . .
</div>
[Edited to remove the ambiguity Sean noticed. — Thanks]
When the current element is <div n="a">, I need an XPATH expression that returns the red and green elements, but not the blue and yellow ones, as .//spec does.
When the current element is <div n="b">, the same expression needs to return the blue element; when <div n="c">, the yellow element.
Something like .//spec[but no deeper than another div if there is one]
In XSLT 1.0, assuming that the current node is a
div:In XSLT 2.0 under the same assumptions:
And a pure XPath 2.0 expression:
Full XSLT 1.0 transformation:
when applied on the provided XML document:
the wanted, correct result is produced:
Full XSLT 2.0 transformation:
When applied on the same XML document (above), the same correct result is produced:
And using pure XPath 2.0 (no
current()):produces the same correct result: