Andreas Maier, 07.06.2012 12:08:
I am using lxml's XSLT support to transform XML to HTML. The XSLT specifies the following xsl:output directive:
<xsl:output method="html" version="4.0" encoding="UTF-8" media-type="text/html" doctype-public="-//W3C//DTD HTML 4.01//EN" standalone="yes" omit-xml-declaration="yes" indent="no"/>
I serialize the output element tree to a string using the etree.tostring() function:
xslt_tree = etree.parse(xslt_url) xslt_transform = etree.XSLT(xslt_tree.getroot()) out_tree = xslt_transform(in_root_elem) fp.write(etree.tostring(out_tree))
This creates self-closing HTML tags, for example:
<script type="text/javascript" src="tocgen.js"/>
This hurts, because some browsers (including IE8 and FF10) do not support self-closing tags for some tags when the doctype is HTML. The script tag is a particularly nasty one because not recognizing that it is actually closed causes the whole rest of the document to be interpreted as (invalid) Javascript. But doing that with other tags may create problems as well.
What works on all browsers I tested, is the explicitly closed form:
<script type="text/javascript" src="tocgen.js"></script>
You can put a space character into the script tag. Browsers will happily ignore it. Stefan