VirtualBox

source: vbox/trunk/src/libs/libxslt-1.1.22/python/tests/extelem.py@ 15017

最後變更 在這個檔案從15017是 7296,由 vboxsync 提交於 17 年 前

Added libxslt-1.1.22 sources.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 2.1 KB
 
1#!/usr/bin/python -u
2import sys
3import string
4import StringIO
5import libxml2
6# Memory debug specific
7libxml2.debugMemory(1)
8import libxslt
9
10EXT_URL="http://example.com/foo"
11
12insertNodeName = None
13transformNodeName = None
14
15def compile_test(style, inst, func):
16 pass
17
18def transform_test(ctx, node, inst, comp):
19 global insertNodeName
20
21 #
22 # Small check to verify the context is correcly accessed
23 #
24 try:
25 #
26 # FIXME add some more sanity checks
27 #
28 tctxt = libxslt.transformCtxt(_obj=ctx)
29 insertNodeName = tctxt.insertNode().name
30
31 # FIXME find and confirm the note being replaced is called 'test'
32 # transformNodeName = libxml2.xmlNode(inst).name
33 except:
34 pass
35
36 tctxt.insertNode().addContent('SUCCESS')
37
38
39
40styledoc = libxml2.parseDoc("""
41<xsl:stylesheet version='1.0'
42 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
43 xmlns:foo='%s'
44 extension-element-prefixes='foo'>
45
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>
49 </xsl:template>
50</xsl:stylesheet>
51""" % EXT_URL)
52
53style = libxslt.parseStylesheetDoc(styledoc)
54libxslt.registerExtModuleElement("test", EXT_URL, compile_test, transform_test)
55doc = libxml2.parseDoc("<doc/>")
56result = style.applyStylesheet(doc, None)
57style.freeStylesheet()
58doc.freeDoc()
59
60
61extensions = StringIO.StringIO()
62libxslt.debugDumpExtensions(extensions)
63
64if 0 and extensions.buf.find(EXT_URL) < 0:
65 print "Element extension not registered (or dumping broken)"
66 sys.exit(1)
67
68root = result.children
69
70if root.name != "article":
71 print "Unexpected root node name"
72 sys.exit(1)
73if root.content != "SUCCESS":
74 print "Unexpected root node content, extension function failed"
75 sys.exit(1)
76if insertNodeName != 'article':
77 print "The function callback failed to access its context"
78 sys.exit(1)
79
80result.dump(sys.stdout)
81result.freeDoc()
82
83# Memory debug specific
84libxslt.cleanup()
85if libxml2.debugMemory(1) == 0:
86 print "OK"
87else:
88 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
89 libxml2.dumpMemory()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette