[xml] Applying XSLT to HTML
- From: Dmitry Dzhus <mail sphinx net ru>
- To: xml gnome org
- Subject: [xml] Applying XSLT to HTML
- Date: Tue, 19 Jun 2007 19:45:41 +0400
My aim is to apply XSLT to some HTML document (which may be broken
just a little).
I'm using standard Python libxml2/libxslt bindings.
My code is:
mf_extract = libxslt.parseStylesheetFile("mf-extract.xsl")
doc = libxml2.readHtmlFile(url, None, libxml2.HTML_PARSE_RECOVER)
Applying XSLT results as if there were no content in `doc` tree at
all. Using `readFile` instead of `readHtmlFile` works fine as
I tried to `print doc` after using both `readHtmlFile` and `readFile`
and noticed that, given the input document is well-formed, the output
differs only in XML declaration at the very beginning.
As I understand (and `document.type` indicates), using `readFile` and
`readHtmlFile` results in different kinds of documents --
`document_xml` and `document_html` -- while applying XSLT is only
possible with `document_xml` one. Is there any way to convert
`document_html` to `document_xml`?
I know that applying XSLT to real-world HTML is "undefined behaviour"
at all, but I just want to give those HTML pages a few more chances to
Dmitry "Sphinx" Dzhus
] [Thread Prev