Hi Владимир (cc to the list),
let $docs := db:open('sirukov')/docs/doc for $msg in db:open('sirukov')/msgs/msg[EnvelopeID = $docs/envelopeid] let $db := try {db:open($msg/dbname)} catch * {} for $xml in $db[*:Envelope/*:Header/*:RoutingInf/*:EnvelopeID = $msg/EnvelopeID] (: some actions with $xml and then return map data :) return $xml
Thanks. So you’d like to close the single databases after you have processed them in you inner loop, right? That’s not possible indeed, I’m sorry (because it might happen that your database would need to be opened twice – and due to the functional nature of XQuery, the database, and its contents, must be the same throughout the query).
I know too less about your data (the number of databases, their size) and the evaluation times of your query, but you could try to use the enforceindex pragma [1] to enforce index rewritings.
Best, Christian
[1] http://docs.basex.org/wiki/XQuery_Extensions#Database_Pragmas
basex-talk@mailman.uni-konstanz.de