[xquery-talk] creating tree from sequence (from tree)
Ghislain Fourny
gfourny at inf.ethz.ch
Sat May 7 00:43:29 PDT 2011
Hi,
Would something like the following help? It organizes the selected nodes according to the hierarchy of their parents, which is my understanding of the problem statement (but I could be wrong).
declare function local:filter($tree as node(), $selected-nodes as node()*) {
let $selected-child :=
$selected-nodes[some $child in $tree/node() satisfies . is $child]
let $recursively-filtered-children :=
for $n in $tree/node() return local:filter($n, $selected-nodes)
return
if ($selected-child)
then
element
{ name($selected-child[1]) }
{ $selected-child/attribute(),
$selected-child/text(),
$recursively-filtered-children }
else
$recursively-filtered-children
};
I tested it with local:filter($doc, $nodes) with $doc and $nodes defined in your e-mail, and obtained the desired result.
Kind regards,
Ghislain
More information about the talk
mailing list