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.
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()* |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:change-element-ns" as="element()?"
xmlns:functx="http://www.functx.com">
<xsl:param name="elements" as="element()*"/>
<xsl:param name="newns" as="xs:string"/>
<xsl:param name="prefix" as="xs:string"/>
<xsl:for-each select="$elements">
<xsl:variable name="element" select="."/>
<xsl:element name="{concat($prefix,
if ($prefix = '')
then ''
else ':',
local-name($element))}"
namespace="{$newns}">
<xsl:sequence select="$element/@*, $element/node()"/>
</xsl:element>
</xsl:for-each>
</xsl:function>
|
Examples<xsl:variable name="in-xml" as="item()*"> | | <bar:a xmlns:bar="http://bar">
<bar:b>557</bar:b>
<bar:c>xyz</bar:c>
</bar:a> |
| </xsl:variable> |
XPath 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:
|