1.1 --- a/XSLForms/Output.py Sun May 08 23:13:39 2005 +0000
1.2 +++ b/XSLForms/Output.py Sun May 15 19:54:13 2005 +0000
1.3 @@ -5,8 +5,8 @@
1.4 """
1.5
1.6 import Constants
1.7 -import libxslt
1.8 -import libxml2
1.9 +import libxsltmod, libxml2mod
1.10 +import libxml2dom
1.11
1.12 """
1.13 import libxml2
1.14 @@ -42,8 +42,8 @@
1.15
1.16 l = []
1.17 # Skip attribute reference.
1.18 - if node.type == "attribute":
1.19 - node = node.parent
1.20 + if node.nodeType == node.ATTRIBUTE_NODE:
1.21 + node = node.parentNode
1.22 # Manually insert the attribute name if defined.
1.23 if attribute_ref:
1.24 # A real attribute is referenced.
1.25 @@ -51,21 +51,21 @@
1.26 l.insert(0, name)
1.27 if multivalue:
1.28 l.insert(0, Constants.multi_separator)
1.29 - l.insert(0, node.name)
1.30 - node = node.parent
1.31 + l.insert(0, node.nodeName)
1.32 + node = node.parentNode
1.33 l.insert(0, Constants.path_separator)
1.34 # Otherwise, treat the element name as an attribute name.
1.35 else:
1.36 - l.insert(0, node.name)
1.37 + l.insert(0, node.nodeName)
1.38 l.insert(0, Constants.path_separator)
1.39 - node = node.parent
1.40 + node = node.parentNode
1.41 # Element references.
1.42 - while node is not None and node.type != "document_xml":
1.43 - l.insert(0, str(int(node.xpathEval("count(preceding-sibling::*) + 1"))))
1.44 + while node is not None and node.nodeType != node.DOCUMENT_NODE:
1.45 + l.insert(0, str(int(node.xpath("count(preceding-sibling::*) + 1"))))
1.46 l.insert(0, Constants.pair_separator)
1.47 - l.insert(0, node.name)
1.48 + l.insert(0, node.nodeName)
1.49 l.insert(0, Constants.path_separator)
1.50 - node = node.parent
1.51 + node = node.parentNode
1.52 return "".join(l)
1.53
1.54 def path_to_context(context, attribute_ref, multivalue_name=None):
1.55 @@ -79,11 +79,10 @@
1.56 name.
1.57 """
1.58
1.59 - pctxt = libxslt.xpathParserContext(_obj=context)
1.60 - context = pctxt.context()
1.61 - node = context.contextNode()
1.62 - transform_context = context.transformContext()
1.63 - name_var = transform_context.variableLookup("this-name", None)
1.64 + context = libxml2mod.xmlXPathParserGetContext(context)
1.65 + #context = libxsltmod.xsltXPathGetTransformContext(pctxt)
1.66 + transform_context = libxsltmod.xsltXPathGetTransformContext(context)
1.67 + name_var = libxsltmod.xsltVariableLookup(transform_context, "this-name", None)
1.68 if multivalue_name is not None:
1.69 name = multivalue_name
1.70 multivalue = 1
1.71 @@ -93,44 +92,49 @@
1.72 else:
1.73 name = None
1.74 multivalue = 0
1.75 + node = libxml2dom.Node(libxml2mod.xmlXPathGetContextNode(context))
1.76 return path_to_node(node, attribute_ref, name, multivalue)
1.77
1.78 def this_position(context):
1.79 - return path_to_context(context, 0)
1.80 + r = path_to_context(context, 0)
1.81 + return r.encode("utf-8")
1.82
1.83 def field_name(context):
1.84 - return path_to_context(context, 1)
1.85 + r = path_to_context(context, 1)
1.86 + return r.encode("utf-8")
1.87
1.88 def multi_field_name(context, multivalue_name):
1.89 - return path_to_context(context, 1, multivalue_name)
1.90 + r = path_to_context(context, 1, multivalue_name)
1.91 + return r.encode("utf-8")
1.92
1.93 def new_field(context, name):
1.94 - return path_to_context(context, 0) + "/" + name
1.95 + r = path_to_context(context, 0) + "/" + name
1.96 + return r.encode("utf-8")
1.97
1.98 def other_field_names(context, nodes):
1.99 names = []
1.100 for node in nodes:
1.101 - n = libxml2.xmlNode(node)
1.102 - name = path_to_node(n, 0, None, 0)
1.103 + name = path_to_node(libxml2dom.Node(node), 0, None, 0)
1.104 if name not in names:
1.105 names.append(name)
1.106 - return ",".join(names)
1.107 + r = ",".join(names)
1.108 + return r.encode("utf-8")
1.109
1.110 def other_multi_field_names(context, multivalue_name, nodes):
1.111 names = []
1.112 for node in nodes:
1.113 - n = libxml2.xmlNode(node)
1.114 - name = path_to_node(n, 1, multivalue_name, 1)
1.115 + name = path_to_node(libxml2dom.Node(node), 1, multivalue_name, 1)
1.116 if name not in names:
1.117 names.append(name)
1.118 - return ",".join(names)
1.119 + r = ",".join(names)
1.120 + return r.encode("utf-8")
1.121
1.122 -libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.123 -libxslt.registerExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
1.124 -libxslt.registerExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
1.125 -libxslt.registerExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
1.126 -libxslt.registerExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
1.127 -libxslt.registerExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names)
1.128 +libxsltmod.xsltRegisterExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.129 +libxsltmod.xsltRegisterExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
1.130 +libxsltmod.xsltRegisterExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
1.131 +libxsltmod.xsltRegisterExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
1.132 +libxsltmod.xsltRegisterExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
1.133 +libxsltmod.xsltRegisterExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names)
1.134
1.135 def get_field_name(field_or_multi_name):
1.136 return field_or_multi_name.split(Constants.multi_separator)[0]