Matthew Kirkley
Matthew Kirkley

Reputation: 4208

xsltproc transform to html removes close tags of empty elements

I am trying to transform a very simple xml to html. In fact the xml file is blank.

 <?xml-stylesheet type="text/xsl" href="test.xsl" ?>
 <myElement>
 </myElement>

And here is my XSL

 <xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" version="4.0" />

 <xsl:template match="/">
    <html>
    <head>
       <title>How you doing?</title>
    </head>
    <body>
     <br />
     <br />

    </body>
    </html>
 </xsl:template>
 </xsl:stylesheet>

Here is the output of xsltproc. Notice that the br tags are no longer closed. Anyone have any ideas as to why this is happening?

 matt@ubuntu:~/src/tmp$ xsltproc test.xsl test.xml 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>How you doing?</title>
 </head>
 <body>
 <br><br>
 </body>
 </html>

Upvotes: 2

Views: 567

Answers (1)

Matthew Kirkley
Matthew Kirkley

Reputation: 4208

I figured it out.

 <xsl:output method="html" version="4.0" />

The non closed tags are actually valid html, but not xhtml. So this is working as expected.

Upvotes: 3

Related Questions