<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">Saxon allows you to set the static base URI when you compile a query using the API</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">XQueryCompiler.setBaseURI()</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">The base URI doesn't have to have any particular relationship with the location of the query source code. However, the same base URI is used for compile time actions such as importing modules and schemas, and for run-time actions such as the doc() function, so this has limited usefulness.</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">The XQuery 3.1 spec allows more flexibility than this. §2.1.1 says:</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">If the value of the Static Base URI is based on the location of the query module (in the terminology of </span><a href="https://www.w3.org/TR/xquery-31/#RFC3986" style="color: rgb(3, 69, 117); text-decoration: none; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(187, 187, 187); padding: 0px 1px; margin: 0px -1px; font-family: sans-serif; orphans: 2; widows: 2;" class="">[RFC3986]</a><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">, the URI used to retrieve the encapsulating entity), then the implementation </span><strong style="font-family: sans-serif; orphans: 2; widows: 2;" class="">may</strong><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""> use different values for the Static Base URI during static analysis and during dynamic evaluation. This might be necessary, for example, if a query consisting of several modules is compiled, and the resulting object code is distributed to a different location for execution. It would then be inappropriate to use the same location when resolving </span><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", Monaco, monospace; font-size: 0.9em; break-inside: avoid; orphans: 2; widows: 2;" class="">import module</code><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""> declarations as when retrieving source documents using the </span><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", Monaco, monospace; font-size: 0.9em; break-inside: avoid; orphans: 2; widows: 2;" class="">fn:doc</code><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""> function. If an implementation uses different values for the Static Base URI during static analysis and during dynamic evaluation, then it is implementation-defined which of the two values is used for particular operations that rely on the Static Base URI; for example, it is implementation-defined which value is used for resolving collation URIs.</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">Saxon uses some of that flexibility for XSLT (where compiled stylesheets may now be deployed to a different location that the source code -- which is why that clause was introduced). But transportable compiled code is not yet available for XQuery.</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">In practice the way that most people achieve what you are looking for is to set a URIResolver for use by the doc() function. Your URIResolver can resolve the supplied relative URI against any base URI of its choosing. You can also use OASIS catalogs for complete freedom in redirecting requests.</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">What the spec doesn't offer is the ability to have a parameterized "declare base URI" declaration within the query itself. Might be a nice feature, but there are plenty of other ways of achieving the required effect.</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">Michael Kay</span></div><div class=""><span style="font-family: sans-serif; font-size: medium; orphans: 2; widows: 2; background-color: rgb(255, 255, 255);" class="">Saxonica </span></div><div class=""><div style="orphans: 2; widows: 2;" class=""><font face="sans-serif" size="3" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div style="orphans: 2; widows: 2;" class=""><font face="sans-serif" size="3" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div><br class=""><blockquote type="cite" class=""><div class="">On 1 May 2018, at 17:55, Andreas Mixich <<a href="mailto:mixich.andreas@gmail.com" class="">mixich.andreas@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello,<br class=""><br class="">Since the application I am writing can be installed on other hosts, the<br class="">`base-uri` must be configurable to that foreign host. I want to solve<br class="">this with a library module, that keeps domain specific configuration<br class="">separate to the user and which gets imported where needed.<br class=""><br class="">Test case:<br class=""><br class="">  declare namespace cfg = "ns:cfg";<br class="">  declare base-uri "{$cfg:base-uri}";<br class="">  declare variable $cfg:base-uri := "file:/S:/projects/xqfr/src/fragments/";<br class=""><br class="">  let $file := doc("xhtml5-page.xhtml")<br class="">  return $file<br class=""><br class="">Doing this test case, both Saxon and BaseX try to find the file in the<br class="">directory of their executable installation<br class=""><br class="">  [FODC0002] Resource 'C:/Program Files (x86)/BaseX/xhtml5-page.xhtml'<br class="">  does not exist.<br class=""><br class="">When using it in a module context, with Saxon I get:<br class=""><br class="">  Invalid URI config.xqm: Invalid base URI: Illegal character in scheme<br class="">  name at index 0: {$cfg:base-uri}: {$cfg:base-uri}<br class=""><br class="">Googling it, it appears to be Java itself, throwing the error message.<br class="">Thus the {$base-uri} may get passed verbatim, but when used outside of<br class="">the module context, it somehow gets caught, but without a signal.<br class=""><br class="">Long story short: Is there a way to achieve what I want? Is there a<br class="">reason against hoisting variables in XQuery, that get 'declared'?<br class=""><br class="">Would it make sense to file an enhancement request on '<a href="http://www.w3.org/Bugs" class="">www.w3.org/Bugs</a>' ?<br class=""><br class="">-- <br class="">Goody Bye, Minden jót, Mit freundlichen Grüßen,<br class="">Andreas Mixich<br class="">_______________________________________________<br class=""><a href="mailto:talk@x-query.com" class="">talk@x-query.com</a><br class="">http://x-query.com/mailman/listinfo/talk</div></div></blockquote></div><br class=""></div></body></html>