Jump to navigation Jump to search
1,151 bytes added ,  23:32, 24 January 2011
Added Leo's function (Thanks to Leo & Huib) from
== Transform List to Tree ==
This snippet transform a ''flat'' list of elements with <code>parentId</code>-references to a nested list.
<pre class="brush:xquery">
declare function local:link($entries as node()*, $id as xs:string) {
let $entry := $entries[@id eq $id],
$children := $entries[@parentId eq $id]
return element entry {
for $child in $children
return local:link($entries, $child/@id)
let $entries :=
<entry id="entry1" />
<entry id="entry2" parentId="entry1" />
<entry id="entry3" parentId="entry1" />
<entry id="entry4" parentId="entry2" />
<entry id="entry5" parentId="entry2" />
<entry id="entry6" parentId="entry3" />
<entry id="entry7" parentId="entry3" />
return local:link($entries/entry, 'entry1')
results in
<pre class="brush:xml">
<entry id="entry1">
<entry id="entry2" parentId="entry1">
<entry id="entry4" parentId="entry2"/>
<entry id="entry5" parentId="entry2"/>
<entry id="entry3" parentId="entry1">
<entry id="entry6" parentId="entry3"/>
<entry id="entry7" parentId="entry3"/>
administrator, Bureaucrats, editor, Interface administrators, reviewer, Administrators


Navigation menu