Hi, I get a very consistent error when including an XSL stylesheet from another XSL stylesheet using <xsl:include> or <xsl:import> But the problem is so basic that I cannot believe it could be something inside lxml. So I am overlooking something in my code. When there is a template file named "template.xsl" with ------------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:include href="para.xsl"/> <xsl:template match="*"/> <xsl:template match="/"> <foo>...</foo> </xsl:template> </xsl:stylesheet> ------------------------------------------------ and another template file named: ------------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:template match="para"> This is a paragraph </xsl:template> </xsl:stylesheet> ------------------------------------------------ and then executing the code below ------------------------------------------------ import lxml f = open('template.xsl', 'rb') xslttree = lxml.etree.parse(f) f.close() transformer = lxml.etree.XSLT(xslttree) ------------------------------------------------ the following error is raised: File "xslt.pxi", line 261, in etree.XSLT.__init__ File "etree.pyx", line 133, in etree._ExceptionContext._raise_if_stored etree.XSLTParseError: Cannot resolve URI XSLT://para.xsl All 3 files are in the same directory. And I am in that directory when executing the Python code. What do I do wrong that XSLT cannot resolve the para.xsl file? Petr ---------------------------------------------- Petr van Blokland buro@petr.com | www.petr.com | +31 15 219 10 40 ----------------------------------------------
Hi Petr, Petr van Blokland wrote:
I get a very consistent error when including an XSL stylesheet from another XSL stylesheet using <xsl:include> or <xsl:import> But the problem is so basic that I cannot believe it could be something inside lxml.
the following error is raised:
File "xslt.pxi", line 261, in etree.XSLT.__init__ File "etree.pyx", line 133, in etree._ExceptionContext._raise_if_stored etree.XSLTParseError: Cannot resolve URI XSLT://para.xsl
What do I do wrong that XSLT cannot resolve the para.xsl file?
Nothing. That was a bug in lxml, thanks for reporting it. It stopped working when I started making lxml read file-like objects directly where ever it can. The problem was that libxml2 doesn't get to know the file name in this case and thus can't store it in the document when you call parse(). This prevents the stylesheet from knowing where it came from. Here's a patch: Index: src/lxml/parser.pxi =================================================================== --- src/lxml/parser.pxi (Revision 28159) +++ src/lxml/parser.pxi (Arbeitskopie) @@ -419,6 +419,8 @@ if result is NULL: _raiseParseError(ctxt, c_filename) + elif result.URL is NULL and c_filename is not NULL: + result.URL = tree.xmlStrdup(c_filename) return result ############################################################ BTW, you can also call parse on the filename rather than an open file. That's even more efficient as it doesn't go through Python to read the file. Sorry for the inconvenience, Stefan
Stefan, thanks for the patch. I don't seem to get the change appear in a new compile, however. Isn't it enough to do: python setup.py build python setup.py install Petr On Jun 4, 2006, at 12:16 PM, Stefan Behnel wrote:
Hi Petr,
Petr van Blokland wrote:
I get a very consistent error when including an XSL stylesheet from another XSL stylesheet using <xsl:include> or <xsl:import> But the problem is so basic that I cannot believe it could be something inside lxml.
the following error is raised:
File "xslt.pxi", line 261, in etree.XSLT.__init__ File "etree.pyx", line 133, in etree._ExceptionContext._raise_if_stored etree.XSLTParseError: Cannot resolve URI XSLT://para.xsl
What do I do wrong that XSLT cannot resolve the para.xsl file?
Nothing. That was a bug in lxml, thanks for reporting it. It stopped working when I started making lxml read file-like objects directly where ever it can.
The problem was that libxml2 doesn't get to know the file name in this case and thus can't store it in the document when you call parse(). This prevents the stylesheet from knowing where it came from. Here's a patch:
Index: src/lxml/parser.pxi =================================================================== --- src/lxml/parser.pxi (Revision 28159) +++ src/lxml/parser.pxi (Arbeitskopie) @@ -419,6 +419,8 @@
if result is NULL: _raiseParseError(ctxt, c_filename) + elif result.URL is NULL and c_filename is not NULL: + result.URL = tree.xmlStrdup(c_filename) return result
############################################################
BTW, you can also call parse on the filename rather than an open file. That's even more efficient as it doesn't go through Python to read the file.
Sorry for the inconvenience,
Stefan
---------------------------------------------- Petr van Blokland buro@petr.com | www.petr.com | +31 15 219 10 40 ----------------------------------------------
Hi Petr, Petr van Blokland wrote:
Stefan, thanks for the patch. I don't seem to get the change appear in a new compile, however. Isn't it enough to do: python setup.py build python setup.py install
Do "make clean" first or remove the file src/lxml/etree.c (I assume you have Pyrex 0.9.4.1 installed?). Stefan
participants (2)
-
Petr van Blokland
-
Stefan Behnel