예제 #1
0
styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:foo='%s'
  extension-element-prefixes='foo'>

  <xsl:template match='/'>
    <article><foo:test>FAILURE</foo:test></article>
    <deeper><article><foo:test>something<foo:test>nested</foo:test>even</foo:test></article></deeper>
  </xsl:template>
</xsl:stylesheet>
""" % EXT_URL)

style = libxslt.parseStylesheetDoc(styledoc)
libxslt.registerExtModuleElement("test", EXT_URL, compile_test, transform_test)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, None)
style.freeStylesheet()
doc.freeDoc()


extensions = StringIO.StringIO()
libxslt.debugDumpExtensions(extensions)

if 0 and extensions.buf.find(EXT_URL) < 0:
    print "Element extension not registered (or dumping broken)"
    sys.exit(1)

root = result.children
예제 #2
0
styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:foo='%s'
  extension-element-prefixes='foo'>

  <xsl:template match='/'>
    <article><foo:test>FAILURE</foo:test></article>
    <deeper><article><foo:test>something<foo:test>nested</foo:test>even</foo:test></article></deeper>
  </xsl:template>
</xsl:stylesheet>
""" % EXT_URL)

style = libxslt.parseStylesheetDoc(styledoc)
libxslt.registerExtModuleElement("test", EXT_URL, compile_test, transform_test)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, None)
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 insertNodeName != 'article':
    print("The function callback failed to access its context")