2
votes

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]
2
It’s not clear to me what you want to achieve. Most of all, I am confused about the naming of your variables. Does db:open really return lines? Could you please replace the database function with an XML snippet that allows us to run your code without further modifications?Christian Grün
it wasn't anything specifically, just to get a range of results. The line is a bad name, yes. I kept trying from (99..199) or other variations but couldn't find the correct syntax.Thufir

2 Answers

3
votes

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

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

You can use range in XQuery as follows:

for $i in (99 to 199)