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. (There is no standard XQuery update syntax yet.)
Arguments and Return Type| Name | Type | Description |
$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. | | XQuery Syntax for April 2005 - January 2007 (1.0): |
|---|
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()}
} ; | | XQuery Syntax for July 2004: |
|---|
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 {expanded-QName ($newns,
concat($prefix,
if ($prefix = '')
then ''
else ':',
local-name($element)))}
{$element/@*, $element/node()}
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function change-element-ns
( $elements as element()* ,
$newns as xs:string ,
$prefix as xs:string ) as element()? {
for $element in $elements
return
element {fn:expanded-QName ($newns,
fn:concat($prefix,
if ($prefix = '')
then ''
else ':',
fn:local-name($element)))}
{$element/@*, $element/node()}
} |
Exampleslet $in-xml := | <bar:a xmlns:bar="http://bar">
<bar:b>557</bar:b>
<bar:c>xyz</bar:c>
</bar:a> | return |
| XQuery Example | Results |
|---|
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 AlsoHistory |
|