XQuery for retrieving the latest modified date of any resource in a collection
Posted by mholmes on 21 Dec 2011 in R & D, Activity log, Documentation, Documentation
We intend this as the first stage in implementing a script which can refresh a large db collection based on document dates, so only documents changed since the last-modified date are uploaded (perhaps after allowing a 24-hour cushion):
xquery version "1.0"; declare namespace local="http://hcmc.uvic.ca/ns"; declare namespace exist="http://exist.sourceforge.net/NS/exist"; declare namespace xmldb="http://exist-db.org/xquery/xmldb"; import module namespace request="http://exist-db.org/xquery/request"; declare variable $inCol := request:get-parameter("col", "/db"); declare variable $startCol := if (starts-with($inCol, "/")) then $inCol else concat("/", $inCol); declare function local:getLatest($col as xs:string) as xs:dateTime* { let $dates :=local:getDocDates($col) return max($dates) }; declare function local:getDocDates($col as xs:string) as xs:dateTime* { let $result := (for $c in xmldb:get-child-collections($col) return local:getDocDates(concat($col, '/', $c)), for $r in xmldb:get-child-resources($col) return xmldb:last-modified($col, $r) ) return $result }; local:getLatest($startCol)UPDATE: the next step is ready. See this post: http://hcmc.uvic.ca/blogs/index.php?blog=11&p=8962