optional parameter with default value of fn:static-base-uri()

Friday, 30 October 2026 · 4 messages · last reply 31 Oct 2026
AB
Andy Bunce30 Oct 2026 16:59 #

Hi,

I am trying to understand the XQ4 spec here https://qt4cg.org/specifications/xquery-40/xquery-40.html#eval_context

When the fn:static-base-uri <https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-static-base-uri> function is called within the initializing expression of an optional parameter in a function declaration, it returns the executable base URI of the relevant function call. This allows a user-written function to accept two parameters: a required parameter containing a relative URI, and an optional parameter containing a base URI. The optional parameter can be given a default value of fn:static-base-uri(), allowing the code in the function body to *resolve the relative URI against the executable base URI of the caller.*

In the code below I was expecting the result to be relative to the location of run.xq not a/lib.xqm. Am I misunderstanding the spec here or this a BaseX (13.0 beta 3be3f1d) issue?

/Andy

-----------a/lib.xqm----------------------------------
module namespace cm = 'app/cm';
(:~ resolve :)
declare function cm:r($file as xs:string,
                      $base as xs:string :=static-base-uri())
as xs:string{
  resolve-uri($file,$base)
};

-----------run.xq------------------
import  module namespace cm = 'app/cm' at "a/lib.xqm";
cm:r("file.xml")
CG
Christian Grün30 Oct 2026 18:27 #

Hi Andy,

Indeed it’s the spec that is inconsistent here and must be updated [1].

Thanks for the observation! Christian

[1] https://github.com/qt4cg/qtspecs/issues/3023#issuecomment-6528899541

Quoted text · Andy Bunce · 24 lines
Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Freitag, 30. Oktober 2026 um 17:10: > Hi, > > I am trying to understand the XQ4 spec here https://qt4cg.org/specifications/xquery-40/xquery-40.html#eval_context > > When the [fn:static-base-uri](https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-static-base-uri) function is called within the initializing expression of an optional parameter in a function declaration, it returns the executable base URI of the relevant function call. This allows a user-written function to accept two parameters: a required parameter containing a relative URI, and an optional parameter containing a base URI. The optional parameter can be given a default value of fn:static-base-uri(), allowing the code in the function body to resolve the relative URI against the executable base URI of the caller. > > In the code below I was expecting the result to be relative to the location of `run.xq` not `a/lib.xqm`. > Am I misunderstanding the spec here or this a BaseX (13.0 beta 3be3f1d) issue? > > /Andy > > -----------a/lib.xqm---------------------------------- > module namespace cm = 'app/cm'; > (:~ resolve :) > declare function cm:r($file as xs:string, > $base as xs:string :=static-base-uri()) > as xs:string{ > resolve-uri($file,$base) > }; > > -----------run.xq------------------ > import module namespace cm = 'app/cm' at "a/lib.xqm"; > cm:r("file.xml")
AB
Andy Bunce30 Oct 2026 18:54 #

Hi Christian,

First: Congratulations on the BaseX 13 release. I know there is so much good stuff in there from playing with the betas. And, I welcome the return of an official Docker release :-)

Regarding default params and static-base-uri I think is it a bit of shame this behaviour has been dropped from the spec. I liked the idea, but I guess it might make things complicated and interconnected. I will have to go back to passing the base-uri into my functions.

Thanks /Andy

Quoted text · Christian Grün · 54 lines
On Fri, 30 Oct 2026 at 17:27, Christian Grün <cg at basex.org> wrote: > Hi Andy, > > Indeed it’s the spec that is inconsistent here and must be updated [1]. > > Thanks for the observation! > Christian > > [1] https://github.com/qt4cg/qtspecs/issues/3023#issuecomment-6528899541 > > > Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am > Freitag, 30. Oktober 2026 um 17:10: > > Hi, > > I am trying to understand the XQ4 spec here > https://qt4cg.org/specifications/xquery-40/xquery-40.html#eval_context > > When the fn:static-base-uri > <https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-static-base-uri> > function is called within the initializing expression of an optional > parameter in a function declaration, it returns the executable base URI of > the relevant function call. This allows a user-written function to accept > two parameters: a required parameter containing a relative URI, and an > optional parameter containing a base URI. The optional parameter can be > given a default value of fn:static-base-uri(), allowing the code in the > function body to *resolve the relative URI against the executable base > URI of the caller.* > > In the code below I was expecting the result to be relative to the > location of `run.xq` not `a/lib.xqm`. > Am I misunderstanding the spec here or this a BaseX (13.0 beta 3be3f1d) > issue? > > /Andy > > > -----------a/lib.xqm---------------------------------- > module namespace cm = 'app/cm'; > (:~ resolve :) > declare function cm:r($file as xs:string, > $base as xs:string :=static-base-uri()) > as xs:string{ > resolve-uri($file,$base) > }; > > -----------run.xq------------------ > import module namespace cm = 'app/cm' at "a/lib.xqm"; > cm:r("file.xml") > > > >
CG
Christian Grün31 Oct 2026 17:19 #

Hi Andy,

I understand the regret. We kept the exception as narrow as possible (focus-only). If the base URI depended on the caller, it would include surprises such as the following one:

module namespace lib = 'lib';
declare function lib:settings($config := doc('config.xml')) {
$config/settings/*
};

If we take the context of the caller, the document URI is resolved against the caller’s base URI, not the one from the library. Similar surprises can happen with collations other context properties.

But it’s still all in flux. Feel free to create a qtspecs issue to trigger some discussion!

Quoted text · Andy Bunce · 1 line
Andy Bunce <bunce.andy at gmail.com> schrieb am Freitag, 30. Oktober 2026 um 18:54:

Hi Christian,

First: Congratulations on the BaseX 13 release. I know there is so much good stuff in there from playing with the betas. And, I welcome the return of an official Docker release :-)

Regarding default params and static-base-uri I think is it a bit of shame this behaviour has been dropped from the spec. I liked the idea, but I guess it might make things complicated and interconnected. I will have to go back to passing the base-uri into my functions.

Thanks /Andy


⚡Generated with XQuery