XQuery allows recursion. For some approach (e.g., algebraic ones), it is hard to suport this fully. Some examples of functions I recently wrote: declare function product($seq as xs:decimal*) as xs:decimal { if (count($seq) gt 0) then exactly-one($seq[1]) * product($seq[position() gt 1]) else 1.0 }; declare function allCombinations($wlists as element(wlist)*) as element(wlist)* { let $cnt := count($wlists) return if ($cnt eq 0) then () else if ($cnt eq 1) then for $x in $wlists/child::w return {$x} else let $y := exactly-one($wlists[1]) ,$ys := $wlists[position() gt 1] ,$as := allCombinations($ys) return for $x in $y/child::w, $a in $as return {$x}{$a/child::w} }; Recursion usually 'follows' the XML hierarchy (by descending into an XML tree), the order in sequences, some diminishing computation, or a combination thereof. Mutual recursion, etc. all are possible in XQuery.