I am trying to remove nodes from an XML file. Using just one XSLT for each of my XML I need to make decisions in the XSLT based upon the number of children of the document element.
<root>
<branch>
<foo>bar</foo>
</branch>
<root>
should transform into
<branch>
</branch>
but
<root>
<branch>
<foo>bar</foo>
</branch>
<branch>
<foo>baz</foo>
<root>
into
<root>
<branch>
</branch>
<branch>
</branch>
<root>
That is, the root element should be removed if its (only) child can act as the new document root of the result XML after applying XSLT. The <foo> nodes have to be removed in every occurence.
Is there a way to perform this operation with a single XSL?
Try