Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-terminations-since-date.xq
Created May 22, 2014
Principals & Chiefs whose positions ended after a certain date; using XQuery
View principal-officers-and-chiefs-of-mission-terminations-since-date.xq
xquery version "3.0";
(: Displays a list of Principals & Chiefs whose positions ended after a certain date. :)
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 $cut-off := '2008-06-01'
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-from-massachusetts.xq
Created Apr 21, 2014
Principal Officers and Chiefs of Mission from Massachusetts; using XQuery
View principal-officers-and-chiefs-of-mission-from-massachusetts.xq
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'
@joewiz
joewiz / store-files.xq
Created Apr 21, 2014
Upload a directory of XML files into eXist-db, with XQuery
View store-files.xq
xquery version "3.0";
(: Set the absolute file path appropriate for your OS :)
let $source-directory :=
(: Mac :)
(: '/Users/Joe/workspace/myapp/data' :)
(: Windows :)
'C:\Users\wicentowskijc\workspace\myapp\data'
let $target-collection :=
@joewiz
joewiz / days-since-date.xq
Created Apr 21, 2014
How many days have you been alive, with XQuery
View days-since-date.xq
xquery version "3.0";
declare function local:days-since-date($date as xs:date) {
let $duration := current-date() - $date
let $days := days-from-duration($duration)
return
$days
};
local:days-since-date(xs:date('2012-10-12'))
@joewiz
joewiz / check-links.xq
Created Apr 21, 2014
Check a remote webpage for broken links, with XQuery and EXPath HTTP Client
View check-links.xq
View FRUS RelaxNG Import.xml
<?xml-model href="../../schemas/frus.rnc" type="application/relax-ng-compact-syntax"?>
@joewiz
joewiz / generate-xfdf.xq
Created Feb 13, 2014
Generate XFDF data for use in filling a PDF form, with XQuery; see http://joewiz.org/2014/02/13/filling-pdf-forms-with-pdftk-xfdf-and-xquery/
View generate-xfdf.xq
xquery version "3.0";
import module namespace functx="http://www.functx.com";
(: Prepare XFDF data to use with PDFtk to populate a blank form SF702,
e.g., http://www.archives.gov/isoo/security-forms/sf702.pdf,
with data for each month of the year :)
let $data-collection := xmldb:create-collection('/db', 'sf702')
let $year := 2014
@joewiz
joewiz / save-collection-to-disk.xq
Created Oct 30, 2013
Save a collection of XML documents from eXist-db onto the file system, with XQuery
View save-collection-to-disk.xq
xquery version "3.0";
let $file-system-target-base-directory :=
(: Mac :)
(: '/Users/Joe/workspace/paho-trunk' :)
(: Windows :)
'C:\Users\wicentowskijc\oxygensvn\paho-trunk'
let $source-collection := '/db/cms/apps/tei-content/data/short-history'
for $doc in collection($source-collection)
let $target :=
@joewiz
joewiz / milestones-to-tsv.xq
Created Oct 28, 2013
Create a tab-separated TSV file - like a comma-separated CSV file - out of a collection of TEI documents, with XQuery
View milestones-to-tsv.xq
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $site-base-url := 'http://history.state.gov/milestones'
let $milestones-files := collection('/db/cms/apps/tei-content/data/milestones')/tei:TEI
let $tab-delimited-cells :=
for $file in $milestones-files
let $filename := substring-before(util:document-name($file), '.xml')
return
@joewiz
joewiz / nixon-chiefs-of-mission.xq
Last active Dec 22, 2015
Chiefs of Mission appointed during the presidency of Richard Nixon, using XQuery
View nixon-chiefs-of-mission.xq
xquery version "3.0";
let $roles := collection('/db/cms/apps/principals-chiefs/code-tables/roles/data')/role
let $countries := collection('/db/cms/apps/countries/data')/country
let $start-date := '1969-01-20'
let $end-date := '1974-08-09'
let $appointments := collection('/db/cms/apps/principals-chiefs/data')//event[@type='appointed' and @when gt $start-date and @when lt $end-date]/parent::role[@class='chief' and @type ne 'charge-daffaires-ad-interim']
return
<div>
<p>{count($appointments)} Chiefs of Mission who were appointed between {format-date(xs:date($start-date), "[MNn] [D], [Y]")} and {format-date(xs:date($end-date), "[MNn] [D], [Y]")}.</p>