The two attached files allow to reproduce the bug easily. The XSLT stylesheet no-decl.xsl works fine with xsltproc and Sablotron (no XML declaration is produced), while it fails with test-nodecl.py.
A workaround I use is to use the "children" attribute: html_results = html_style.applyStylesheet(xml_document, None) # html_results contain the erroneous XML declaration html_results_ok = html_results.children # html_results_ok does NOT contain the erroneous XML declaration
no-decl.xsl
Description: XML document
import libxml2 import libxslt xml = "<a><c>33</c>Text</a>" styledoc = libxml2.parseFile("no-decl.xsl") style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseMemory(xml, len(xml)) # Raises libxml2.parserError if not well-formed result = style.applyStylesheet(doc, None) i = 0 for node in result: print "\n%i (%s) >>>> %s\n" % (i, node.name, node) i = i + 1 print result.children