Is there a better way? Getting earliest date
I was able to get this to work with the code below -
Basically, I'm given a date that looks like this:
<ms:Dates>
<ms:Date ms:type="posted" ms:value="2008-07-23"/>
</ms:Dates>
I've a bunch in my collection, but need to get the year (for starters) of the earliest one... so, while I'm almost certain there's a better way (and hoping someone can teach me), I'm doing this:
---Code---
declare function analysis:earliest() as xs:integer {
let $ordered_dates := for $the_dates in collection($collection_all )/ms:Resource/ms:Dates/ms:Date
order by $the_dates/@ms:value
return $the_dates
let $min_date := $ordered_dates[1]
let $year_string := substring($min_date/@ms:value, 1, 4)
return xs:integer($year_string)
};
---End Code---