Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 18, 2015 23:19
Show Gist options
  • Save caschwartz/5860818 to your computer and use it in GitHub Desktop.
Save caschwartz/5860818 to your computer and use it in GitHub Desktop.
XQuery - Query that adds the @integer attribute to the <number> element
xquery version "1.0-ml";
(: 7/11/12 This query adds the @integer attribute to the <number> element :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/d/", "infinity")
for $doc in $docs
let $number := $doc/ia:doc/ia:metadata/ia:volumeInfo/ia:number
let $numValue := fn:replace($number, "^(\d+)(\-|\s*).*$", "$1")
where $number
and $numValue castable as xs:integer
and fn:not($number/@integer)
return (xdmp:set-request-time-limit(3600), xdmp:node-insert-child($number, attribute integer { $numValue }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment