Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Created March 10, 2015 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caschwartz/042ed9a13079e0d8f1a2 to your computer and use it in GitHub Desktop.
Save caschwartz/042ed9a13079e0d8f1a2 to your computer and use it in GitHub Desktop.
Query to create a CSV file to import into Excel
xquery version "1.0-ml";
(:
: This main module queries basic Tanis postcards metadata for IA to create a
: CSV file to import into Excel. For Excel import, quotation marks are needed
: if value could contain a comma. Needed quotes for Title, Location, and Postcard-type.
:)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/mods/v3";
declare namespace ptsl = "http://digital.library.ptsem.edu/";
let $headers := "Identifier,Title,Location,Format-type,Postcard-type,Denomination"
let $metadata:= for $meta in fn:collection()/ia:doc/ia:metadata
let $id := $meta/ia:id
let $title := $meta/ia:title
let $city := $meta/ia:city
let $state := $meta/ia:state
let $format := $meta/ia:format
let $type := $meta/m:mods/m:extension/ptsl:type
let $denom := $meta/m:mods/m:extension/ptsl:denomination[@type="main"]
where $state = "OH" and $title != "" (: Limits by state and checks for metadata based on title :)
order by $id
return concat($id, ',', '"', $title, '"', ',', '"', $city, ', ', $state, '"', ',', $format, ',', '"', $type, '"', ',', $denom)
return ($headers, $metadata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment