6 # Memory debug specific
10 EXT_URL="http://example.com/foo"
13 transformNodeName = None
15 def compile_test(style, inst, func):
18 def transform_test(ctx, node, inst, comp):
22 # Small check to verify the context is correcly accessed
26 # FIXME add some more sanity checks
28 tctxt = libxslt.transformCtxt(_obj=ctx)
29 insertNodeName = tctxt.insertNode().name
31 # FIXME find and confirm the note being replaced is called 'test'
32 # transformNodeName = libxml2.xmlNode(inst).name
36 tctxt.insertNode().addContent('SUCCESS')
40 styledoc = libxml2.parseDoc("""
41 <xsl:stylesheet version='1.0'
42 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
44 xsl:extension-element-prefixes='foo'>
46 <xsl:template match='/'>
47 <article><foo:test>FAILURE</foo:test></article>
48 <deeper><article><foo:test>something<foo:test>nested</foo:test>even</foo:test></article></deeper>
53 style = libxslt.parseStylesheetDoc(styledoc)
54 libxslt.registerExtModuleElement("test", EXT_URL, compile_test, transform_test)
55 doc = libxml2.parseDoc("<doc/>")
56 result = style.applyStylesheet(doc, None)
57 style.freeStylesheet()
61 extensions = StringIO.StringIO()
62 libxslt.debugDumpExtensions(extensions)
64 if 0 and extensions.buf.find(EXT_URL) < 0:
65 print "Element extension not registered (or dumping broken)"
68 root = result.children
70 if root.name != "article":
71 print "Unexpected root node name"
73 if root.content != "SUCCESS":
74 print "Unexpected root node content, extension function failed"
76 if insertNodeName != 'article':
77 print "The function callback failed to access its context"
80 result.dump(sys.stdout)
83 # Memory debug specific
85 if libxml2.debugMemory(1) == 0:
88 print "Memory leak %d bytes" % (libxml2.debugMemory(1))