[xquery-talk] paging mechanism

David Carlisle davidc at nag.co.uk
Fri Feb 3 11:24:25 PST 2006



> for $doc in //text
> order by $doc/body/idno
> ascending return
> if($doc[(position() mod 50) < 2])then
> (
> $doc/body/idno
> )
> else()


the variable ($doc here) in a for is _always_ bound to a sequence of
length 1 corresponding to one of the items in the sequence that is being
iterated over. 
so in $doc[ ....]  position() is always equal to 1 (as it is a sequence
of length 1) so [(position() mod 50) < 2] is always true and doesn't
filter anything.

You want to use the positions in the sorted sequence (I think you want 
position()mod 50=1 (ie 1,51,101)  rather than (position() mod 50) < 2
(ie 1,50,51,100,101,...)

so

(for $x idno order by number($x) return $x)[position() mod 50 =1]

sorts into order then returns every 50th item.

For your second case
> Again, do you have any idea what went wrong?
the sequence of numbers that you show as the result looks rather odd,
but as you didn't show your input I can't guess. Your query takes the
first 10 items from the unsorted input, then sorts them. Does that match
your result?

David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the talk mailing list