declare function local:filter($node as element()) as node()?
{
if ( fn:namespace-uri($node) = 'urn:my-nice-namespace'
and fn:local-name($node) = 'car'
and $node/@make = 'Ferrari'
and $node/@model = 'PuroSangue') then
element {name($node)} {
$node/@*, (: Copy all attributes :)
attribute {"revealed"} {"2022-09-13"}, (:add an extra attribute:)
for $child in $node/node()
return local:identity-transform($child) (: Recursive call on child nodes :)
}
else ()
};
declare function local:identity-transform($node as node()) as node()*
{
if ($node instance of element()) then
let $filter := local:filter($node)
return
if (not(fn:empty($filter))) then $filter
else
element {name($node)} {
$node/@*, (: Copy all attributes :)
for $child in $node/node()
return local:identity-transform($child) (: Recursive call on child nodes :)
}
else if ($node instance of attribute()) then
attribute {name($node)} {string($node)}
else $node (: Copy all other nodes unmodified :)
};