Showing posts with label Xquery. Show all posts
Showing posts with label Xquery. Show all posts

Friday, June 26, 2020

Xquery to remove namespace from XML

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

(:: OracleAnnotationVersion "1.0" ::)

declare variable $input as element() external;

declare function local:change-ns($input as element()) as element() {
    
    element {fn:local-name($input) }
    {
    for $child in $input/(@*,node())
      return
      if ($child instance of element())
        then local:change-ns($child)
      else $child
    }
};
local:change-ns($input)

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')