|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] XQuery count()Wolfgang Meier wolfgang at exist-db.orgMon Nov 9 20:09:39 PST 2009
Hi,
> I need to count the total number of distinct collections in my db (eXist XML
> Database).
> How can i do this in a compact way using XQuery?
This won't be possible without using extension functions. Different
systems will have different ideas of what constitutes a "collection"
(which can be queried with fn:collection). In eXist, you could use a
recursive approach:
import module namespace xdb="http://exist-db.org/xquery/xmldb";
declare function local:scan-collection($collection) {
$collection,
for $child in xdb:get-child-collections($collection) return
local:scan-collection(concat($collection, "/", $child))
};
local:scan-collection("/db")
The following solution is much shorter, but it might be slower:
distinct-values(
for $doc in collection("/db")
return util:collection-name($doc)
)
Wolfgang
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






