Skip to content

How to make javax Transformer output HTML (no self-closing tags)?

I’m using a javax.xml.transform.Transformer to convert an XML file into an HTML file. It can happen that a div will have no content, which causes the Transformer to output <div/>, which breaks rendering.

I’ve searched and found that “You can change the xslt output to html instead of xml to avoid the problem with self closing tags“, but that was for a different tool and I’m left wondering: how do I do that with a javax Transformer?



This answer in another thread doesn’t seem to work in my case; even if I specify <xsl:output method="html"...> it still produces <div/> instead of <div></div>.

I don’t know if my IDE or compiler is broken (IBM Rational Application Developer), but I’m using a work-around of detecting blank nodes and inserting single spaces in them. Less clean, but effective…