[lxml-dev] Error from Variables in Extension Functions?
jholg at gmx.de
jholg at gmx.de
Thu Jun 12 11:30:13 CEST 2008
Hi,
> def test_extensions3(self):
> tree = self.parse('<a><b>B</b></a>')
> style = self.parse('''\
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:myns="testns"
> exclude-result-prefixes="myns">
> <xsl:template match="a">
> <xsl:variable name="content">
> <xsl:apply-templates/>
> </xsl:variable>
> <A><xsl:value-of select="myns:mytext($content)"/></A>
> </xsl:template>
> </xsl:stylesheet>''')
>
> def mytext(ctxt, values):
> return 'X' * len(values)
>
> namespace = etree.FunctionNamespace('testns')
> namespace['mytext'] = mytext
>
> result = tree.xslt(style)
> self.assertEquals(self._rootstring(result),
> _bytes('<A>X</A>'))
>
> Actually, the function test_extensions3() is derived from
> test_extensions2. The
> only difference is the variable content which is passed on to the
> extension
> function. I've expected an identical result like test_extensions2. From
> what
> I know, I think it is a common approach to collect the content in a
> variable
> and pass it on to other functions.
>
> [...]
>
> Any hints what I'm doing wrong?
>
In the stylesheet, your selection of content into the "content" XSLT
variable does not
work.
Try s.th. like
style = self.parse('''\
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:myns="testns"
exclude-result-prefixes="myns">
<xsl:template match="a">
<xsl:variable name="content" select="*"/>
<A><xsl:value-of select="myns:mytext($content)"/></A>
</xsl:template>
</xsl:stylesheet>''')
Cheers,
Holger
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20080612/28125f5c/attachment.htm
More information about the lxml-dev
mailing list