Last active
October 25, 2016 18:42
-
-
Save caschwartz/2845340 to your computer and use it in GitHub Desktop.
XQuery - Adds "sort" namespace to dmdSec of METS documents for volume and issue numbers
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 "1.0-ml"; | |
(: 12/1/11 Adds "sort" elements to dmdSec of METS documents for volume and issue numbers :) | |
declare namespace sort = "http://my.local.namespace/sort"; | |
declare namespace mets = "http://www.loc.gov/METS/"; | |
declare namespace dc = "http://purl.org/dc/elements/1.1/"; | |
for $journal in xdmp:directory("/METS/")/mets:mets/mets:dmdSec[2]/mets:mdWrap/mets:xmlData | |
let $title := $journal/dc:format | |
let $volumeIssue := fn:replace(fn:normalize-space($title), "^.*?(\d*:\d*).*$", "$1") | |
let $volume := fn:replace($volumeIssue, "(^\d*):(\d*$)", "$1") | |
let $issue := fn:replace($volumeIssue, "(\d*):(\d*$)", "$2") | |
let $sortVolume := element sort:volume {$volume} | |
let $sortIssue := element sort:issue {$issue} | |
let $node := $journal/preceding::mets:dmdSec/mets:mdWrap/mets:xmlData | |
where fn:not(fn:contains(fn:base-uri($journal), "PSB"))and fn:matches(fn:string($title), "^.*?(\d*:\d*).*$") | |
return xdmp:node-insert-child($node, for $item in ($sortVolume, $sortIssue) | |
where $item != "" | |
return $item) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment