Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 28, 2015 08:19
Show Gist options
  • Select an option

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

Select an option

Save caschwartz/7470708 to your computer and use it in GitHub Desktop.
XQuery - Query to isolate superscript numbers and change to ASCII in the <tei:hi> element for TEI metadata
xquery version "1.0-ml";
(: 11/4/13 Query to isolate the superscript numbers and change to ASCII numbers in the <tei:hi> element :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $doc in fn:collection()
let $superNums := $doc//tei:hi[@rend = "super"]
for $superNum in $superNums
(: Where clause isolates the superscript numbers (since some are already ASCII numbers) :)
where fn:not($superNum castable as xs:integer)
return let $normNum := fn:normalize-unicode($superNum, "NFKC") (: Change superscript numbers to ASCII numbers :)
(: The imperative function to replace the text node for the <tei:hi> element :)
return xdmp:node-replace($superNum/text(), text{ $normNum })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment