[xquery-talk] Collections - family relationships
David Lee
dlee at calldei.com
Sun Jan 5 13:24:02 PST 2014
Arg ... so your saying index-of causes a string atomization ?
Ug. I know it wants item* and uses "eq" as the comparison but didn't realize that would stringify documents ...
Do you know of a sequence function that uses document or node ID's ?
----------------------------------------
David A. Lee
dlee at calldei.com
http://www.xmlsh.org
-----Original Message-----
From: Michael Kay [mailto:mike at saxonica.com]
Sent: Sunday, January 05, 2014 4:21 PM
To: David Lee
Cc: ihe.onwuka at gmail.com; talk at x-query.com
Subject: Re: [xquery-talk] Collections - family relationships
On 5 Jan 2014, at 20:59, David Lee <dlee at calldei.com> wrote:
> Given those truths ...
> If you do have a sequence from fn:collection() or another function you *can* find the position of a document in that collection and its 'sibling'
>
> Note: this may be a horribly inefficient thing to do so buyer beware ....
>
> let $c := fn:collection(),
> $doc := local:pick-a-random-doc( $c ),
> $prev := $c[ fn:index-of( $c , $doc ) - 1 ] (: Might be bad to do on the first or only document :)
> return $c
>
>
This only works if all the documents have distinct string-values.
A more efficient and reliable approach would be
min(for $c at $i in collection() where $c is $doc return $i)
Michael Kay
Saxonica
More information about the talk
mailing list