XQJ: Binding a collection to the context item
Added by Anonymous over 16 years ago
Legacy ID: #5118248 Legacy Poster: Markku Laine (mplaine)
Hi, I would like to execute a simple XQuery (e.g., //product) expression against a collection. Does somebody know is there a way to bind a collection to the context item using XQJ? I know that it is possible to bind a document to the context item using XQJ, and by doing so, the simple XQuery expression above can be successfully executed against a document. I am also aware of that collections can be queried by using the collection( "the_name_of_the_collection" ) function in the XQuery expression but this not what I am looking for. I managed to "bind" a collection to the context item when using eXist database (XML:DB API) but cannot do the same when using XQJ + documents are located in the file system. Thanks for your help in advance! -Markku
Replies (1)
RE: XQJ: Binding a collection to the context - Added by Anonymous over 16 years ago
Legacy ID: #5118312 Legacy Poster: Michael Kay (mhkay)
The context item is by definition an item, not a sequence, whereas a collection is a sequence; so I can't see what it would mean to bind a collection to the context item. A path expression starting with "//x" is equivalent to (root() treat as document-node())/descendant-or-self::node()/child::x, so it is guaranteed to select within a single XML document under all circumstances. I think your best approach is to write the query as declare variable $x as document-node()*; $x//product and then bind your "collection" of documents to the variable $x.
Please register to reply