Created
April 21, 2014 20:12
-
-
Save joewiz/11154995 to your computer and use it in GitHub Desktop.
Principal Officers and Chiefs of Mission from Massachusetts; using XQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(: Displays a list of Principals & Chiefs hailing from Massachusetts. :) | |
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; | |
declare option output:method "html5"; | |
declare option output:media-type "text/html"; | |
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person | |
let $state := 'ma' | |
let $from-state := $all-people[contains(residence/@location, $state)] | |
return | |
<div> | |
<h1>Principal Officers and Chiefs of Mission from Massachusetts</h1> | |
<h2>{format-date(current-date(), '[MNn] [D], [Y]')}</h2> | |
<p>Principal Officers and Chiefs of Mission from Massachusetts. There are {count($from-state)} entries. We do our best to monitor obituaries, but some people listed below may in fact have passed away. Please let us know if you discover any information that is out of date.</p> | |
<ol>{ | |
for $person in $from-state | |
let $id := $person/@id | |
let $name := string-join(($person/persName/surname, $person/persName/forename, $person/persName/genName[. ne '']), ', ') | |
let $birth := if ($person/birth ne '') then $person/birth/string() else '?' | |
let $roles := | |
string-join( | |
for $role in $person/role[event and not(@type = 'charge-daffaires-ad-interim')] | |
let $role-label := collection('/db/cms/apps/principals-chiefs/code-tables/roles/data/')/role[id = $role/@type]/names/singular | |
let $start := $role/event[@type = 'appointed']/@when | |
let $end := $role/event[@type = ('appointmentterminated', 'missionterminated')][1]/@when | |
order by $start | |
return | |
concat( | |
$role-label, | |
', ', | |
(: handle dates like yyyy-mm-dd :) | |
if (matches($start, '\d{4}-\d{2}-\d{2}')) then | |
format-date(xs:date($start), '[MNn] [D], [Y]') | |
(: handle dates like yyyy-mm :) | |
else if (matches($start, '\d{4}-\d{2}')) then | |
format-date(xs:date(concat($start, '-01')), '[MNn], [Y]') | |
(: show asterisks for all other dates - unexpected input :) | |
else | |
concat('***', $start, '***'), | |
(: sometimes empty date entries are intentional :) | |
if ($start = '' or empty($start)) then | |
if ($role/note or $end/parent::event/text() ne '') then | |
' (see note)' | |
else | |
() | |
else | |
(), | |
'–', | |
(: handle end dates as above :) | |
if ($end = '' or empty($end)) then | |
'' | |
else if (matches($end, '\d{4}-\d{2}-\d{2}')) then | |
format-date(xs:date($end), '[MNn] [D], [Y]') | |
else if (matches($end, '\d{4}-\d{2}')) then | |
format-date(xs:date(concat($end, '-01')), '[MNn], [Y]') | |
else | |
concat('***', $end, '***'), | |
if ($end = '' or empty($end)) then | |
if ($role/note or $end/parent::event/text() ne '') then | |
' (see note)' | |
else | |
() | |
else | |
() | |
) | |
, | |
'; ') | |
let $career-type := $person/career/string() | |
order by $id | |
return | |
<li><a href="http://history.state.gov/departmenthistory/people/{$id}">{$name}</a> ({$career-type}, b. {$birth}): {$roles}.</li> | |
}</ol> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment