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.
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()* |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:change-element-ns-deep" as="node()*"
xmlns:functx="http://www.functx.com">
<xsl:param name="nodes" as="node()*"/>
<xsl:param name="newns" as="xs:string"/>
<xsl:param name="prefix" as="xs:string"/>
<xsl:for-each select="$nodes">
<xsl:variable name="node" select="."/>
<xsl:choose>
<xsl:when test="$node instance of element()">
<xsl:element name="{concat($prefix,
if ($prefix = '')
then ''
else ':',
local-name($node))}"
namespace="{$newns}">
<xsl:sequence select="($node/@*,
functx:change-element-ns-deep($node/node(),
$newns, $prefix))"/>
</xsl:element>
</xsl:when>
<xsl:when test="$node instance of document-node()">
<xsl:document>
<xsl:sequence select="functx:change-element-ns-deep(
$node/node(), $newns, $prefix)"/>
</xsl:document>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$node"/>
</xsl:otherwise>
</xsl:choose>
</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-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:
|