Certainly the way we have solved similar problems in the past was to pass the root directory as an external variable, and open all documents in the query by forming paths based on that variable.
You *can* get the URI to a document file by using fn:document-uri(), but only if the document was originally opened using the fn:doc() function. So for example,
declare variable $x as xs:string external;
let $d := fn:doc($x)
return fn:document-uri($d)
If you invoke this with "zorba -f -q /path/to/query -e x:=/path/fo/file.xml", then the result will be "file:///path/to/file.xml". You can then generate new relative URIs using that as a base URI. However, I think it's probably easier to just pass the root directory as a string external variable in the first place.
If you're curious, the reason that it doesn't work the way you wish it did is because Zorba creates internal entries in its store for all documents that are opened. These store entries have internally-generated URIs because they are copies of the original and can be modified through updates. My understanding is that we have to do some special-case magic in the case of fn:doc() specifically to make fn:document-uri() work according to the spec.
However, I could possibly see an argument for Zorba's -e and --context-item command-line arguments behaving like fn:doc() in this way; should I file a bug regarding that? It's quite possible there are good reasons NOT to do this, but I'm not the best person to talk about what they might be.
Ceej
aka Chris Hillery