<div dir="ltr">Hi,<div><br></div><div>I feel like I try to get a hold on a piece of wet soap with this...</div><div><br></div><div>Background: Atom Syndication has an extension[1], which allows threading of entries. These entries are ordered in a flat sequence, one by one.</div><div>As a result we end up with an Atom feed, that has a bunch of entries, where each entry could have a reference to the ID of another entry, which would then be it's parent.</div><div>No nesting is done.</div><div><br></div><div>A simplified input could look like this:</div><div><br></div><div><font face="monospace">declare variable $local:example :=  </font></div><div><font face="monospace">let $xml := <xml><br>  <item id="e1" /><br>  <item id="e2" refid="e1" /><br>  <item id="e3" refid="e2" /><br>  <item id="e4" refid="e2" /><br>  <item id="e5" refid="e4" /></font></div><div><font face="monospace">  <item id="e6" /><br></xml><br></font><div><br></div><div>The task I want to accomplish is to create an output <i>tree</i> of <i>nested</i> sections, resembling the natural flow of replies:</div><div><br></div><div><font face="monospace"><result><br>  <section id="e1"></font></div><div><font face="monospace">    <section id="e2" refid="e1"></font></div><div><font face="monospace">      <section id="e3" refid="e2" /></font></div><div><font face="monospace">      <section id="e4" refid="e2"></font></div><div><font face="monospace">        <section id="e5" refid="e4" /></font></div><div><font face="monospace">      </section></font></div><div><font face="monospace">    </section></font></div><div><font face="monospace">  </section></font></div><div><font face="monospace">  <section id="e6" /></font></div><div><font face="monospace"></result></font><br></div><div><br></div><div>One of the many queries I tried is:</div><div><br></div><div><font face="monospace">declare function local:rec($data) {<br>  if (empty($data))<br>  then ()<br>  else (<br>         let $current := head($data)<br>         let $children := tail($data)[@refid = $current/@id]<br>         return (<br>                  <section id="{$current/@id}"><br>                  { <br>                    $current/*<br>(:                  , prof:dump("current: " || $current/@id/data() || " children: " || $children/@id/data() => string-join())</font></div><div><font face="monospace">:)<br>                  , for $child in $children<br>                    return local:rec($children)<br>                  }<br>                  </section><br>                  , local:rec(tail($data))<br>                )<br>       )<br>};<br><br></font></div><div><font face="monospace"><result> </font></div><div><span style="font-family:monospace">  { local:rec($local:example/</span><span style="font-family:monospace">item) } </span></div><div><span style="font-family:monospace"></result></span></div><div><br></div><div>Of course, this has not yet any logic, to keep out the already processed items (besides other issues). </div><div>When I tried that, however, by removing them from the return sequence, I found no way to break out </div><div>of scope and have that modified return sequence go back to the next recursion.</div><div><br></div><div>Previous example results in this, btw.:</div><div><br></div><div><font face="monospace"><section id="e1"><br>  <section id="e2"/><br></section><br><section id="e2"><br>  <section id="e3"/><br>  <section id="e4"/><br>  <section id="e3"/><br>  <section id="e4"/><br></section><br><section id="e3"/><br><section id="e4"><br>  <section id="e5"/><br></section><br><section id="e5"/><br><section id="e6"/></font><br></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">I can't believe, that there is no super easy way to do it. Any help would be greatly appreciated!</font></div><div><br></div>-- <br><div dir="ltr" data-smartmail="gmail_signature">Minden jót, all the best, Alles Gute,<br>Andreas Mixich</div></div></div>