# HG changeset patch # User paulb # Date 1115590005 0 # Node ID 343eef881239680bfff78146116b15198c842cfc # Parent d782f2178752fb196df532ddf50052853f63f1ad [project @ 2005-05-08 22:06:45 by paulb] Added support for multiple field names, renaming the other-field-name and other-multi-field-name functions to other-field-names and other-multi-field-names respectively. Fixed the field name to XPath expression conversion - the position numbers are solely used to select elements where such numbers are stated. diff -r d782f2178752 -r 343eef881239 XSLForms/Output.py --- a/XSLForms/Output.py Sun May 08 21:05:24 2005 +0000 +++ b/XSLForms/Output.py Sun May 08 22:06:45 2005 +0000 @@ -107,20 +107,30 @@ def new_field(context, name): return path_to_context(context, 0) + "/" + name -def other_field_name(context, nodes): - node = libxml2.xmlNode(nodes[0]) - return path_to_node(node, 0, None, 0) +def other_field_names(context, nodes): + names = [] + for node in nodes: + n = libxml2.xmlNode(node) + name = path_to_node(n, 0, None, 0) + if name not in names: + names.append(name) + return ",".join(names) -def other_multi_field_name(context, multivalue_name, nodes): - node = libxml2.xmlNode(nodes[0]) - return path_to_node(node, 1, multivalue_name, 1) +def other_multi_field_names(context, multivalue_name, nodes): + names = [] + for node in nodes: + n = libxml2.xmlNode(node) + name = path_to_node(n, 1, multivalue_name, 1) + if name not in names: + names.append(name) + return ",".join(names) libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position) libxslt.registerExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name) libxslt.registerExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name) libxslt.registerExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field) -libxslt.registerExtModuleFunction("other-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_field_name) -libxslt.registerExtModuleFunction("other-multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_name) +libxslt.registerExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names) +libxslt.registerExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names) def get_field_name(field_or_multi_name): return field_or_multi_name.split(Constants.multi_separator)[0] @@ -130,7 +140,7 @@ """ Convert the given 'field_or_multi_name' back to an XPath reference. For example: - /configuration#1/base-system##value -> /configuration[1]/base-system + /configuration#1/details#1/base-system##value -> /*[position() = 1]/*[position() = 1]/base-system """ field_name = get_field_name(field_or_multi_name) @@ -139,7 +149,7 @@ for part in parts: path_parts = part.split(Constants.pair_separator) if len(path_parts) == 2: - new_parts.append(path_parts[0] + "[" + path_parts[1] + "]") + new_parts.append("*[position() = " + path_parts[1] + "]") else: new_parts.append(path_parts[0]) return "/".join(new_parts)