Hello again,
You guys do such a great job of answering and responding to questions and concerns on this board, thanks again for that Christian. This next one might be a case of misunderstanding the standard on my part, but I'm seeing some odd things with XQuery when using a different initial context than the document root. Take the following XML:
<test> <a> <aa/> <ab> <aba/> <abb/> <abc/> </ab> <ac/> </a> <b> <ba/> <bb> <bba/> <bbb/> <bbc/> </bb> <bc/> </b> </test>
Here is the result of several different XQuery commands with different initial contexts (I've loaded the document into the BaseX GUI and am setting initial context by double-clicking the element in the grid view)...
Query: . Context: document, Result: The entire document (as expected) Context: <b>, Result: The <b> element and all its content (as expected)
Query: let $v := . return $v Context: document, Result: The entire document (as expected) Context <b>, Result: The entire document (was expecting the <b> element and all its content!)
Query: .//ab Context: document, Result: Result: The <ab> element and its content (as expected) Context <b>, Result: Nothing (as expected)
Query: let $v := //ab return $v Context: document, Result: The <ab> element and its content (as expected) Context: <b>, Result: The <ab> element and its content (as expected)
Query: let $v := .//ab return $v Context: document, Result: The <ab> element and its content (as expected) Context: <b>, Result: The <ab> element and its content (was expecting nothing!)
As you can see, it seems to behave counter to expectations when the initial context is not the document and I use the initial context in the FLOWR expression. I attempted to test in other tools, but it appears that setting the initial context for an XQuery expression is actually a difficult feature to find. It's not a totally academic question, though - the system we're building uses initial contexts pretty extensively.
I know that context is not maintained in XQuery, but can the initial context not be used in variable assignment or other components of a FLOWR expression?
Thanks,
Dave
Hi Dave,
Query: let $v := . return $v Context: document, Result: The entire document (as expected) Context <b>, Result: The entire document (was expecting the <b> element and all its content!)
This has been fixed as well (some performance optimizations lead to an erroneous decision to ignore the current context). Please check out the latest sources.
It is interesting to see that this feature is actually used. You can use the BaseX command "cs" to change the context reference outside the GUI for new queries, as e.g. shown here:
basex -c "create db doc.xml; cs //text(); xquery ."
Hope this helps, Christian
Christian,
Thanks as always. I've updated from source and can confirm it works great now. We're using the initial context pretty extensively in our system. We set it through the API by using a custom class that wraps QueryContext and re-implements several of the methods including compile(). We do that so that we can have a little more control over the query process (like setting the context and defining new custom collections that span multiple databases).
Dave
-----Original Message----- From: Christian Grün [mailto:christian.gruen@gmail.com] Sent: Friday, June 18, 2010 12:50 PM To: Dave Glick Cc: basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] XQuery FLOWR and Context
Hi Dave,
Query: let $v := . return $v Context: document, Result: The entire document (as expected) Context <b>, Result: The entire document (was expecting the <b> element and all its content!)
This has been fixed as well (some performance optimizations lead to an erroneous decision to ignore the current context). Please check out the latest sources.
It is interesting to see that this feature is actually used. You can use the BaseX command "cs" to change the context reference outside the GUI for new queries, as e.g. shown here:
basex -c "create db doc.xml; cs //text(); xquery ."
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de