Description
The functx:remove-attributes function removes attributes from a sequence of one or more elements. The $names argument is a sequence of strings that represent attribute names to remove. Prefixes can (and must) be used in the $names values for attributes that are prefixed in the input documents (using the same prefix). You can also specify wildcard values "*", "*:" and ":*" as the second argument. See the description for functx:name-test for details.
The function does not remove attributes from the descendants of the elements, just the elements themselves; see functx:remove-attributes-deep for this purpose.
Arguments and Return TypeName | Type | Description |
$elements |
element()* |
the element(s) from which to remove the attributes |
$names |
xs:string* |
the names of the attributes to remove, or * for all attributes |
return value |
element()* |
XSLT Function DeclarationSee XQuery definition. | <xsl:function name="functx:remove-attributes" as="element()"
xmlns:functx="http://www.functx.com">
<xsl:param name="elements" as="element()*"/>
<xsl:param name="names" as="xs:string*"/>
<xsl:for-each select="$elements">
<xsl:element name="{node-name(.)}">
<xsl:sequence
select="(@*[not(functx:name-test(name(),$names))],
node())"/>
</xsl:element>
</xsl:for-each>
</xsl:function>
|
Examples<xsl:variable name="in-xml-1" as="item()*"> | | <a attr1="123" attr2="456">abc</a> |
| </xsl:variable> | <xsl:variable name="in-xml-2" as="item()*"> | | <a xmlns:a="http://a"
a:attr1="123" attr1="456">abc</a> |
| </xsl:variable> |
XPath Example | Results |
---|
functx:remove-attributes(
$in-xml-1, ('attr1','attr2')) |
<a>abc</a> |
functx:remove-attributes(
$in-xml-1, ('attr1','attr3')) |
<a attr2="456">abc</a> |
functx:remove-attributes($in-xml-1, '*') |
<a>abc</a> |
functx:remove-attributes(
$in-xml-2, ('a:attr1')) |
<a attr1="456">abc</a> |
Depends OnSee AlsoHistory |
Recommended Reading:
|