[xquery-talk] joining multiple queries into a single one

Wolfgang Meier wolfgang at exist-db.org
Tue Apr 11 13:50:18 PDT 2006


> I am using the eXist Native XML Database. My content files are the path
> /db/content 
> If I write a query such as 
> For $r in /db/content where $r//prolog/meta/filename/text()="xys" 
> this doesn't seem to work.

Please note: collections are internal administrative structures. You 
cannot query them as if they were XML nodes (i.e. with a path 
expression). Instead, you use the collection() function to select a 
collection for the query, so your query above becomes:

for $r in collection("/db/content") where 

How the argument to collection() is interpreted is implementation 
dependant. In the case of eXist, the path is resolved as a collection 
path relative to the database root.

To query the various document structures in one query, create a union of 
the nodes in question, e.g.:

for $r in (//task|//concept)/meta/filename/text() = "xys" return $r

or with a predicate instead of the "for":

(//task|//concept)/meta/filename[text() = "xys"]

and including the collection path:

/meta/filename[text() = "xys"]


More information about the talk mailing list