xdmp:eval($s, (), "world"))
Instead of default value as second parameter from the above code, i want to pass map as the parameter to the external function.
xdmp:eval($s, (), "world"))
Instead of default value as second parameter from the above code, i want to pass map as the parameter to the external function.
If $s
has e.g. declare variable $v1 external;
in the prolog then I think you can use xdmp:eval($s, map:new(map:entry('{}v1', some-expression)))
, or, as pointed out in a comment, even xdmp:eval($s, map:new(map:entry('v1', some-expression)))
to pass the result of evaluating some-expression
as the value of the variable $v1
e.g. xdmp:eval($s, map:new(map:entry('v1', 'foo')))
passes in the string value foo
.
As indicated in the documentation for xdmp:eval()
you can either pass a sequence of alternating QName and value, or you can pass a map.
External variable values to make available to the evaluated code, expressed as either a sequence of alternating QName-value pairs, or a
map:map
.
- If you use a sequence, it must contain alternating variable QNames and values. e.g.
(xs:QName("var1"), "val1", xs:Qname("var2"), "val2")
.- If you use a map, then each key is a string representing the Clark notation of the variable QName ("{namespaceURI}localname"), and its value is the corresponding variable value. You can use
xdmp:key-from-QName
to generate the Clark notation to use as a key.
The example from xdmp:eval()
documentation shows how to invoke with the sequence:
xquery version "1.0-ml";
declare namespace my='http://mycompany.com/test';
let $s :=
"xquery version '1.0-ml';
declare namespace my='http://mycompany.com/test';
declare variable $my:x as xs:string external;
declare variable $my:y as xs:string external := 'goodbye';
concat('hello ', $my:x, ' ', $my:y)"
return
(: evaluate the query string $s using the variables
supplied as the second parameter to xdmp:eval :)
xdmp:eval($s, (xs:QName("my:x"), "world"))
So, instead of (xs:QName("my:x"), "world")
you need to create a map:map
and create an entry with the key of the QName as Clark notation: {http://mycompany.com/test}x
and the value "world" for that entry.
The way to invoke with a map:map
would be:
let $vars := map:new() => map:with(xdmp:key-from-QName(xs:QName("my:x")), "world")
return
xdmp:eval($s, $vars)