Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 18, 2015 23:19
Show Gist options
  • Save caschwartz/5860967 to your computer and use it in GitHub Desktop.
Save caschwartz/5860967 to your computer and use it in GitHub Desktop.
XQuery - Query embedded MARC records for edition statements and create <edition> element for local metadata schema
xquery version "1.0-ml";
(: 6/19/12 Query theocom documents for edition statements and create <edition> elements :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
for $doc in xdmp:directory("/ia-xml/l/ly/", "infinity")
let $marc := $doc/ia:doc/ia:metadata/ia:marc/m:record
let $id := $doc/ia:doc/ia:metadata/ia:id
let $sortTitle := $doc/ia:doc/ia:metadata/ia:sortTitle
let $edition := $marc/m:datafield[@tag = "250"]
let $newNodeEdition := <edition xmlns="http://digital.library.ptsem.edu/ia">{ fn:normalize-space($edition) }</edition>
let $newLine := text {"&#10;"}
let $indent := text {" "}
where $edition
return let $empty := xdmp:node-insert-after($sortTitle, $newLine)
let $empty := xdmp:node-insert-after($sortTitle, $indent)
let $empty := xdmp:node-insert-after($sortTitle, $newNodeEdition)
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment