Hi Simon,
thanks for your mail. The reason for the surprising query result is that the root expression ("/") points to the document node of the node which is in the current context. In your query, this is the first document ("doc_a"):
//a1[@id = /......
I agree that the result is somewhat surprising, because you would possibly expect "/" to return all documents of your collection.
The following query will return the expected results (and it will usually be evaluated faster if you have indexed your documents):
let $refs := //b/b1/@ref return //a1[@id = $refs]
In this case, "/" is applied to all nodes in your initial context. As you are starting with the document nodes anyway, the following query would be equivalent:
let $refs := descendant::b/b1/@ref return descendant::a1[@id = $refs]
Hope this helps; feel free to ask for more details, Christian ________________________________
On Tue, Feb 11, 2014 at 6:58 PM, Simon Görke simon.goerke@ils.uni-stuttgart.de wrote:
Hello there,
I am not really sure if the following is an issue or just a lack of understanding on my side. I have two documents and try to find elements from one based on (attribute-stored) constraints given in the other. A basic example structure looks as follows:
<commands> <create-db name='test1'/> <add path='doc_a'><a><a1 id='1'/><b1 ref='1'/></a></add> <add path='doc_b'><b><b1 ref='1'/></b></add> </commands>
Queries: //a1[@id=//a/b1/@ref] => 1 hit
//a1[@id=//b/b1/@ref] => no hits?
When putting the nodes in one and the same document (adding a common parental node), either query returns 1 hit:
<commands> <create-db name='test2'/> <add path='doc'><any><a><a1 id='1'/><b1 ref='1'/></a><b><b1 ref='1'/></b></any></add> </commands>
What I would have expected is 1 hit in any of the cases, but finding the correct context in predicate expressions confused me more than one time...
Regards, Simon (BaseX Version is 7.8 beta 8f51466)
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk