Re: [lxml] Can I change maxvars?
![](https://secure.gravatar.com/avatar/8b97b5aad24c30e4a1357b38cc39aeaa.jpg?s=120&d=mm&r=g)
Sam Bull schrieb am 21.06.2015 um 12:12:
On Mon, 2014-07-14 at 20:52 +0200, Stefan Behnel wrote:
Sam Bull, 12.07.2014 17:15:
I'm trying to process some XML files, and a few of them are several thousand lines long, and with the moderately complicated XSL I'm using, I seem to be hitting recursion limits.
I'm currently getting this message: lxml.etree.XSLTApplyError: xsltApplyXSLTTemplate: A potential infinite template recursion was detected. You can adjust maxTemplateVars (--maxvars) in order to raise the maximum number of variables/params (currently set to 15000).
It says I can adjust the value, but doesn't explain how, nor is this value mentioned anywhere in the documentation.
I've just had to change the maxdepth, which can be done with XSLT.set_global_max_depth(), but there doesn't appear to be an equivalent for maxvars. How can I change this value?
You can't currently. The problem is, it was new in libxslt 1.1.27, and even the next lxml release will still support everything back to 1.1.23, so this needs a little C level hacking to support depending on the libxslt version it compiles against.
The upside is that libxslt 1.1.27 also introduced a per-context setting (maxTemplateVars), i.e. you can define the value for each stylesheet run rather than setting a global value. A new keyword argument for XSLT() should work nicely here, e.g. "max_recursion_vars". The same applies to "maxTemplateDepth" in 1.1.27, which could be set as "max_recursion_depth" in XSLT().
Don't suppose there's been any progress on this?
No. Pull requests still welcome. Stefan
participants (1)
-
Stefan Behnel