XQERY Help
Hello,
I need help with hopefully a simple XQUERY.
I want to extend below XQUERY to run not on all documents in all databases, but only on those documents which contains "input string X" in its db:path (i.e. its original file name).
Any help appreciated.
declare variable $n as xs:string external; (: command line query, to be entered as "n" variable :) declare option output:item-separator "
"; (: Each element would be in new line :)
(: Run input query, on every XML document in every Database:)
let $queryData :=
for $db in db:list()
(: Assign dynamic variables to generate query, to be used in eval :)
let $query := "declare variable $db external; " || "db:open($db)" || $n
return xquery:eval($query,map { 'db': $db, 'query': $n })return distinct-values($queryData)
- Mansi
Quoted text · Mansi Sheth · 3 lines
> I want to extend below XQUERY to run not on all documents in all databases, > but only on those documents which contains "input string X" in its db:path > (i.e. its original file name).
This should do it:
db:open('db')[contains(db:path(.), 'input string X')]If a database has a big number of documents stored, it will be faster to store and access documents by their path (obviously, this won’t allow you do look for arbitrary substrings in the file name):
db:open('db', '/path/from/root/')Cheers, Christian
Quoted text · Mansi Sheth · 18 lines
> > Any help appreciated. > > declare variable $n as xs:string external; (: command line query, to be > entered as "n" variable :) > declare option output:item-separator "
"; (: Each element would be in > new line :) > > (: Run input query, on every XML document in every Database:) > let $queryData := > for $db in db:list() > (: Assign dynamic variables to generate query, to be used in eval :) > let $query := "declare variable $db external; " || "db:open($db)" || $n > return xquery:eval($query,map { 'db': $db, 'query': $n }) > > return distinct-values($queryData) > > - Mansi
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.