1.1 --- a/XSLForms/Constants.py Fri May 06 19:07:59 2005 +0000
1.2 +++ b/XSLForms/Constants.py Fri May 06 19:10:17 2005 +0000
1.3 @@ -4,6 +4,7 @@
1.4
1.5 path_separator = "/"
1.6 pair_separator = "#"
1.7 +multi_separator = "##"
1.8 selector_indicator = "="
1.9
1.10 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/XSLForms/Output.py Fri May 06 19:07:59 2005 +0000
2.2 +++ b/XSLForms/Output.py Fri May 06 19:10:17 2005 +0000
2.3 @@ -6,6 +6,7 @@
2.4
2.5 import Constants
2.6 import libxslt
2.7 +import libxml2
2.8
2.9 """
2.10 import libxml2
2.11 @@ -49,8 +50,7 @@
2.12 if name is not None:
2.13 l.insert(0, name)
2.14 if multivalue:
2.15 - l.insert(0, Constants.pair_separator)
2.16 - l.insert(0, Constants.pair_separator)
2.17 + l.insert(0, Constants.multi_separator)
2.18 l.insert(0, node.name)
2.19 node = node.parent
2.20 l.insert(0, Constants.path_separator)
2.21 @@ -107,9 +107,41 @@
2.22 def new_field(context, name):
2.23 return path_to_context(context, 0) + "/" + name
2.24
2.25 +def other_field_name(context, nodes):
2.26 + node = libxml2.xmlNode(nodes[0])
2.27 + return path_to_node(node, 0, None, 0)
2.28 +
2.29 +def other_multi_field_name(context, multivalue_name, nodes):
2.30 + node = libxml2.xmlNode(nodes[0])
2.31 + return path_to_node(node, 1, multivalue_name, 1)
2.32 +
2.33 libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
2.34 libxslt.registerExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
2.35 libxslt.registerExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
2.36 libxslt.registerExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
2.37 +libxslt.registerExtModuleFunction("other-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_field_name)
2.38 +libxslt.registerExtModuleFunction("other-multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_name)
2.39 +
2.40 +def get_field_name(field_or_multi_name):
2.41 + return field_or_multi_name.split(Constants.multi_separator)[0]
2.42 +
2.43 +def get_element_path(field_or_multi_name):
2.44 +
2.45 + """
2.46 + Convert the given 'field_or_multi_name' back to an XPath reference.
2.47 + For example:
2.48 + /configuration#1/base-system##value -> /configuration[1]/base-system
2.49 + """
2.50 +
2.51 + field_name = get_field_name(field_or_multi_name)
2.52 + parts = field_name.split(Constants.path_separator)
2.53 + new_parts = []
2.54 + for part in parts:
2.55 + path_parts = part.split(Constants.pair_separator)
2.56 + if len(path_parts) == 2:
2.57 + new_parts.append(path_parts[0] + "[" + path_parts[1] + "]")
2.58 + else:
2.59 + new_parts.append(path_parts[0])
2.60 + return "/".join(new_parts)
2.61
2.62 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/XSLForms/Prepare.py Fri May 06 19:07:59 2005 +0000
3.2 +++ b/XSLForms/Prepare.py Fri May 06 19:10:17 2005 +0000
3.3 @@ -16,4 +16,22 @@
3.4 template = libxml2dom.parse(template_name)
3.5 proc.send_output(open(output_name, "wb"), encoding, template)
3.6
3.7 +def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding="utf-8"):
3.8 + global resource_dir
3.9 + proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"element-id" : element_id})
3.10 + template = libxml2dom.parse(template_name)
3.11 + proc.send_output(open(output_name, "wb"), encoding, template)
3.12 +
3.13 +def ensure_stylesheet(template_name, output_name):
3.14 + if not os.path.exists(output_name) or \
3.15 + os.path.getmtime(output_name) < os.path.getmtime(template_name):
3.16 +
3.17 + make_stylesheet(template_name, output_name)
3.18 +
3.19 +def ensure_stylesheet_fragment(template_name, output_name, element_id):
3.20 + if not os.path.exists(output_name) or \
3.21 + os.path.getmtime(output_name) < os.path.getmtime(template_name):
3.22 +
3.23 + make_stylesheet_fragment(template_name, output_name, element_id)
3.24 +
3.25 # vim: tabstop=4 expandtab shiftwidth=4