[xml] Applying XSLT to HTML


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)
   mf_extract.applyStylesheet(doc, None)

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
be processed.

Happy Hacking.

Dmitry "Sphinx" Dzhus

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]