On my recently launched site I present documents, each of which has a distinct number between MS609-0001...MS609-3826. When I present a document, such as MS609-0003, a side bar should show the previous/next 5 documents in order, assuming a start from the first document in alpha-numeric order. But, looking at http://medieval-inquisition.huma-num.fr/doc/MS609-0003 the document list is:
MS609-0001 Arnald Garnier
MS609-0002 Guilhem de Rosengue
> MS609-0003 Hugo de Mamiros
MS609-0004 P Lapassa senior
MS609-0005 Guilhem de la Silva
MS609-0006 Pons Rainart
MS609-0007 B de Vasega
MS609-0008 P de Vasega
MS609-3824 Arnaut Bartholomieu
MS609-3825 Arnaut Ademar
MS609-3826 Arnaud Sabater
Evidently the code is looping back through a list of documents and going to the 'end' to get enough for 10 documents. It does the same (in reverse) when you look towards the end http://medieval-inquisition.huma-num.fr/doc/MS609-3825 .
The XQuery for getting these records uses a subsequence()
.
let $listlength := 10
let $docprefix := "MS609"
let $list := xmldb:get-child-resources($globalvar:URIdata)[starts-with(., $docprefix)]
let $i := index-of($list, "MS609-0003.xml")
(: $listlength should be an odd number to place the active doc in the middle :)
let $listlength := if ($listlength mod 2 = 0) then ($listlength + 1) else $listlength
(: reduce list to max ODD number requested :)
let $list := subsequence($list, $i - (($listlength - 1) div 2), $listlength)
for $x in $list
order by $x ascending
return $x
I'm at a loss as to how to operatively prevent the code from returning to the end/beginning of the list.
This is XQuery 3.1 under eXist-db 3.6.