Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active October 13, 2015 00:57
Show Gist options
  • Select an option

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

Select an option

Save caschwartz/4113606 to your computer and use it in GitHub Desktop.
XQuery - Query removes final period from names unless part of name
xquery version "1.0-ml";
(: 11/16/12 This query removes the final period from names :)
declare namespace ia = "http://my.local.namespace.name";
let $docs := xdmp:directory("/ia-xml/i/", "infinity")
let $meta := $docs/ia:doc/ia:metadata
for $name in $meta/ia:name
let $newNameNode := if (fn:matches($name, "[a-zA-Z]\.\s*$")) then (: keeps final period for names with initials, titles, etc. :)
()
else if (fn:matches($name, "\.\s*$")) then
<name xmlns="http://my.local.namespace.name">{ fn:normalize-space(fn:replace($name, "\.\s*$", "")) }</name>
else ()
where fn:not($name = "")
order by $newNameNode
return (xdmp:set-request-time-limit(3600), xdmp:node-replace($name, $newNameNode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment