Last active
October 13, 2015 02:47
-
-
Save caschwartz/4126944 to your computer and use it in GitHub Desktop.
XQuery - Query retrieves and replaces sort titles with punctuation at the beginning of the title
This file contains hidden or 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"; | |
| (: 11/7/12 This query retrieves and replaces sort titles with punctuation at the beginning of the title :) | |
| declare namespace ia = "http://my.namespace.uri"; | |
| let $docs := xdmp:directory("/ia-xml/o/", "infinity") | |
| let $sortTitles := $docs/ia:doc/ia:metadata/ia:sortTitle | |
| for $sortTitle in $sortTitles | |
| let $newSortTitle := fn:replace($sortTitle, "^\p{P}+\s*", "") | |
| let $normTitle := fn:normalize-unicode($newSortTitle, "NFKD") | |
| let $letter := fn:upper-case(fn:substring($normTitle, 1, 1)) | |
| return if (fn:matches($sortTitle, "^\p{P}+\s*")) then | |
| xdmp:node-replace($sortTitle, | |
| <sortTitle first-letter="{ $letter }" xmlns="http://digital.library.ptsem.edu/ia">{ $newSortTitle }</sortTitle>) | |
| else () | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment