[xquery-talk] paging mechanism

Peter Mueller Peter.Mueller10 at gmx.de
Fri Feb 3 11:09:38 PST 2006

Hi everybody,

here is what I am trying to achieve ...

I would like to implement a paging mechanism that offers access to several
collections with between 500 and 3000 documents.

When the web user selects one collection he should be presented with some
kind of sub folder hierarchy where each "sub folder" contains "chunks" of -
lets say 50 - documents. These "sub folders" should be labeled with the time
period they belong to (to allow the user more specific access), e.g.:
and so on...

If a user then chooses one time interval (lets say "1980-1983") he should be
given a navigating structure (like [1-10] [11-20] ... [41-50]) (trivial if
PROBLEM 2 is solved --> see below) along with some metadata of the first 10
"hits" (PROBLEM 2!). 

For solving the first problem I need to first sort the documents (by date)
and then extract the years from which the 1st, the 50th, the 51st and so on
documents originate. 

For this tried a couple of queries (see below) which unfortunatelly didn't
yield the expected results (using SAXON).

I tested my query on just one xml file which contains 147 test-documents.

[I used <idno> instead of <date> for sorting and as result because it's
easier for testing.]

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

Instead of the expected:

... I got the idno of all the docs:

The same happended when I replaced the line
if($doc[(position() mod 50) < 2])then  
if((position() mod 50) < 2)then  

Finally, I tried:

for $id at $pos in //text/body/idno
order by xs:integer($id) ascending
if ($id[$pos mod 50 < 2]) then $id
else () 

leaving me with:


Do you have any suggestions as to how this could work correctly?

For solving the second problem I would need the same sorting as above and
then extract some metadata from the documents at position number 1 to 10
(11-20, etc...) in the resulting sequence. 

To solve this I tried:

declare variable $startIndex as xs:integer := 1;
declare variable $pageSize as xs:integer := 10;
for $idno in 
fn:subsequence( //text/body/idno, $startIndex, $pageSize)
order by $idno
return $idno

instead of the expected:

I got:

Again, do you have any idea what went wrong?

Thank you very much for your help!

Best wishes,

10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
+++ GMX - die erste Adresse für Mail, Message, More +++

More information about the talk mailing list