[lxml-dev] Avoiding re-parsing for document loading

I have an XSLT that accesses a number of other documents. These other documents are also created in lxml. Is there a way to pass them to my stylesheet without incurring an additional parse? Laurence

http://codespeak.net/lxml/resolvers.html I believe that's what you want. If you don't mind making your XSLT bound to your lxml setup, you could also make custom XSLT/XPath extension functions that returned nodesets. --Paul On Jan 30, 2009, at 10:04 AM, Laurence Rowe wrote:

Sadly this doesn't work: Traceback (most recent call last): File "blocks.py", line 72, in ? output = render(page_path, layout_path, tile_path) File "blocks.py", line 59, in render layout_transform = XSLT(compiler(layout)) File "xslt.pxi", line 505, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:103335) File "lxml.etree.pyx", line 227, in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:6442) File "xslt.pxi", line 90, in lxml.etree._xslt_resolve_from_python (src/lxml/lxml.etree.c:99907) TypeError: Cannot convert lxml.etree._ElementTree to lxml.etree._InputDocument I have to use one of return_{filename|file|string|empty} which means serializing the document and reparsing. Laurence 2009/1/30 Paul Everitt <paul@agendaless.com>:

Hi, Laurence Rowe wrote:
This might be a way to do it: http://codespeak.net/lxml/extensions.html#xslt-extension-elements That said, you should still do some performance measurements to see if parsing a document that you return from a custom resolver (called when encountering the document() function) is really expensive enough to merit a custom solution. Parsing is an impressively cheap thing in lxml/libxml2. Stefan

http://codespeak.net/lxml/resolvers.html I believe that's what you want. If you don't mind making your XSLT bound to your lxml setup, you could also make custom XSLT/XPath extension functions that returned nodesets. --Paul On Jan 30, 2009, at 10:04 AM, Laurence Rowe wrote:

Sadly this doesn't work: Traceback (most recent call last): File "blocks.py", line 72, in ? output = render(page_path, layout_path, tile_path) File "blocks.py", line 59, in render layout_transform = XSLT(compiler(layout)) File "xslt.pxi", line 505, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:103335) File "lxml.etree.pyx", line 227, in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:6442) File "xslt.pxi", line 90, in lxml.etree._xslt_resolve_from_python (src/lxml/lxml.etree.c:99907) TypeError: Cannot convert lxml.etree._ElementTree to lxml.etree._InputDocument I have to use one of return_{filename|file|string|empty} which means serializing the document and reparsing. Laurence 2009/1/30 Paul Everitt <paul@agendaless.com>:

Hi, Laurence Rowe wrote:
This might be a way to do it: http://codespeak.net/lxml/extensions.html#xslt-extension-elements That said, you should still do some performance measurements to see if parsing a document that you return from a custom resolver (called when encountering the document() function) is really expensive enough to merit a custom solution. Parsing is an impressively cheap thing in lxml/libxml2. Stefan
participants (3)
-
Laurence Rowe
-
Paul Everitt
-
Stefan Behnel