I have been making function calls at the end of xpath statements as a kind
of best practice to hedge against the possibility that part of the path
may resolve to empty (and prevent calling a function that doesn't handle
empty): a/b/x:y(.) - however, I recently came across a scenario where this
is affecting the order of the called function output:
declare function local:dostuff(
$a as xs:string?,
$b as xs:string?
) as element()*
{
$a ! <a>{ $a }</a>,
$b ! <b>{ $b }</b>
};
let $x := <x><a>a</a><b>b</b></x>
for $i in (1 to 100)
return
deep-equal(
$x/local:dostuff(./a, ./b),
local:dostuff($x/a, $x/b))
I expect these to always be equal since $x is a sequence of 1, so
dostuff() is only ever called once (with identical parameters). Or I would
expect both calls to return results in non-deterministic order, but only
the first call is ever out of order:
deep-equal(
local:dostuff($x/a, $x/b),
local:dostuff($x/a, $x/b)) => always true
deep-equal(
$x/local:dostuff(./a, ./b),
$x/local:dostuff(./a, ./b)) => non-deterministic
-Will
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general