Description
The functx:remove-attributes-deep function removes attributes from a sequence of elements and all of their descendants. 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. You can also specify wildcard values "*", "*:" and ":*" in the second argument. See the description for functx:name-test for details.
Note: this function is intended to change the way elements and attributes 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 |
$nodes |
node()* |
the root(s) to start from |
$names |
xs:string* |
the names of the attributes to remove, or * for all attributes |
return value |
node()* |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:remove-attributes-deep
( $nodes as node()* ,
$names as xs:string* ) as node()* {
for $node in $nodes
return if ($node instance of element())
then element { node-name($node)}
{ $node/@*[not(functx:name-test(name(),$names))],
functx:remove-attributes-deep($node/node(), $names)}
else if ($node instance of document-node())
then functx:remove-attributes-deep($node/node(), $names)
else $node
} ; |
Exampleslet $in-xml-1 := | <a attr1="123" attr2="456">
<b attr1="xzy">abc</b>
</a> | let $in-xml-2 := | <a xmlns:a="http://a" a:attr1="123" attr1="456">
<b a:attr1="ghi" attr1="xzy">abc</b>
</a> | return |
XQuery Example | Results |
---|
functx:remove-attributes-deep(
$in-xml-1,
('attr1','attr2')) |
<a>
<b>abc</b>
</a> |
functx:remove-attributes-deep(
$in-xml-1,
('attr1','attr3')) |
<a attr2="456">
<b>abc</b>
</a> |
functx:remove-attributes-deep(
$in-xml-2,
'a:attr1') |
<a attr1="456">
<b attr1="xzy">abc</b>
</a> |
Depends OnSee AlsoHistory |
Recommended Reading:
|