
cazic@gmx.net wrote:
Stefan Behnel wrote:
I changed the code on the trunk to create a fake URL for the case that the document URL is empty. So, document('') should now work from any stylesheet (if anyone wants to verify...)
Does it still reparse the stylesheet document?
I'm not changing anything here, I'm only providing a URL for the stylesheet, which already exists for stylesheets read from files or the network. I tried this: ----------------------
from lxml.etree import XSLT,XML xml = XML("""\ ... <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"> ... <template match="/"> ... <copy-of select="document('')/*/*"/> ... </template> ... </stylesheet>""") xslt=XSLT(xml) str(xslt(xml) '<?xml version="1.0"?>\n<template xmlns="http://www.w3.org/1999/XSL/Transform" match="/"><copy-of select="document(\'\')/*/*"/></template>\n'
The output is all in one line. strace tells me that it tries to find the fake file and fails. It then checks a catalog in /etc/xml and then retries finding the fake file (which fails again). However, it then returns the above tree, so there must be a fallback somewhere that lets document('') succeed.
If you managed to reuse the stylesheet-tree for this purpose then this will produce problems, since the stylesheet-compilation process of Libxslt will change the tree; i.e., e.g. it will eliminate xsl:text elements and preserve whitespace-only text-nodes if they are children of xsl:text.
That would produce the above output, yes. So, what you say is that we should rather handle the lookup "manually"? That would require copying the document twice before the XSLT compilation, to use one copy for compilation and to store the other one. The doc loader would then return a copy of the second copy when the stylesheet URL is requested. Is that the correct approach? That would really make it a lot of deep copying. If this is really necessary, would you mind if I called this behaviour a bug in libxslt? Stefan