[lxml-dev] NotImplementedError for external functions with xsl:variable's

Greetings, We've been using lxml for almost a year now. Recently we were stuck with XSLT functionality and eventually started to use external functions, which are pretty useful in many cases. Of course, this makes the template unportable, but we deal with this. So, we register the functions in our namespace for the transformer and use them like this: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="http://rambler.ru/fe" extension-element-prefixes="fe"> <xsl:template match="/"> query=<xsl:value-of select="fe:quote($query)"/> </xsl:tempalte> Here $query is the external parameter passed to the transformer. Works fine. But when we slightly modify the template and want to use not the external parameter, but xsl:variable, we fail: <xsl:template match="/"> <xsl:variable name="query1">asdfadsfadsf</xsl:variable> query=<xsl:value-of select="fe:quote($query1)"/> </xsl:tempalte> We have lxml 2.0.1 in production and 2.1 on the development machine. The problem occurs, but in slightly different manner, in both situations. 2.0.1 just performs nothing and returns an empty string; 2.1 raises File "xslt.pxi", line 515, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:90526) File "lxml.etree.pyx", line 233, in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:4916) File "extensions.pxi", line 665, in lxml.etree._extension_function_call (src/lxml/lxml.etree.c:82995) File "extensions.pxi", line 513, in lxml.etree._unwrapXPathObject (src/lxml/lxml.etree.c:81828) NotImplementedError As far as I can understand, this situation is handled explicitly in 2.1 and there are reasons for that. So, may I ask if it is implemented sometime later? Cheers, Dmitri

Hi, Dmitri Fedoruk wrote:
This might or might not be related: https://bugs.launchpad.net/lxml/+bug/208339 Since you are using 2.0.1, it *might* mean that the exception is raised but not propagated.
As far as I can understand, this situation is handled explicitly in 2.1 and there are reasons for that.
A NotImplementedError means just that: it's not implemented (yet). I don't know what libxml2 XPath object type is involved here - I should really put the offending type into the exception message in _unwrapXPathObject() ... I'll give it a try on my side as soon as I get to it. Stefan

Hi Dmitri, Dmitri Fedoruk wrote:
I was right in recalling that I had started working on this before, but according to the partial patch in my working directory, I never got around to finishing it up. I assume that your real stylesheet creates a result tree fragment for the variable that you pass into your function. Until now, lxml didn't handle result trees at all. I'm not exactly sure what a result tree fragment looks like in libxslt in all possible cases, but what I implemented on the trunk so far works for me. Please give it a try (after installing Cython 0.10). It would be nice if you could come up with a couple of additional test cases for test_xslt.py to make sure this works (and continues to work) as expected for different variable values or <xsl:copy-of> scenarios. Currently, there is only test_variable_result_tree_fragment(), which tests for result trees returned by <xsl:apply-templates/>. Have fun, Stefan

Hello everybody,
I assume that your real stylesheet creates a result tree fragment for the variable that you pass into your function.
To be frank - it's not like that. We used variables just as function parameters (e.g. a float number). But using a tree is a very powerful feature, too.
Please give it a try (after installing Cython 0.10).
lxml.etree: (2, 2, -199, 59835) libxml used: (2, 6, 30) libxml compiled: (2, 6, 30) libxslt used: (1, 1, 22) libxslt compiled: (1, 1, 22) I've attached the test source. In brief - it works :) I tried to test the variable as a number literal, as a string and as a tree. I got expected results in all cases.
I'll try to - sorry, nothing has came up to my mind yet. Maybe we'll encounter some tricky cases in our templates, then I'll report them. Cheers, Dmitri

Hi, Dmitri Fedoruk wrote:
This might or might not be related: https://bugs.launchpad.net/lxml/+bug/208339 Since you are using 2.0.1, it *might* mean that the exception is raised but not propagated.
As far as I can understand, this situation is handled explicitly in 2.1 and there are reasons for that.
A NotImplementedError means just that: it's not implemented (yet). I don't know what libxml2 XPath object type is involved here - I should really put the offending type into the exception message in _unwrapXPathObject() ... I'll give it a try on my side as soon as I get to it. Stefan

Hi Dmitri, Dmitri Fedoruk wrote:
I was right in recalling that I had started working on this before, but according to the partial patch in my working directory, I never got around to finishing it up. I assume that your real stylesheet creates a result tree fragment for the variable that you pass into your function. Until now, lxml didn't handle result trees at all. I'm not exactly sure what a result tree fragment looks like in libxslt in all possible cases, but what I implemented on the trunk so far works for me. Please give it a try (after installing Cython 0.10). It would be nice if you could come up with a couple of additional test cases for test_xslt.py to make sure this works (and continues to work) as expected for different variable values or <xsl:copy-of> scenarios. Currently, there is only test_variable_result_tree_fragment(), which tests for result trees returned by <xsl:apply-templates/>. Have fun, Stefan

Hello everybody,
I assume that your real stylesheet creates a result tree fragment for the variable that you pass into your function.
To be frank - it's not like that. We used variables just as function parameters (e.g. a float number). But using a tree is a very powerful feature, too.
Please give it a try (after installing Cython 0.10).
lxml.etree: (2, 2, -199, 59835) libxml used: (2, 6, 30) libxml compiled: (2, 6, 30) libxslt used: (1, 1, 22) libxslt compiled: (1, 1, 22) I've attached the test source. In brief - it works :) I tried to test the variable as a number literal, as a string and as a tree. I got expected results in all cases.
I'll try to - sorry, nothing has came up to my mind yet. Maybe we'll encounter some tricky cases in our templates, then I'll report them. Cheers, Dmitri
participants (2)
-
Dmitri Fedoruk
-
Stefan Behnel