Type: recursive functions in XQuery Description: an implementation of transitive closure of a location path via recursion functions in XQuery (see http://www.dimi.uniud.it/~francesc/xpathmark/PTbench.html for more instances) Target documents: any XMark document Queries: REC1) People that are bidders of open auctions that are watched by people that are bidders of open auctions that are watched by people... declare namespace fun = 'have.more.fun'; declare function fun:closure($input as node()*, $result as node()*) as node()* { let $current := $input/watches/watch/id(@open_auction)/bidder/personref/id(@person) let $new := $current except $result let $all := ($result,$new) return if(exists($new)) then ($new, fun:closure($new,$all)) else () }; (: the filter on the person element below has the effect of making deeper the recursion depth :) doc("auction.xml")/site/people/person[position() <= 5]/fun:closure(.,())/name REC2) Categories that are reachable from a given category through an arbitrary path in the category graph declare namespace fun = 'have.more.fun'; declare function fun:closure($input as node()*, $result as node()*) as node()* { let $current := $input/idref(.)[name() = "from"]/../@to let $new := $current except $result let $all := ($result,$new) return if(exists($new)) then ($new, fun:closure($new,$all)) else () }; doc("auction.xml")//category[@id="category0"]/@id/fun:closure(.,())/id(.)/name