Skip to content

Instantly share code, notes, and snippets.

@eedeebee
Created January 7, 2014 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eedeebee/8303191 to your computer and use it in GitHub Desktop.
Save eedeebee/8303191 to your computer and use it in GitHub Desktop.
Grouping the values from a range index
xquery version "1.0-ml";
declare namespace sample = "http://marklogic.com/sample";
let $groupsize := 1000
let $values := cts:element-values(xs:QName("sample:value"))
let $count := fn:count($values)
let $groups :=
for $i in (0 to (xs:int($count div $groupsize) + 1))
let $group := $values[(($i * $groupsize) + 1) to (($i + 1) * $groupsize)]
return fn:string-join($group, "|")
return (fn:count($groups), $groups)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment