[xml-bindings]Obscure bug?
- From: Gary Benson <gary inauspicious org>
- To: xml-bindings gnome org
- Subject: [xml-bindings]Obscure bug?
- Date: Thu, 8 Aug 2002 19:02:55 +0100
Hi all,
I think I found a very obscure bug in which extension functions are not
recognised within {} XPath syntax if the stylesheet was imported into
another stylesheet via xsl:import. The attached file broken-ext2func.py
exercises the bug on my system:
| $ ./broken-ext2func.py
| xmlXPathCompOpEval: function foo bound to undefined prefix foo
| Unexpected root property content, extension function failed
The file broken-ext2func-workaround.py contains the workaround that I am
currently using:
| $ ./broken-ext2func-workaround.py
| OK
Can anyone else verify that they are seeing this?
Cheers,
Gary
[ gary inauspicious org ][ GnuPG 85A8F78B ][ http://inauspicious.org/ ]
#!/usr/bin/python -u
import sys
import string
import libxml2
import libxslt
# Memory debug specific
libxml2.debugMemory(1)
nodeName = None
def f(ctx, str):
global nodeName
#
# Small check to verify the context is correcly accessed
#
try:
pctxt = libxslt.xpathParserContext(_obj=ctx)
ctxt = pctxt.context()
tctxt = ctxt.transformContext()
nodeName = tctxt.insertNode().name
except:
pass
return string.upper(str)
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)
open("tmp.xsl", "w").write("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:foo='http://example.com/foo'
xsl:exclude-result-prefixes='foo'>
<xsl:param name='bar'>failure</xsl:param>
<xsl:template match='/'>
<article baz='{foo:foo($bar)}'>
<xsl:value-of select='foo:foo($bar)'/>
</article>
</xsl:template>
</xsl:stylesheet>
""")
styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:import href='tmp.xsl'/>
</xsl:stylesheet>
""")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, { "bar": "'success'" })
style.freeStylesheet()
doc.freeDoc()
root = result.children
if root.name != "article":
print "Unexpected root node name"
sys.exit(1)
if root.content != "SUCCESS":
print "Unexpected root node content, extension function failed"
sys.exit(1)
if root.prop("baz") != "SUCCESS":
print "Unexpected root property content, extension function failed"
sys.exit(1)
if nodeName != 'article':
print "The function callback failed to access its context"
sys.exit(1)
result.freeDoc()
# Memory debug specific
libxslt.cleanup()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()
#!/usr/bin/python -u
import sys
import string
import libxml2
import libxslt
# Memory debug specific
libxml2.debugMemory(1)
nodeName = None
def f(ctx, str):
global nodeName
#
# Small check to verify the context is correcly accessed
#
try:
pctxt = libxslt.xpathParserContext(_obj=ctx)
ctxt = pctxt.context()
tctxt = ctxt.transformContext()
nodeName = tctxt.insertNode().name
except:
pass
return string.upper(str)
libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)
open("tmp.xsl", "w").write("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:foo='http://example.com/foo'
xsl:exclude-result-prefixes='foo'>
<xsl:param name='bar'>failure</xsl:param>
<xsl:template match='/'>
<article>
<xsl:attribute name='baz'>
<xsl:value-of select='foo:foo($bar)'/>
</xsl:attribute>
<xsl:value-of select='foo:foo($bar)'/>
</article>
</xsl:template>
</xsl:stylesheet>
""")
styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:import href='tmp.xsl'/>
</xsl:stylesheet>
""")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, { "bar": "'success'" })
style.freeStylesheet()
doc.freeDoc()
root = result.children
if root.name != "article":
print "Unexpected root node name"
sys.exit(1)
if root.content != "SUCCESS":
print "Unexpected root node content, extension function failed"
sys.exit(1)
if root.prop("baz") != "SUCCESS":
print "Unexpected root property content, extension function failed"
sys.exit(1)
if nodeName != 'article':
print "The function callback failed to access its context"
sys.exit(1)
result.freeDoc()
# Memory debug specific
libxslt.cleanup()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]