Hi,
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>
See this thread for discussion:
http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work
BTW, Xalan produces the explicitly closed form for the same
scenario. (Just to mention it as one other data point, not that I
would consider going back to Xalan - lxml is much much faster and by
comparing lxml and Xalan output beyond differences such as
self-closing tags I found already one difference that seems to be a
Xalan bug).
-> Is there a way to get lxml's HTML serialization support to
produce the explicitly closed form ?
The lxml version I am using is lxml 2.3 with libxml2 statically
linked, for Python 2.6, on Windows (lxml-2.3.win32-py2.6.exe).
-> Is there a later version that has a Windows installer and
libxml2 statically linked ? (Other people need to be able to set
that up for my stuff to work, and this way it is real simple).
Andy