
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 for my example. When I try input_node[0] instead of input_node: results = self.apply_templates(context, input_node[0]) print results results is empty list. 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 -- Marat On Tue, Nov 10, 2009 at 11:26 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
Hi,
please don't top-post.
Marat Dakota, 09.11.2009 10:13:
Than it looks like I don't completely understand how it works. Could you please help me:
XSLT file is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="testns" extension-element-prefixes="my"> <xsl:template match="/"> <foo> <my:ext> <xsl:attribute name="test"><xsl:value-of select="111" /></xsl:attribute> blabla </my:ext> </foo> </xsl:template> </xsl:stylesheet>
Ah, yes, attributes. Attributes are mapped to smart strings when passed through Python code.
Function is:
def execute(self, context, self_node, input_node, output_parent): ????? print etree.tostring(deepcopy(self_node))
Remember that self_node is the extension element itself. It will not change during the evaluation, so printing it is uninteresting.
What should I put instead of ????? to make self_node having attribute named test with "111" as value? I tried to call self.apply_templates for everything (for self_node, for self_node[0], even for input_node and output_parent).
I would guess that you want to call it on "input_node". Calling .apply_templates() should return a string (although I never tested that), which you can then add as a new attribute to the tree. You have to do that manually, though. I would expect that "is_attribute" flag of the smart string to be True in your case (see the XPath docs), that would allow you to distinguish attributes from plain text context.
Stefan