here is a sample of my xml.
let $test :=
<root>
<a z="">stuff</a>
<b z="12" y="">more stuff</b>
<c>stuff</c>
<d z = " " y="0" x ="lkj">stuff goes wild</d>
</root>
i would like to remove empty attributes using query to get this :
<root>
<a>stuff</a>
<b z="12">more stuff</b>
<c>stuff</c>
<d y="0" x ="lkj">stuff goes wild</d>
</root>
I've gotten this far with my query, but i cannot get it to only remove the empty attribute, instead of removing all attributes if there is any empty one inside the element.
declare function local:sanitize ($nodes as node()*) {
for $n in $nodes
return typeswitch($n)
case element() return
if ($n/@*[normalize-space()='']) then (element{node-name($n)} {($n/@*[.!=''], local:sanitize($n/node()))})
else (element {node-name($n)} {($n/@*, local:sanitize($n/node()))})
default return ($n)
};
The function needs to be performant hence my desire to use typeswitch. I feel i m close but the last step seems to elude me. ie. z = " " doesn't get caught. Thanks for the help.