xquery version "1.0"; declare function local:path($start, $finish, $visited, $links) { (: finds a path between two nodes - links are unweighted and search is depth-first :) if ($start = $finish) then end else let $paths := for $link in $links[node=$start] [not(node = $visited)] let $node := $link/node[. != $start] let $path := local:path($node, $finish, ($visited,$start) ,$links) return if (exists($path)) then {($link, $path)} else () return $paths[1]/* }; declare function local:listLinks($start, $links) { (: recursively print the path from $start :) if (exists($links)) then let $link := $links[1] let $next := $link/node[. !=$start] let $row := {$link/type}{$next} return ($row, local:listLinks($next,remove($links,1))) else () }; let $from := request:request-parameter("from","") let $to := request:request-parameter("to","") let $links := doc('/db/chriswallace/graph/links.xml')//link let $path := local:path($from,$to, (), $links ) return {local:listLinks($from, $path)}
From{$from}