Thursday, May 28, 2020

Xquery to change namespace of xml

Change namespace of XML - 


xquery version "1.0" encoding "utf-8";

 

(:: OracleAnnotationVersion "1.0" ::)

 

declare variable $src as element() external;

declare variable $ns as xs:string external;

 

declare function local: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/@*,

                local:change-element-ns-deep($node/node(),

                                           $newns, $prefix)})

         else if ($node instance of document-node())

         then local:change-element-ns-deep($node/node(),

                                           $newns, $prefix)

         else $node

} ;

local:change-element-ns-deep($src, $ns, 'ns')

No comments:

Post a Comment