Typically when I work in XSLT I create a main file that is composed mostly of imports. I keep each of the import files small so that they are easier for me to maintain.
I'm trying to do the same thing in XQuery (in MarkLogic), but I'm not able to make it work the way I'd hoped it'd work.
Here's what I'd like to be able to do:
main.xqy:
xquery version "1.0-ml";
module namespace summit = "http://example.com/summit";
import module "http://example.com/summit" at "/ext/variables.xqy";
import module "http://example.com/summit" at "/ext/utils.xqy";
variables.xqy:
xquery version "1.0-ml";
module namespace summit = "http://example.com/summit";
declare variable $BASEURL as xs:string := "https://example.com/v1";
utils.xqy:
xquery version "1.0-ml";
module namespace summit = "http://example.com/summit";
declare function summit:baseUrl() {
let $url := $BASEURL
return $url
};
and then use the following code to call it in the query console:
xquery version "1.0-ml";
import module namespace summit = "http://example.com/summit" at "/ext/main.xqy";
summit:baseUrl()
I get the following error:
[1.0-ml] XDMP-UNDVAR: (err:XPST0008) Undefined variable $BASEURL
Stack Trace
In /ext/utils.xqy on line 4
In xdmp:eval("xquery version "1.0-ml"; import module namespace s...", (), <options xmlns="xdmp:eval"><database>8148014817830251656</database>...</options>)
I get similar errors for functions defined in the same way (defined in one xquery file, used in a different one that's imported into main.xqy).
I can work around this by importing variables.xqy into utils.xqy, but I'd like to avoid that as it adds management overhead, not decreases it.
I'm sure there's something I'm doing obviously wrong here, but I'm not sure what.
How do you organize large xquery projects?