Hi,
as I am trying to learn more of lxml simplicity, I stumpled over a strange
behaviour that I couldn't explain. Probably it's only my wrong understanding. :)
I've played with some extension functions and I could condense my problem to a
small testcase. Maybe it's totally dumb and useless and only my wrong
understanding. Well, let's see. :)
I used the source code from lxml-2.0.6, compiled it and modified the file in
lxml/tests/test_xslt.py. I added the following small test function:
def test_extensions3(self):
tree = self.parse('<a><b>B</b></a>')
style = self.parse('''\
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:myns="testns"
exclude-result-prefixes="myns">
<xsl:template match="a">
<xsl:variable name="content">
<xsl:apply-templates/>
</xsl:variable>
<A><xsl:value-of select="myns:mytext($content)"/></A>
</xsl:template>
</xsl:stylesheet>''')
def mytext(ctxt, values):
return 'X' * len(values)
namespace = etree.FunctionNamespace('testns')
namespace['mytext'] = mytext
result = tree.xslt(style)
self.assertEquals(self._rootstring(result),
_bytes('<A>X</A>'))
Actually, the function test_extensions3() is derived from test_extensions2. The
only difference is the variable content which is passed on to the extension
function. I've expected an identical result like test_extensions2. From what
I know, I think it is a common approach to collect the content in a variable
and pass it on to other functions.
I've ran the testcase like this:
$ python test.py -vv lxml/tests/test_xslt.py
Unfortunately it gives me this output:
======================================================================
ERROR: test_extensions3 (lxml.tests.test_xslt.ETreeXSLTTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.5/unittest.py", line 260, in run
testMethod()
File "/local/repos/home:thomas-schraitle/python-lxml/lxml-2.0.6/src/lxml/tests/test_xslt.py", line 620, in test_extensions3
result = tree.xslt(style)
File "lxml.etree.pyx", line 1732, in lxml.etree._ElementTree.xslt (src/lxml/lxml.etree.c:16290)
File "xslt.pxi", line 457, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:83016)
XSLTApplyError: XPath evaluation returned no result.
----------------------------------------------------------------------
Ran 54 tests in 0.686s
FAILED (errors=1)
Any hints what I'm doing wrong?
Thanks,
Tom
Used libraries:
libxml2-2.6.31-3.1
libxslt-1.1.22-3.2