Select document as root context from a BaseX database by URI

292 Views Asked by At

Might not be difficult, but i cannot find the correct command and syntax:

I have a BaseX database opened that holds several XML documents:

/document-uri()

looks like this

/dirA/dirA1/x01.xml
/dirA/dirA1/x02.xml
/dirA/dirA2/x03.xml
/dirA/dirA3/dirA31/x04.xml
/dirA/dirA3/dirA31/x05.xml
/dirA/dirA3/dirA32/x06.xml
/dirB/dirB1/x07.xml
/dirB/dirB2/x08.xml
/dirC/dirC1/x09.xml
/dirC/dirC2/dirC11/x10.xml
/dirD/dirD1/dirD11/x11.xml
/dirE/dirE1/dirE11/x12.xml

What i am looking for is a XQuery to select a document by URI and use it as XPath context, s.th. like this:

document("/dirA/dirA1/x01.xml")/root/foo

Another one would be super useful as well: select all documents in a dir path (recursively:))

document("/dirA/dirA1/")/root/foo
1

There are 1 best solutions below

1
On BEST ANSWER

There is a doc function so doc('/dirA/dirA1/x01.xml') should select the document. There is also the collection function which probably allows you to select collection('/dirA/dirA1'), the exact use of the collection function is depending on the XQuery processor and e.g. how you set up your DB in BaseX.

So basically the doc and the collection functions should help in XQuery. Only XSLT has a function named document you have used in your samples.