[lxml-dev] XSLT: Issues encountered when transforming docbook
Hi all, Using a python-based build tool, I decided to use lxml directly instead of calling xsltproc in order to transform docbook sources. The docbook sources contain olinks (links between documents). Everything works fine when using xsltproc. I tried the following : def xsltproc(xml_filename, xslt_filename, **kw): parser = etree.XMLParser() xml_doc = etree.parse(xml_filename, parser) print xml_doc.getroot().base xml_doc.xinclude() xslt_doc = etree.parse(xslt_filename) ac = etree.XSLTAccessControl(read_network=True, write_file=True, read_file=True, create_dir=True) transform = etree.XSLT(xslt_doc, access_control=ac) result_tree = transform(xml_doc, **kw) res = etree.tostring(result_tree, pretty_print=True, encoding="utf-8", xml_declaration=True) print "Transform\n", transform.error_log print "Parser\n", parser.error_log if not res: raise Exception("pouet") return res kw = { "olink.base.uri" : "doc.html", "collect.xref.targets" : "yes", "targets.filename" : "doc.html.db", "target.database.document" : "olinkdb-html.xml", } res = xsltproc("doc.xml", ".../xsl/xhtml/docbook.xsl", **kw) with open("pouet", "w") as f: f.write(res) This code fails silently (Exception("pouet") is raised). If I comment the line with remove collect.xref.targets, a document is correctly output. But the olinks are screwed. Somehow the xslt transformer is not able to read the olink information of other documents, by reading the pointers in olinkdb-html.xml. It seems that the silent failure is a bug, and I may be missing some stuff in order to convert the documents properly. More complete test cases available upon request. Thank you all, -- cJ
Jérôme Carretero, 03.09.2010 22:15:
This code fails silently (Exception("pouet") is raised). If I comment the line with remove collect.xref.targets, a document is correctly output. [...] It seems that the silent failure is a bug, and I may be missing some stuff in order to convert the documents properly.
Did you check the error_log of the XSLT object to see if it reports any errors? Stefan
On Fri, 03 Sep 2010 22:21:18 +0200 Stefan Behnel <stefan_ml@behnel.de> wrote:
Jérôme Carretero, 03.09.2010 22:15:
This code fails silently (Exception("pouet") is raised). If I comment the line with remove collect.xref.targets, a document is correctly output. [...] It seems that the silent failure is a bug, and I may be missing some stuff in order to convert the documents properly.
Did you check the error_log of the XSLT object to see if it reports any errors?
Stefan
In my listing I have : print "Transform\n", transform.error_log print "Parser\n", parser.error_log And the printout is empty (except from the strings of course). Regards, -- cJ
Jérôme Carretero, 03.09.2010 22:31:
On Fri, 03 Sep 2010 22:21:18 +0200 Stefan Behnel<stefan_ml@behnel.de> wrote:
Jérôme Carretero, 03.09.2010 22:15:
This code fails silently (Exception("pouet") is raised). If I comment the line with remove collect.xref.targets, a document is correctly output. [...] It seems that the silent failure is a bug, and I may be missing some stuff in order to convert the documents properly.
Did you check the error_log of the XSLT object to see if it reports any errors?
In my listing I have : print "Transform\n", transform.error_log print "Parser\n", parser.error_log
And the printout is empty (except from the strings of course).
Ok, next questions then: which version of lxml, libxml2 and libxslt are you using, and what command line do you use to do the same thing in libxslt? Stefan
On Fri, 03 Sep 2010 22:33:55 +0200 Stefan Behnel <stefan_ml@behnel.de> wrote:
Ok, next questions then: which version of lxml, libxml2 and libxslt are you using, and what command line do you use to do the same thing in libxslt?
Stefan
from lxml import etree print "lxml.etree: ", etree.LXML_VERSION lxml.etree: (2, 2, 6, 0) print "libxml used: ", etree.LIBXML_VERSION
print "libxml compiled: ", etree.LIBXML_COMPILED_VERSION
print "libxslt used: ", etree.LIBXSLT_VERSION
print "libxslt compiled: ", etree.LIBXSLT_COMPILED_VERSION
Python 2.6.5 (release26-maint, Aug 3 2010, 17:34:54) [GCC 4.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. libxml used: (2, 7, 7) libxml compiled: (2, 7, 7) libxslt used: (1, 1, 26) libxslt compiled: (1, 1, 26) /usr/bin/xsltproc --maxdepth 10000 --nonet --xinclude --stringparam olink.base.uri "doc.html" --stringparam collect.xref.targets "yes" --stringparam targets.filename "doc.html.db" --stringparam target.database.document "olinkdb-html.xml" /path/to/the/xsl/xhtml/docbook.xsl.xsl doc.xml > doc.html Regards, -- cJ
On 09/03/2010 04:46 PM, Jérôme Carretero wrote:
...
Hi Stefan, A self-contained test case is available at: git clone git://git.zougloub.eu/docbook_testcase A makefile calls xsltproc and a make.py file tentatively uses lxml to produce html documents from two simple docbook files. HTH, -- cJ
On Mon, 6 Sep 2010 13:53:15 -0400 Jérôme Carretero <cJ-lxml@zougloub.eu> wrote:
On 09/03/2010 04:46 PM, Jérôme Carretero wrote:
...
Out of curiosity I tried trunk r76925 and have the same behavior. -- cJ PS: this was just a pretext to send another mail, to maybe have an answer.
В Птн, 03/09/2010 в 16:15 -0400, Jérôme Carretero пишет:
Hi all, ...... Everything works fine when using xsltproc.
I tried the following : ...... kw = { "olink.base.uri" : "doc.html", "collect.xref.targets" : "yes", "targets.filename" : "doc.html.db", "target.database.document" : "olinkdb-html.xml", }
It seems that the silent failure is a bug, and I may be missing some stuff in order to convert the documents properly.
More complete test cases available upon request.
I've checked your code from the git repo. The difference between your python code and xsltproc is that you do use stringparam with xsltproc but not with lxml. It looks like the usage of XSLT.strparam solves your problem. Please look at attached patch.
participants (3)
-
Alexander Shigin
-
Jérôme Carretero
-
Stefan Behnel