Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active October 6, 2015 06:18
Show Gist options
  • Select an option

  • Save caschwartz/2950145 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/2950145 to your computer and use it in GitHub Desktop.
Query constructs a <volumeInfo> element using part of the Internet Archive ID for the <volume> value
xquery version "1.0-ml";
(: 6/4/12 This query constructs a <volumeInfo> element using part of the IA ID for the <volume> value. :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/l/lv/", "infinity")
for $doc in $docs
let $id := $doc/ia:doc/ia:metadata/ia:id
let $date := $doc/ia:doc/ia:metadata/ia:date
let $volume := $doc/ia:doc/ia:metadata/ia:volumeInfo
let $volumeInfo := $doc/ia:doc/ia:metadata/ia:marc/m:record/m:datafield[@tag = "300"]/m:subfield[@code = "a"]
where fn:not(fn:matches($volumeInfo, "^1 v."))
and fn:not(fn:matches($volumeInfo, "^1 vol."))
and fn:not(fn:contains($volumeInfo, "in 1"))
and fn:not(fn:exists($volume))
and fn:contains($volumeInfo, "v.")
or fn:contains($volumeInfo, "vol.")
return let $idNum := fn:replace($id, "(.*)(\d{2})(\w*)$", "$2")
let $volumeValue := if ($idNum = "00") then
"1"
else if (fn:starts-with($idNum, "0")) then
fn:substring($idNum, 2)
else $idNum
let $newLine := text {"&#10;"}
let $indent := text {" "}
let $newNode := <volumeInfo xmlns="http://digital.library.ptsem.edu/ia">
<volume>{ $volumeValue }</volume>
</volumeInfo>
return (xdmp:set-request-time-limit(3600), let $empty := xdmp:node-insert-after($date, $newLine)
let $empty := xdmp:node-insert-after($date, $indent)
let $empty := xdmp:node-insert-after($date, $newNode)
return ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment