How to preserve Empty XML Tags after XSLT - prevent collapsing them from <B></B> to <B/>

Ok, so here what worked for me:

<xsl:output method="html">

Try this:

<script type="..." src="...">&#160;</script>

Your HTML output will be:

<script type="..." src="..."> </script>

The &#160; prevents the collapsing but translates to a blank space. It's worked for me in the past.


There is no standard way, as they are equivalent; You might be able to find an XSLT engine that has an option for this behaviour, but I'm not aware of any.

If you're passing this to a third party that cannot accept empty tags using this syntax, then you may have to post-process the output yourself (or convince the third party to fix their XML parsing)

Tags:

Java

Xml

Xslt