Below is the sample code where $p2
is an optional external parameter
(i.e. with ? modifier
); the code gives XDMP-ARG: -- vars is invalid
exception when empty sequence-()
is passed against $p2
.
Tried it on Marklogic 8 & 9
let $query :=
"
declare variable $p1 as node()? external;
declare variable $p2 as node()? external;
(
if($p1) then xdmp:log('P1') else ()
,
if($p2) then xdmp:log('P2') else ()
)
"
let $p1 := <p></p>
let $p2 := ()
return
xdmp:eval(
$query,
(xs:QName('p1'), $p1, xs:QName('p2'), $p2)
)
I expected the code to run and print logs. Can I get some deep insights into how the exception occurred?
If you pass in vars as a Sequence of key,val,key,val it needs to be even (multiple of 2). You can't embed sequences like that, as nested sequences get flattened automatically in XQuery. Pass in your vars using a map:map:
map:new((
map:entry("p1", $p1),
map:entry("p2", $p2),
))
HTH!