1.1 --- a/XSLForms/Output.py Fri May 06 19:07:59 2005 +0000
1.2 +++ b/XSLForms/Output.py Fri May 06 19:10:17 2005 +0000
1.3 @@ -6,6 +6,7 @@
1.4
1.5 import Constants
1.6 import libxslt
1.7 +import libxml2
1.8
1.9 """
1.10 import libxml2
1.11 @@ -49,8 +50,7 @@
1.12 if name is not None:
1.13 l.insert(0, name)
1.14 if multivalue:
1.15 - l.insert(0, Constants.pair_separator)
1.16 - l.insert(0, Constants.pair_separator)
1.17 + l.insert(0, Constants.multi_separator)
1.18 l.insert(0, node.name)
1.19 node = node.parent
1.20 l.insert(0, Constants.path_separator)
1.21 @@ -107,9 +107,41 @@
1.22 def new_field(context, name):
1.23 return path_to_context(context, 0) + "/" + name
1.24
1.25 +def other_field_name(context, nodes):
1.26 + node = libxml2.xmlNode(nodes[0])
1.27 + return path_to_node(node, 0, None, 0)
1.28 +
1.29 +def other_multi_field_name(context, multivalue_name, nodes):
1.30 + node = libxml2.xmlNode(nodes[0])
1.31 + return path_to_node(node, 1, multivalue_name, 1)
1.32 +
1.33 libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.34 libxslt.registerExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
1.35 libxslt.registerExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
1.36 libxslt.registerExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
1.37 +libxslt.registerExtModuleFunction("other-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_field_name)
1.38 +libxslt.registerExtModuleFunction("other-multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_name)
1.39 +
1.40 +def get_field_name(field_or_multi_name):
1.41 + return field_or_multi_name.split(Constants.multi_separator)[0]
1.42 +
1.43 +def get_element_path(field_or_multi_name):
1.44 +
1.45 + """
1.46 + Convert the given 'field_or_multi_name' back to an XPath reference.
1.47 + For example:
1.48 + /configuration#1/base-system##value -> /configuration[1]/base-system
1.49 + """
1.50 +
1.51 + field_name = get_field_name(field_or_multi_name)
1.52 + parts = field_name.split(Constants.path_separator)
1.53 + new_parts = []
1.54 + for part in parts:
1.55 + path_parts = part.split(Constants.pair_separator)
1.56 + if len(path_parts) == 2:
1.57 + new_parts.append(path_parts[0] + "[" + path_parts[1] + "]")
1.58 + else:
1.59 + new_parts.append(path_parts[0])
1.60 + return "/".join(new_parts)
1.61
1.62 # vim: tabstop=4 expandtab shiftwidth=4