Search code examples
xmlsyntaxxquerybasexflwor

How to return a range of XML nodes with XQuery of FLWOR?


I'm interested in getting back a specific range of results, say from 99 to 199, or, perhaps, the last JSON object. While this works for small numbers or ranges, how can it be generalized or expanded to a larger range?

xquery version "3.0";

for $i in (1,2,3)
for $line in db:open("json_people")
return $line/json/_[$i]

Solution

  • You can avoid the nested loop, use the position() function and specify a range:

    db:open("json_people")/json/_[position() = 99 to 199]