I don't fully understand the behaviour I'm seeing when using XPath union operator.
Having the following XML
<root>
<foo>hello</foo>
<bar>world</bar>
</root>
We get these results for different XPath expressions
(/root/foo | /root/bar)[1]
-> hello(/root/foo | /root/bar)[last()]
-> world(substring(/root/foo, 2, 4) | /root/bar)[1]
-> ello(substring(/root/foo, 2, 4) | /root/bar)[last()]
-> world
So far, they are intuitive results but...
(/root/foo | substring(/root/bar, 2, 4))[1]
-> orld (expected hello)(/root/foo | substring(/root/bar, 2, 4))[last()]
-> hello (expected orld)
Is there a reason for results presented? Are these compliant with XPath 2.0 spec?