Reputation: 1140
In a directory, I have several XML files like this:
File #1: <root myAtt="one"/>
File #2: <root myAtt="two"/>
I want to select the first document. For this, I use the following query (assuming the directory is called "myDocs"):
collection('myDocs')[/root/@myAtt = 'one']
(I know I could use doc()
to select the document of interest. But this example is just a simplified version of the real situation I'm facing, in which I have to work with a collection extracted from a database.)
If I run this query on Saxon-HE 9.6, I get what I expect: <root myAtt="one"/>
. But If I run the same query on BaseX 8.3, I surprisingly get: <root myAtt="one"/><root myAtt="two"/>
. Confusion ensues.
Apparently, the leading /
of the path expression inside the predicate (a "rooted path expression" according to Dr. Kay in XSLT 2.0 and XPath 2.0 4th Edition) is being treated differently across implementations.
In this case, /
is supposed to select the document node of the tree that contains the context node. And that is what Saxon does.
But in BaseX, /
seems to select the sequence of document nodes being filtered by the predicate. That would explain (if I'm getting it right) that the predicate evaluates to true for all documents, given the special behavior of the general comparison operator =
(there's always at least one item in the result sequence equal to 'one').
So, is the behavior of the /
operator in rooted path expressions implementation-dependent?
Upvotes: 3
Views: 129
Reputation: 6229
Thanks for the observation. This was a bug in BaseX, which will be fixed in BaseX 8.4 (the fix is also available in the latest snapshot).
The following query is equivalent, as the current context item, which serves as input for the path in the predicate, will be the current root node anyway:
collection('myDocs')[root/@myAtt = 'one']
Upvotes: 3