1
votes

I have a fairly simple XQuery function that returns a sequence of IDs.

declare function local:get-ids($param as xs:string) {
  ...do something...
  return $ids
}

What I want to do is combine return values like this:

for $ids in local:get-ids("something") | fn:subsequence(local:get-ids("something else"), 5)

This isn't working, though. I'm getting an error saying that one of the IDs is not a node. I am able to run this with each sequence individually, but when I try to combine them it fails. What's the proper way to do this?

Thanks>

2
What do you mean by combining sequences? Do you want to concatenate them, do a set-union (as | does for node sets, plus sorting in document order) or merge them in a more complicated way? - Leo Wörteler

2 Answers

3
votes

There are no nested sequences in xquery, so you can just join two sequences together like this:

let $s1 := ('a', 'b')
let $s2 := ('a', 'c')

return ($s1, $s2)

The result will just be ('a', 'b', 'a', 'c'), so in your case you can do:

for $ids in (local:get-ids("something"), fn:subsequence(local:get-ids("something else"), 5))

optionally you could wrap it in a distinct-values(....) to get only distinct ids

0
votes

You don't declare the return type of your local:get-ids() function, but to judge from the error message, it's returning strings, and not nodes. The union operator works only on sequences of nodes; to combine sequences of values you can use comma (if you don't need to remove duplicate values) or comma and then distinct-values (if you do):

for $ids in (local:get-ids("something"),
  fn:subsequence(local:get-ids("something else"),
  5)
...

or

for $ids in distinct-values( (local:get-ids("something"),
  fn:subsequence(local:get-ids("something else"),
  5))
...