Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Created January 6, 2014 16:16
Show Gist options
  • Select an option

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

Select an option

Save caschwartz/8285160 to your computer and use it in GitHub Desktop.
XQuery - Using Priscilla Walmsley's function, this query puts the root node and all descendant elements in the MARCXML namespace
xquery version "1.0-ml";
(: 1/6/14 Using Priscilla Walmsley's function, this query puts the root node and all descendant elements in the MARCXML namespace :)
declare namespace m = "http://www.loc.gov/MARC21/slim";
declare namespace functx = "http://www.functx.com";
declare function functx:change-element-ns-deep
( $nodes as node()* ,
$newns as xs:string ,
$prefix as xs:string ) as node()* {
for $node in $nodes
return if ($node instance of element())
then (element
{QName ($newns,
concat($prefix,
if ($prefix = '')
then ''
else ':',
local-name($node)))}
{$node/@*,
functx:change-element-ns-deep($node/node(),
$newns, $prefix)})
else if ($node instance of document-node())
then functx:change-element-ns-deep($node/node(),
$newns, $prefix)
else $node
} ;
for $doc in fn:collection()[1 to fn:last()]
let $rootNode := $doc/record
return xdmp:node-replace($rootNode, functx:change-element-ns-deep($rootNode, "http://www.loc.gov/MARC21/slim", ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment