XSLT extension elements: self_node evaluated only sometimes

Bug #2020895 reported by Stanislaw Findeisen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
New
Undecided
Unassigned

Bug Description

Hi, I am following this example: https://lxml.de/extensions.html#xslt-extension-elements . All good, and it even works if I substitute this line:

<foo><my:ext><child>xyz</child></my:ext></foo>

with this line:

<foo><my:ext><child>xyz<xsl:text>123</xsl:text></child></my:ext></foo>

that is, I get in the output:

<foo>I did it!<child>xyz123</child></foo>

which is great.

However, if instead I do:

<foo><my:ext><child>xyz<xsl:value-of select="text()"/></child></my:ext></foo>

then the output becomes:

<foo>I did it!<child xmlns:xsl="http://www.w3.org/1999/XSL/Transform">xyz<xsl:value-of select="text()"/></child></foo>

which is not what I want because I want this to be evaluated.

This means the XSLT inside the extension element gets evaluated _sometimes_. xsl:text gets evaluated but xsl:value-of does not.

Here your original code from the documentation, in one piece:

import lxml.etree as etree

class MyExtElement(etree.XSLTExtension):
    def execute(self, context, self_node, input_node, output_parent):
        print("Hello from XSLT!")
        output_parent.text = "I did it!"
        # just copy own content input to output
        output_parent.extend( list(self_node) )
        # output_parent.append(self_node)

xslt_ext_tree = etree.XML('''
 <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><child>XYZ</child></my:ext></foo>
     </xsl:template>
     <xsl:template match="child">
         <CHILD>--xyz--</CHILD>
     </xsl:template>
 </xsl:stylesheet>''')

my_extension = MyExtElement()
extensions = { ('testns', 'ext') : my_extension }
transform = etree.XSLT(xslt_ext_tree, extensions = extensions)

root = etree.XML('<dummy/>')
result = transform(root)
print(str(result))

Here my config:

Python : sys.version_info(major=3, minor=9, micro=2, releaselevel='final', serial=0)
lxml.etree : (4, 6, 3, 0)
libxml used : (2, 9, 10)
libxml compiled : (2, 9, 10)
libxslt used : (1, 1, 34)
libxslt compiled : (1, 1, 34)

Thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.