Index: MDRepository/trunk/xquery/cmd-model.xql
===================================================================
--- MDRepository/trunk/xquery/cmd-model.xql	(revision 641)
+++ MDRepository/trunk/xquery/cmd-model.xql	(revision 654)
@@ -22,11 +22,24 @@
     $format := request:get-parameter("format", $cmd-model:responseFormatXml),
     $collection := "/db/cmdi-mirror",
-    $query-model-collection := fn:concat($collection, "/", if (fn:empty(request:get-parameter("collection", ()))) then "silang_data" else ""),
+    $collection-params := request:get-parameter("collection", ()),
+    $query-model-collection := 
+    if (fn:empty($collection-params)) then fn:concat($collection, "/")
+    else
+      for $coll in $collection-params 
+      return 
+	if (starts-with($coll, "test-")) then
+	  $coll
+	else
+	  fn:concat($collection, "/", $coll),
     $query-collections := 
-    if (fn:empty(request:get-parameter("collection", ()))) then
+    if (fn:empty($collection-params)) then
       $collection
     else
-      for $coll in request:get-parameter("collection", ()) 
-      return fn:concat($collection, "/", $coll),
+      for $coll in $collection-params 
+      return 
+	if (starts-with($coll, "test-")) then
+	  $coll
+	else
+	  fn:concat($collection, "/", $coll),
     $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1))
     return
Index: MDRepository/trunk/xquery/cmd-model.xqm
===================================================================
--- MDRepository/trunk/xquery/cmd-model.xqm	(revision 641)
+++ MDRepository/trunk/xquery/cmd-model.xqm	(revision 654)
@@ -84,7 +84,7 @@
 	  let $child-results :=
 	    for $child in $children
-	      let $child-doc := doc(concat(util:collection-name($child/root()), "/", $child/ResourceRef)),
+	      let $child-doc := if (empty($child/unresolvable-uri)) then doc(concat(util:collection-name($child/root()), "/", $child/ResourceRef)) else (),
 		$child-name := ($child-doc//Corpus/Name, $child-doc//Session/Name, "UNKNOWN")[1]
-            return if (empty($child-doc)) then <no-target proxy-id="{$child/@id}">{<proxy>{$child}</proxy>, <in-document>{concat(util:collection-name($child/root()), "/", util:document-name($child/root()))}</in-document>}</no-target> else
+            return if (empty($child-doc)) then () (:<no-target proxy-id="{$child/@id}">{<proxy>{$child}</proxy>, <in-document>{concat(util:collection-name($child/root()), "/", util:document-name($child/root()))}</in-document>}</no-target> :) else
               cmd-model:recurse-collections($child-doc, $child-name, $child-doc//Header/MdSelfLink, $child/@id, $depth - 1)
 	  return
@@ -225,5 +225,14 @@
 
 
-
+(:
+  Get the resource by handle or by path. 
+:)
+declare function cmd-model:get-resource-by-handle-or-collection-path($id as xs:string) as node()? {
+  (: fixme! - urldecode $id when we decide to pass them encoded from the client.  :)
+  if (starts-with($id, "test-")) then
+    collection($cmd-model:cmdiMirrorPath)//MdSelfLink[. = $id]/ancestor::CMD
+  else
+    collection($id)//IsPartOf[. = "root"]/ancestor::CMD
+};
 
 (:
@@ -253,4 +262,6 @@
   let $names := if (exists($collections[2])) then
     ($cmd-model:commonFreqsPath, cmd-model:make-compound-doc-name($collections, "collection", $max-depth)) 
+  else if (starts-with($collections, "test-")) then 
+    ($cmd-model:commonFreqsPath, cmd-model:make-compound-doc-name($collections, "collection", $max-depth)) 
   else
     ($collections, concat($cmd-model:collectionDocName, xs:string($max-depth))),
@@ -259,8 +270,8 @@
 	()
       else
-	let $children := for $collection-item in $collections
-	  let $collection-item-docs := collection(concat($collection-item, "/", "Corpusstructure"))
+	let $children := 
+	for $collection-item in $collections
         return
-	  for $collection-doc in $collection-item-docs//CMD return
+	for $collection-doc in cmd-model:get-resource-by-handle-or-collection-path($collection-item) return
 	  cmd-model:recurse-collections($collection-doc, ($collection-doc//Corpus/Name, $collection-doc//Session/Name, "UNKNOWN")[1], $collection-doc//MdSelfLink, "", $max-depth)
 	  return
Index: MDRepository/trunk/xquery/cmd-stats.xql
===================================================================
--- MDRepository/trunk/xquery/cmd-stats.xql	(revision 641)
+++ MDRepository/trunk/xquery/cmd-stats.xql	(revision 654)
@@ -6,5 +6,5 @@
 <item label="ResourceProxy - Resource" >count(//ResourceProxy[ResourceType='Resource'])</item>,
 <item label="ResourceProxy - Metadata" >count(//ResourceProxy[ResourceType='Metadata'])</item>,
-<item label="CMD with MD, Res " >count((//CMD[.//ResourceType='Resource'], //CMD[.//ResourceType='Metadata']))</item>,
+<item label="CMD with MD and Res (fixme!)" >count((//CMD[.//ResourceType='Resource'], //CMD[.//ResourceType='Metadata']))</item>,
 <item label="CMD without " >count(//CMD[not(.//ResourceType='Resource')][not(.//ResourceType='Metadata')])</item>,
 <item label="CMD with relative Resource (starts-with('.'))" >count(//CMD[.//ResourceType='Resource'][starts-with(.//ResourceRef,'.')])</item>,
