declare function local:replace($tree as node(), $orig as xs:string, $new as xs:string) as node()
{
if($tree instance of element()) then
let $nodename := xs:string(node-name($tree)),
$name := if($nodename = $orig) then $new else $nodename
return
element {$name} {
$tree/@*,
for $child in $tree/node()
return local:replace($child, $orig, $new)
}
else $tree
};
(:you can test the function by invoking it like this:
let $src :=
return local:replace($src, "c", "newnode"):)(: Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
:)