[lxml-dev] Resolvers not passed on to sub-documents?

Stefan Behnel stefan_ml at behnel.de
Mon May 21 16:28:01 CEST 2007


Hi,

Sidnei da Silva wrote:
> This might or might not have been fixed recently. I am using lxml 1.2.
> I'm writing a self-contained test for this.
> 
> If you have a XSLT that includes another XSLT, which in turn includes
> a third one, the resolvers doesn't seem to be passed on.
> 
> theme.xsl:
>   xsl:import sub.xsl
> 
> sub.xsl:
>   xsl:import common.xsl
> 
> The custom resolver I passed when parsing theme.xsl is used to resolve
> 'sub.xsl' but not to resolve 'common.xsl'.

That's quite possible as keeping track of parsed documents in XSLT isn't the
most simple thing on earth. We had the same problem with XInclude (where
nothing would help), but it should be fixable for XSLT.

Could you check if the attached (and completely untested) patch fixes the
problem? It's against the trunk, but should apply to 1.2 also.

In case this patch helps, 'mind coming up with a test case for it? That could
easily convince me that I should include it in lxml 1.3. :)

Stefan

Index: src/lxml/xslt.pxi
===================================================================
--- src/lxml/xslt.pxi   (Revision 43508)
+++ src/lxml/xslt.pxi   (Arbeitskopie)
@@ -141,6 +141,8 @@
     c_doc = _xslt_resolve_stylesheet(c_uri, c_pcontext)
     if c_doc is not NULL:
         python.PyGILState_Release(gil_state)
+        if c_type == xslt.XSLT_LOAD_STYLESHEET:
+            c_doc._private = c_pcontext
         return c_doc

     c_doc = _xslt_resolve_from_python(c_uri, c_pcontext, parse_options, &error)
@@ -151,6 +153,8 @@
             _xslt_store_resolver_exception(c_uri, c_pcontext, c_type)

     python.PyGILState_Release(gil_state)
+    if c_doc is not NULL and c_type == xslt.XSLT_LOAD_STYLESHEET:
+        c_doc._private = c_pcontext
     return c_doc

 cdef xslt.xsltDocLoaderFunc XSLT_DOC_DEFAULT_LOADER


More information about the lxml-dev mailing list