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.
Arguments and Return TypeName | 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 DeclarationSee XSLT definition. | 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
} ; |
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 |
Recommended Reading:
|