On 5 January 2014 21:20, Michael Kay <[email protected]> wrote:
>
> On 5 Jan 2014, at 20:59, David Lee <[email protected]> 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)


Couldn't you use uri-collection() to give you an order, rather than
the collection() directly?


-- 
Andrew Welch
http://andrewjwelch.com
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to