Skip to content

Instantly share code, notes, and snippets.

@dscape
Created September 8, 2010 10:41
Show Gist options
  • Save dscape/569946 to your computer and use it in GitHub Desktop.
Save dscape/569946 to your computer and use it in GitHub Desktop.
let $l := ('a','b','c','d','e','f','g','h')
let $c := count($l)
let $n := 4
let $m := if ($n > $c) then $c else $n
let $step := ceiling( $c div $m )
return (
concat("l=", string-join($l, ", "), " c=", $c, " n=", $n, " step=", $step),
for $i in (1 to $m)
let $s := xs:integer( 1 + ( ( $i - 1 ) * $step ) )
let $f := xs:integer( $s + $step - 1 )
return <partition>
<n>{$s}, {$f}</n>
<l>{string-join($l [$s to $f], ", ")}</l>
</partition>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment