[xquery-talk] Setting global variables

Ronald Bourret rpbourret at rpbourret.com
Wed Oct 31 12:16:37 PST 2007


Hi, John,

Unfortunately, this does not solve my problem. The name of the document 
can vary, so I can't simply initialize a variable.

One possibility is to make the variable external to the library and then 
set it from the calling query. This would require an 
implementation-specific function -- I'm using Saxon -- and appears to 
violate the XQuery notion of not changing variable values.

One could make the argument that external variables already violate the 
notion of not changing variable values to some extent, and extending 
that capability to libraries is not unreasonable. On the other hand, one 
could also argue that libraries are already parameterized through 
function arguments.

-- Ron

John Snelson wrote:
> Hi Ronald,
> 
> There is no way to do what you're asking, since XQuery is a functional 
> language and variable values cannot be changed.
> 
> What's wrong with something like this:
> 
> declare variable $foo:listOfNames := fn:doc("mydoc.xml")//Name;
> 
> declare function foo:firstFunctionCalled(...)
> {
>   ...
> };
> 
> declare function foo:functionCalled MuchLater(...)
> {
>   ...
>   if ($name = $foo:listOfNames)
>   ...
> };
> 
> John



More information about the talk mailing list