
Marat Dakota, 10.11.2009 16:58:
On Tue, Nov 10, 2009 at 6:22 PM, Stefan Behnel wrote:
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).
That's sad. Do you think it's hard to implement this feature, are there libxml or libxslt limits that will not allow to do that?
All it takes is figuring out how to make libxslt start its evaluation at a given point in the stylesheet document. That's usually more work than looking it up in the docs, although the place to start would likely be here: http://xmlsoft.org/XSLT/html/index.html http://xmlsoft.org/XSLT/html/libxslt-templates.html
Maybe I could join in and dig a bit? Just don't know where to start. I hope it's not too complicated and it's possible - I have my problem's elegant solution, but it needs this feature.
You can try to dig into libxslt to find it out. I don't currently have the time to implement major new features, but if I get an outline how this should work, so that I can estimate the amount of work it takes, I may get around to do it.
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.
My input document is just:
<dummy />
In that case, input_node[0] just doesn't exist, so there's nothing to do. Actually, I wonder why that doesn't raise an IndexError...
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.
My colleague traced it a bit. He was just very curious if it's python's segfault (which he never met and that's why he's curious) or lxml's one. He said lxml dies when trying to read property tag of input_node.
My guess is that input_node is not an element here but a different kind of XML node. Looks like that case isn't handled in the sources (a seriously blatant omission, although I guess I just didn't expect that this can happen...) Stefan