[xquery-talk] creating tree from sequence (from tree)

trubliphone trubliphone at googlemail.com
Tue May 10 12:30:18 PDT 2011


Hi,

Thanks very much for this.  It basically does the trick.  There are
some nuances in the real problem that need addressing, but you've got
me 90% of the way there.



On Sat, May 7, 2011 at 12:43 AM, Ghislain  Fourny <gfourny at inf.ethz.ch> wrote:
> 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