Description
The functx:remove-elements-deep function removes descendant elements from all of the nodes in $nodes based on name. The $names argument is a sequence of strings that represent element names to remove. Prefixes can (and must) be used in the $names values for elements that are prefixed in the input documents. You can also specify wildcard values "*", "*:" and ":*" in the second argument. See the description for functx:name-test for details.
Arguments and Return TypeName | Type | Description |
$nodes |
node()* |
root(s) to start from |
$names |
xs:string* |
the names of the elements to remove |
return value |
node()* |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:remove-elements-deep" as="node()*"
xmlns:functx="http://www.functx.com">
<xsl:param name="nodes" as="node()*"/>
<xsl:param name="names" as="xs:string*"/>
<xsl:for-each select="$nodes">
<xsl:choose>
<xsl:when test=". instance of element()">
<xsl:if test="not(functx:name-test(name(),$names))">
<xsl:element name="{node-name(.)}">
<xsl:sequence select="@*,
functx:remove-elements-deep(node(), $names)"/>
</xsl:element>
</xsl:if>
</xsl:when>
<xsl:when test=". instance of document-node()">
<xsl:document>
<xsl:sequence select="
functx:remove-elements-deep(node(), $names)"/>
</xsl:document>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:function>
|
Examples<xsl:variable name="in-xml-1" as="item()*"> | | <in-xml>
<a>
<b>b1</b>
<c>c1</c>
</a>
<c>Mixed <b>content</b></c>
</in-xml> |
| </xsl:variable> | <xsl:variable name="in-xml-2" as="item()*"> | | <in-xml xmlns:x="http://x">
<a>
<x:b>b1</x:b>
<c>c1</c>
</a>
<c>Mixed <b>content</b></c>
</in-xml> |
| </xsl:variable> |
XPath Example | Results |
---|
functx:remove-elements-deep(
$in-xml-1,
'b') |
<in-xml>
<a>
<c>c1</c>
</a>
<c>Mixed </c>
</in-xml> |
functx:remove-elements-deep(
$in-xml-1,
'a') |
<in-xml>
<c>Mixed <b>content</b>
</c>
</in-xml> |
functx:remove-elements-deep(
$in-xml-1,
('b','c')) |
<in-xml>
<a/>
</in-xml> |
functx:remove-elements-deep(
$in-xml-2,
'x:b') |
<in-xml>
<a>
<c>c1</c>
</a>
<c>Mixed <b>content</b>
</c>
</in-xml> |
Depends OnSee AlsoHistory |
Recommended Reading:
|