
Hi, please, don't top-post. Marat Dakota, 10.11.2009 10:38:
Thanks for reply. It looks like it's not working as expected.
class MyExtElement(etree.XSLTExtension): def execute(self, context, self_node, input_node, output_parent): results = self.apply_templates(context, input_node) print results
This code causes:
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in 'lxml.etree._callExtensionElement' ignored [<Element foo at 1007b0998>] [<Element foo at 1007b0940>] [<Element foo at 1007b0a48>] [<Element foo at 1007b0aa0>] [<Element foo at 1007b0af8>] ... and so on
Ok, that's a bug. It shouldn't swallow that exception. It's because it's trying to call Python functions in the exception handler, which fails if the recursion limit is already reached. I'll see if I can make this more robust. But, yes, the above will necessarily lead to infinite recursion. Sorry, didn't think of that. The feature you want is not "apply_templates", as that just mimics the behaviour of xsl:apply-templates in XSLT, i.e. you can't define which template will be applied or which XSL tags will run. That feature is currently not available (apart from creating a new stylesheet from the content of the extension element and applying that to input_node, but that's a clumsy and also incomplete solution).
When I try input_node[0] instead of input_node:
results = self.apply_templates(context, input_node[0]) print results
results is empty list.
You didn't show your input document, so I don't know what "input_node" or "input_node[0]" actually are in your case.
By the way, this simple code causes segmentation fault on my OSX, Linux and Windows machines.
class MyExtElement(etree.XSLTExtension): def execute(self, context, self_node, input_node, output_parent): print input_node
No idea why, I'll have to look into that. Stefan