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 TypeName | 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 DeclarationSee 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()}
} ; |
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 |
Recommended Reading:
|