(: A few utilitaries functions :) module namespace jj = "http://kumquat.emse.fr/utilitaires" ; (: Extends a (1 or 2 chars) string to 2 chars if necessary :) declare function jj:sl2($s as xs:string) as xs:string { if (fn:string-length($s) = 1) then fn:concat("0",$s) else $s }; (: Edit a dateTime value in a human readable form :) declare function jj:editDate($da as xs:dateTime) as xs:string { fn:concat(jj:sl2(xs:string(fn:day-from-dateTime($da))), "/", jj:sl2(xs:string(fn:month-from-dateTime($da))), "/", fn:year-from-dateTime($da), " ", jj:sl2(xs:string(fn:hours-from-dateTime($da))), "h", jj:sl2(xs:string(fn:minutes-from-dateTime($da))), ":", jj:sl2(xs:string(fn:seconds-from-dateTime($da)))) }; (: Format milliseconds to value in minutes and seconds :) declare function jj:formatMMMSS($millis as xs:integer) as xs:string { let $secs := ($millis idiv 1000) mod 60 let $mins := ($millis idiv 1000) idiv 60 let $minval := if ($mins gt 0) then fn:concat(xs:string($mins),"mn") else "" let $secval := fn:concat(jj:sl2(xs:string($secs)),"s") return fn:concat($minval,$secval) }; (: Convert an integer representing a Unix date (expressed in ms since 1/1/1970) to a a human readable form :) declare function jj:dateFromDREW($da as node()*) as xs:string { if (fn:empty($da)) then "" else let $s := string($da[1]) return if (string-length($s) = 0) then "" else concat(jj:editDate(xs:dateTime("1970-01-01T00:00:00")+xs:integer($s) idiv 1000), ".",jj:sl2(string((xs:integer($s)+50) idiv 10 mod 100))) }; (: Generate a "path" expression for an element :) declare function jj:build-Path($elt as element()) as xs:string { if (fn:empty($elt/..)) then "" else let $n := fn:local-name($elt) for $i at $j in $elt/../*[fn:local-name(.)=$n] where $i is $elt return fn:concat(jj:build-Path($elt/..), "/", $n, "[", $j, "]") }; (: Get an info from an item :) declare function jj:get-item-info($elt as element(), $id as xs:string) as node()* { $elt/info[@name=$id]/node() } (: Get the first value or the second if the first is empty :) declare function jj:get-one($elt1 as node()*, $elt2 as node()*) as node()* { if (fn:empty($elt1)) then $elt2 else $elt1 }