# HG changeset patch # User paulb # Date 1129134571 0 # Node ID 29f8b70da02a6436a4d587e552b586aee2ccae5e # Parent 78d7a2396f753cea4c91dfb5adfe25a9a9547adf [project @ 2005-10-12 16:29:31 by paulb] Added selector-name extension function. diff -r 78d7a2396f75 -r 29f8b70da02a XSLForms/Output.py --- a/XSLForms/Output.py Wed Oct 12 15:26:30 2005 +0000 +++ b/XSLForms/Output.py Wed Oct 12 16:29:31 2005 +0000 @@ -264,6 +264,27 @@ l.append(node_path + Constants.path_separator + attribute_name) return ",".join(l).encode("utf-8") +def selector_name(context, field_name, nodes): + + """ + Exposed as {template:selector-name(field_name, nodes)}. + Provides a selector field name defined using 'field_name' and referring to + the given 'nodes'. For example: + + template:selector-name('add-platform', package/platforms) -> 'add-platform=/package$1/platforms$1' + + NOTE: The 'nodes' must be element references. + """ + + #print "selector_name" + names = [] + for node in nodes: + name = path_to_node(libxml2dom.Node(node), 0, None, 0) + if name not in names: + names.append(field_name + "=" + name) + r = ",".join(names) + return r.encode("utf-8") + # Old implementations. def multi_field_name(context, multivalue_name): @@ -338,6 +359,7 @@ libxsltmod.xsltRegisterExtModuleFunction("other-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_attributes) libxsltmod.xsltRegisterExtModuleFunction("child-element", "http://www.boddie.org.uk/ns/xmltools/template", child_element) libxsltmod.xsltRegisterExtModuleFunction("child-attribute", "http://www.boddie.org.uk/ns/xmltools/template", child_attribute) +libxsltmod.xsltRegisterExtModuleFunction("selector-name", "http://www.boddie.org.uk/ns/xmltools/template", selector_name) # New names.