Description
The functx:change-element-ns-deep function changes the namespace of the XML elements in $nodes to $newns. Unlike the functx:change-element-ns function, it also changes the namespace of all their descendant elements.
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 |
$nodes |
node()* |
the nodes to change |
$newns |
xs:string |
the new namespace |
$prefix |
xs:string |
the prefix to use for the new namespace |
| return value |
node()* |
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-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
} ; | | XQuery Syntax for July 2004: |
|---|
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
{expanded-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
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function 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
{fn:expanded-QName ($newns,
fn:concat($prefix,
if ($prefix = '')
then ''
else ':',
fn: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
} |
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-deep(
$in-xml, 'http://foo','')
|
<a xmlns="http://foo">
<b>557</b>
<c>xyz</c>
</a>
|
functx:change-element-ns-deep(
$in-xml, 'http://foo','foo')
|
<foo:a xmlns:foo="http://foo">
<foo:b>557</foo:b>
<foo:c>xyz</foo:c>
</foo:a>
|
See AlsoHistory |
|