1.1 --- a/XSLForms/Output.py Fri Sep 09 21:02:59 2005 +0000
1.2 +++ b/XSLForms/Output.py Fri Sep 09 22:33:03 2005 +0000
1.3 @@ -312,6 +312,34 @@
1.4 output = "".join(l)
1.5 return output
1.6
1.7 +def element_path(context, field_names):
1.8 +
1.9 + """
1.10 + Convert the given 'field_names' back to XPath references.
1.11 + For example:
1.12 + /configuration$1/details$1/base-system$$value -> /*[position() = 1]/*[position() = 1]/base-system
1.13 + If more than one field name is given - ie. 'field_names' contains a
1.14 + comma-separated list of names - then only the first name is used.
1.15 + """
1.16 +
1.17 + field_name = field_names.split(",")[0]
1.18 +
1.19 + # Get the main part of the name (where a multivalue reference was given).
1.20 +
1.21 + field_name = get_field_name(field_name)
1.22 +
1.23 + # Build the XPath expression.
1.24 +
1.25 + parts = field_name.split(Constants.path_separator)
1.26 + new_parts = []
1.27 + for part in parts:
1.28 + path_parts = part.split(Constants.pair_separator)
1.29 + if len(path_parts) == 2:
1.30 + new_parts.append("*[position() = " + path_parts[1] + "]")
1.31 + else:
1.32 + new_parts.append(path_parts[0])
1.33 + return "/".join(new_parts)
1.34 +
1.35 # New functions.
1.36
1.37 libxsltmod.xsltRegisterExtModuleFunction("list-attribute", "http://www.boddie.org.uk/ns/xmltools/template", list_attribute)
1.38 @@ -342,27 +370,9 @@
1.39 # Utility functions.
1.40
1.41 libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode)
1.42 +libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path)
1.43
1.44 def get_field_name(field_or_multi_name):
1.45 return field_or_multi_name.split(Constants.multi_separator)[0]
1.46
1.47 -def get_element_path(field_or_multi_name):
1.48 -
1.49 - """
1.50 - Convert the given 'field_or_multi_name' back to an XPath reference.
1.51 - For example:
1.52 - /configuration$1/details$1/base-system$$value -> /*[position() = 1]/*[position() = 1]/base-system
1.53 - """
1.54 -
1.55 - field_name = get_field_name(field_or_multi_name)
1.56 - parts = field_name.split(Constants.path_separator)
1.57 - new_parts = []
1.58 - for part in parts:
1.59 - path_parts = part.split(Constants.pair_separator)
1.60 - if len(path_parts) == 2:
1.61 - new_parts.append("*[position() = " + path_parts[1] + "]")
1.62 - else:
1.63 - new_parts.append(path_parts[0])
1.64 - return "/".join(new_parts)
1.65 -
1.66 # vim: tabstop=4 expandtab shiftwidth=4