[lxml-dev] exslt functions in xpath expressions

During XPath Evaluations in XSL-Transformations it's possible to use Stuff from http://www.exslt.org/ (so [5] does indeed match the <a> element). During XPath Evaluations its only possible to use standard XPath/XSLT Functions. Is there a chance to enable the functions from exslt for lxml XPath evaluations as well? ========================================================= In [1]: from lxml import etree In [2]: from StringIO import StringIO In [3]: tree = etree.parse(StringIO('<a b="12"/>')) In [4]: print tree.xpath('/a[@b=concat("1","2")]') [<Element a at 2dbfbd0>] In [5]: print tree.xpath('/a[@b=str:split("12 34")]') [] ========================================================= --dirk

Dirk Rothe, 29.01.2010 09:57:
They should be enabled. But you have to specify the namespace of the function you use. http://codespeak.net/lxml/xpathxslt.html#xpath Stefan

On Fri, 29 Jan 2010 11:29:30 +0100, Dirk Rothe <d.rothe@semantics.de> wrote:
Hmm, but it's not working: ========================================================= In [9]: print tree.xpath("/a[@b=str:split('12 34')]", namespaces={'str': "http://exslt.org/strings"}) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (23303, 0)) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (24793, 0)) --------------------------------------------------------------------------- XPathEvalError Traceback (most recent call last) D:\vls-trunk\server\bin\<ipython console> in <module>() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._ElementTree.xpath (sr c/lxml/lxml.etree.c:41699)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree.XPathDocumentEvaluator .__call__ (src/lxml/lxml.etree.c:103472)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._XPathEvaluatorBase._h andle_result (src/lxml/lxml.etree.c:102330)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._XPathEvaluatorBase._r aise_eval_error (src/lxml/lxml.etree.c:102153)() XPathEvalError: Unregistered function

Dirk Rothe, 30.01.2010 16:14:
You're right, they are currently only available to XSLT. It seems that at least the date, math, sets and string functions can be enabled in plain XPath, but only from libxslt 1.1.25 onwards. That version was released on 2009-09-17, so it's fairly recent. http://xmlsoft.org/XSLT/EXSLT/html/libexslt-exslt.html Could you file a feature request for this in the bug tracker? I should be able to add support in lxml 2.3. Stefan

done: https://bugs.launchpad.net/lxml/+bug/515553 On Sat, 30 Jan 2010 17:10:25 +0100, Stefan Behnel <stefan_ml@behnel.de> wrote:

Dirk Rothe, 29.01.2010 09:57:
They should be enabled. But you have to specify the namespace of the function you use. http://codespeak.net/lxml/xpathxslt.html#xpath Stefan

On Fri, 29 Jan 2010 11:29:30 +0100, Dirk Rothe <d.rothe@semantics.de> wrote:
Hmm, but it's not working: ========================================================= In [9]: print tree.xpath("/a[@b=str:split('12 34')]", namespaces={'str': "http://exslt.org/strings"}) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (23303, 0)) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (24793, 0)) --------------------------------------------------------------------------- XPathEvalError Traceback (most recent call last) D:\vls-trunk\server\bin\<ipython console> in <module>() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._ElementTree.xpath (sr c/lxml/lxml.etree.c:41699)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree.XPathDocumentEvaluator .__call__ (src/lxml/lxml.etree.c:103472)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._XPathEvaluatorBase._h andle_result (src/lxml/lxml.etree.c:102330)() d:\vls-trunk\environment\python25\lib\site-packages\lxml-2.2.2-py2.5-win32.egg\lxml\etree.pyd in lxml.etree._XPathEvaluatorBase._r aise_eval_error (src/lxml/lxml.etree.c:102153)() XPathEvalError: Unregistered function

Dirk Rothe, 30.01.2010 16:14:
You're right, they are currently only available to XSLT. It seems that at least the date, math, sets and string functions can be enabled in plain XPath, but only from libxslt 1.1.25 onwards. That version was released on 2009-09-17, so it's fairly recent. http://xmlsoft.org/XSLT/EXSLT/html/libexslt-exslt.html Could you file a feature request for this in the bug tracker? I should be able to add support in lxml 2.3. Stefan

done: https://bugs.launchpad.net/lxml/+bug/515553 On Sat, 30 Jan 2010 17:10:25 +0100, Stefan Behnel <stefan_ml@behnel.de> wrote:
participants (2)
-
Dirk Rothe
-
Stefan Behnel