0

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?

fglez
  • 8,422
  • 4
  • 47
  • 78

2 Answers2

3

TIBCO BusinessWorks is XPath 1.0 compliant only. Some XPath 2.0 functions are supported. (source: FAQ1-7BXZE5 on http://support.tibco.com)

To answer your two questions:

  • "Is there a reason for results presented?"

Yes. XPath 1.0 union results are unpredictable. A good rule: One should not rely on Union order in BusinessWorks, even for simple cases.

  • "Are these compliant with XPath 2.0 spec?"

The results are not compliant with XPath 2.0 specification but your queries are evaluated with an XPath 1.0 engine.

Tony Baguette
  • 617
  • 7
  • 14
  • If it's just XPath 1.0 compliant, then this question applies: http://stackoverflow.com/questions/8752666/xpath-1-0-order-of-returned-attributes-in-a-union – fglez Mar 07 '13 at 14:10
1

No, the last two results are not compliant with the spec. It's a type error if an operand to the union operator is a string rather than a node, which is the case in your last two examples.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I suppose you mean the last four (they all have a substring function). If I understand well, the problem is the last four expressions shouldn't be allowed. – fglez Feb 28 '13 at 16:51