I have something like this
<a>
<b>
<c>1</c>
<d>2<e>3</e></d>
</b>
</a>
and I want to obtain a sequence like this
<a/>
<b/>
<c>1</c>
<d>2<e>3</e></d>
that is, when recursing, every time an element occurs which does not have a text node, I want to output the element as an empty element, whereas every time an element with a text node occurs, I want to output it as it is. Of course, the text nodes in the above input have to be space-normalized.
If I put it through a standard identity transform,
declare function local:copy($element as element()) as element() {
element {node-name($element)}
{$element/@*,
for $child in $element/*
return
if ($child/text())
then $child
else (element {node-name($child)}{$child/@*}, local:copy($child))
}
};
<b> gets reconstructed as a full element (containing <c> and <d>), but if I remove the element constructor, it does not get output at all.