Changeset 743 for MDRepository


Ignore:
Timestamp:
10/04/10 09:16:39 (14 years ago)
Author:
ljo
Message:

First step elem-r() pass collections as nodes.

File:
1 edited

Legend:

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

    r732 r743  
    3939
    4040declare function cmd-model:elem($collections as xs:string+, $path as xs:string, $depth as xs:integer) as element() {
    41 (: fixme! - handle multiple collections :)
    42 cmd-model:elem-r($collections, $path, $depth, $depth)
    43 };
    44 
    45 declare function cmd-model:elem-r($collections as xs:string+, $path as xs:string, $max-depth as xs:integer, $depth as xs:integer) as element() {
    4641  let $collection := collection($cmd-model:cmdiMirrorPath),
    4742    $path-nodes :=
    4843    if ($collections[1] eq $cmd-model:collectionRoot) then
    49       util:eval(fn:concat("$collection//", $path))
     44      util:eval(fn:concat("$collection/descendant-or-self::", $path))
    5045    else
    5146      for $coll in $collections
    5247      return
    53         util:eval(fn:concat("$collection//ft:query(descendant::IsPartOf, <query><term>", xdb:decode($coll), "</term></query>)//", $path, "/ancestor::CMD"))
    54 
     48        util:eval(fn:concat("$collection/ft:query(descendant::IsPartOf, <query><term>", xdb:decode($coll), "</term></query>)/ancestor-or-self::CMD/descendant-or-self::", $path))
     49        return
     50          cmd-model:elem-r($path-nodes, $path, $depth, $depth)
     51};
     52
     53declare function cmd-model:elem-r($path-nodes as node()+, $path as xs:string, $max-depth as xs:integer, $depth as xs:integer) as element() {
    5554      let $path-count := count($path-nodes)
    56    
    5755      let $subs := distinct-values($path-nodes/child::element()/name())
    58       let $text-nodes := $path-nodes//text()
     56      let $text-nodes := for $node in $path-nodes[child::element()[not(child::element())]] return $node//text()
    5957      let $text-count := count($text-nodes)
    6058      let $text-count-distinct := count(distinct-values($text-nodes))
     
    6462            (for $elname in $subs[. != '']
    6563            return
    66               cmd-model:elem-r($collections, concat($path, '/', $elname), $max-depth, $depth - 1),
     64              cmd-model:elem-r($path-nodes, concat($path, '/', $elname), $max-depth, $depth - 1),
    6765              if ($max-depth eq 1) then cmd-model:values($path-nodes) else ())
    6866          else 'maxdepth'
Note: See TracChangeset for help on using the changeset viewer.