home contribute faq download

FunctX XQuery Functions

functx:change-element-ns

Changes the namespace of XML elements

Google
Webdatypic.com

Description

The functx:change-element-ns function changes the namespace of one or more elements in $elements to $newns. It does not change the namespace of their descendant elements; see the functx:change-element-ns-deep function for that purpose.

Note: this function is intended to change the way elements appear in the results of a query, not to update them in an XML database. To update your XML database, you should use the implementation-specific update functions of your processor.

Arguments and Return Type

NameTypeDescription
$elements element()* the elements to change
$newns xs:string the new namespace
$prefix xs:string the prefix to use for the new namespace
return value element()*

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:change-element-ns
  ( $elements as element()* ,
    $newns as xs:string ,
    $prefix as xs:string )  as element()? {

   for $element in $elements
   return
   element {QName ($newns,
                      concat($prefix,
                                if ($prefix = '')
                                then ''
                                else ':',
                                local-name($element)))}
           {$element/@*, $element/node()}
 } ;

Examples

let $in-xml :=
<bar:a xmlns:bar="http://bar">
   <bar:b>557</bar:b>
   <bar:c>xyz</bar:c>
</bar:a>
return
XQuery ExampleResults
functx:change-element-ns(
     $in-xml, 'http://foo','')
<a xmlns="http://foo">
  <bar:b xmlns:bar="http://bar">557</bar:b>
  <bar:c xmlns:bar="http://bar">xyz</bar:c>
</a>
functx:change-element-ns(
     $in-xml, 'http://foo','foo')
<foo:a xmlns:foo="http://foo">
  <bar:b xmlns:bar="http://bar">557</bar:b>
  <bar:c xmlns:bar="http://bar">xyz</bar:c>
</foo:a>

See Also

functx:change-element-ns-deepChanges the namespace of XML elements and its descendants
functx:change-element-names-deepChanges the names of elements in an XML fragment

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery