Changeset 618 for MDRepository


Ignore:
Timestamp:
08/11/10 14:45:50 (14 years ago)
Author:
ljo
Message:

First take on new getCollections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDRepository/trunk/xquery/cmd-model.xqm

    r570 r618  
    7878  Recurse for collections
    7979:)
    80 declare function cmd-model:recurse-collections($collection as xs:string, $depth as xs:integer) as item()* {
    81     let $children := xdb:get-child-collections($collection)
     80declare function cmd-model:recurse-collections($collection as node()+, $parent as xs:string, $depth as xs:integer) as item()* {
     81    let $children := if ($depth eq 0) then () else $collection//ResourceProxy[ResourceType = "Metadata"]
    8282    return
    8383      if (fn:exists($children)) then
    8484          let $child-results :=
    8585            for $child in $children
    86             return
    87               cmd-model:recurse-collections(concat($collection, '/', xs:string($child)), $depth),
    88               $current := <Collection name="{text:groups($collection, "/([^/]+)$")[last()]}">{$collection}</Collection>
    89           return ($current, $child-results)
     86              let $child-doc := doc(concat(util:collection-name($child/root()), "/", $child/ResourceRef)),
     87                $child-name := ($child-doc//Corpus/Name, "UNKNOWN")[1]
     88            return if (empty($child-doc)) then <no-target>{util:collection-name($child/root())}</no-target> else
     89              cmd-model:recurse-collections($child-doc, $child-name, $depth - 1)
     90          return
     91          <c n="{$parent}" cnt="{sum($child-results/@cnt)}">{$child-results}</c>
    9092      else
    91       <Collection>{$collection}</Collection>
     93      <c n="{$parent}" cnt="{count($collection//CMD)}"></c>
    9294};
    9395
     
    258260      else
    259261        let $children := for $collection-item in $collections
    260         return
    261           cmd-model:recurse-collections($collection-item, $max-depth)
     262          let $collection-item-doc := collection(concat($collection-item, "/", "Corpusstructure"))
     263        return
     264          cmd-model:recurse-collections($collection-item-doc, "", $max-depth)
    262265          return
    263266            cmd-model:store-collection-data(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $names[1], $names[2])
Note: See TracChangeset for help on using the changeset viewer.