declare variable $partlist := doc("docs/parts.xml"); declare function local:one_level($p as element()) as element() { { for $s in $partlist//part where $s/@partof = $p/@partid return local:one_level($s) } };