Another option that you may want to consider is passing an xs:string of
comma separated values, then use fn:tokenize on the receiving side to
expand the sequence.
xdmp:eval("define variable $numbers as xs:string external
let $tok := fn:tokenize($numbers, ',')[not(. = '')]
let $int-seq := for $i in $tok return xs:integer($i)
return fn:sum($int-seq)
", (xs:QName("numbers"), "1,2,3"))
==> 6
Danny Sokolsky wrote:
Hi David,
Yes, that is correct, you cannot pass a sequence as the value of an
external variable. As you surmised, the way to do that is to wrap the
sequence values in XML and pass the node. Then you can use XPath to get
the values from the node.
Also, you can pass as many external variables as you need. They just
need to be an even-length sequence alternating between QNames and items.
For example, the following returns (1,2,3):
xdmp:eval("define variable $a as xs:integer external
define variable $b as xs:integer external
define variable $c as xs:integer external
$a, $b, $c", (xs:QName("a"), 1, xs:QName("b"), 2, xs:QName("c"), 3))
Similarly, the following is how you might use a node to do something
similar:
xdmp:eval("define variable $a as node() external
$a//a/text()", (xs:QName("a"), <foo><a>1</a><a>2</a><a>3</a></foo>))
I hope that helps to clarify.
-Danny
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David
Sewell
Sent: Thursday, November 29, 2007 7:22 AM
To: General XQZone Discussion
Subject: [MarkLogic Dev General] Passing sequence as variable to
xdmp:eval()?
Is there a way to pass a sequence rather than a node or atomic value as
an external variable to xdmp:eval()?
This works, returning '9' as output:
define variable $sequence as xs:integer* { (9) }
xdmp:eval(
'define variable $seq as xs:integer* external
$seq',
(xs:QName("seq"), $sequence)
)
but this produces an XDMP-ARG error
define variable $sequence as xs:integer* { (9, 11) }
xdmp:eval(
'define variable $seq as xs:integer* external
$seq',
(xs:QName("seq"), $sequence)
)
because the second argument to xdmp:eval is parsed as
(xs:QName("seq"), 9, 11)
when $sequence is flattened.
Is the only option in a case like this to wrap my sequence of integers
in a constructed XML element and pass that as the external variable to
xdmp:eval(), or am I missing something obvious?
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general