joewiz
4/2/2015 - 4:08 PM

Travels of the Secretary of State, sorted by trip duration (longest to shortest), using XQuery

Travels of the Secretary of State, sorted by trip duration (longest to shortest), using XQuery

xquery version "3.0";

for $trip in collection('/db/cms/apps/travels/data/secretaries')/trips/trip
let $duration := xs:date($trip/end-date) - xs:date($trip/start-date)
order by $duration descending
return <trip duration="{$duration}">{ $trip }</trip>