Ah, I see. It just felt too PHPish to synthesize the whole query as a string, therefore I thought I might use xquery:eval() ad libitum in the middle of a query and that it would operate on the same database as the static remainder of the query.
And of course it is harder to debug if the whole query is a string, syntax-aware editor support is unavailable, etc.
I wanted to have a generic, configurable RESTXQ interface for retrieving document fragments according to fragmentation rules that are defined elsewhere, by means of an XPath expression. This expression may be for example '//*:div[not(ancestor::*:div)][not(*:divGen)]' for a certain class of TEI documents, or '//(*:chapter | *:part | *:appendix | *:preface)' for DocBook.
This expression is passed to the function sxedit:list-frags() that retrieves the headings of all fragments, as in https://github.com/gimsieke/sxedit/blob/master/lib/basex/restxq/sxedit.xqm#L..., and it is also supplied as an argument to the function that is supposed to retrieve the fragments, inserting placeholder elements whenever a nested fragment is encountered.
Another configurable option in that module is an expression, $doc-condition, that filters the available databases for documents that meet certain criteria, for example, '[namespace-uri(/*) = ''http://www.tei-c.org/ns/1.0'']'.
I’ll have to deal with writing back the (edited) fragments; maybe I’ll contact you folks off-list soon for some guidance on forging the updating queries because I never did updating queries before ;)
Gerrit
On 17.11.2013 12:04, Christian Grün wrote:
Hi Gerrit,
db:node-id(xquery:eval("db:open('doc', 'doc.xml')/*")) => 0
some quick feedback (I'll further look into this): when running xquery:eval, a main-memory copy of the original node is created, which may have another node id than the original node. To get the node id of the original node, you'll have to embed your db:node-id call into the xquery:eval code:
xquery:eval("db:node-id(db:open('doc', 'doc.xml')/*)")
Hope this helps, Christian ___________________________
On Sun, Nov 17, 2013 at 2:51 AM, Imsieke, Gerrit, le-tex gerrit.imsieke@le-tex.de wrote:
Probably related:
db:node-id(db:open('doc', 'doc.xml')/*) => 1
On 16.11.2013 23:57, Imsieke, Gerrit, le-tex wrote:
I think that under certain conditions, the path() function does not return the proper paths.
Here's an example that works ok:
for $doc in <doc><a/><b><c/></b></doc> let $nodes as element(*)* := xquery:eval("$doc//*", map{"doc":=$doc}) return for $node in $nodes return <result path="{path($node)}" name="{name($node)}"/>
=> <result path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}a[1]" name="a"/> <result path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}b[1]" name="b"/> <result path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}b[1]/Q{}c[1]" name="c"/>
Now I create a database 'doc' with the document 'doc.xml' and invoke the slightly modified query:
for $doc in db:open('doc', 'doc.xml')/* let $nodes as element(*)* := xquery:eval("$doc//*", map{"doc":=$doc}) return for $node in $nodes return <result path="{path($node)}" name="{name($node)}"/>
=>
<result path="Q{http://www.w3.org/2005/xpath-functions}root()" name="a"/> <result path="Q{http://www.w3.org/2005/xpath-functions}root()" name="b"/> <result path="Q{http://www.w3.org/2005/xpath-functions}root()" name="c"/>
The element names are still known, but not their paths. Is it a bug or am I missing something?
Gerrit
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
-- Gerrit Imsieke Geschäftsführer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@le-tex.de, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
Geschäftsführer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vöckler
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk