XQuery for retrieving the latest modified date of any resource in a collection


Permalink 11:22:18 am, by mholmes, 173 words, 344 views   English (CA)
Categories: R & D, Activity log, Documentation, Documentation; Mins. worked: 30

XQuery for retrieving the latest modified date of any resource in a collection

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

UPDATE: the next step is ready. See this post: http://hcmc.uvic.ca/blogs/index.php?blog=11&p=8962


No Pingbacks for this post yet...


This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent, in the server room, the labs and the R&D rooms.



September 2014
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

XML Feeds