1.1 --- a/XSLForms/Output.py Thu Jul 21 16:11:32 2005 +0000
1.2 +++ b/XSLForms/Output.py Thu Jul 21 16:13:09 2005 +0000
1.3 @@ -50,10 +50,15 @@
1.4 otherwise 'name' will be None and the context node will be treated like an
1.5 attribute).
1.6
1.7 - If 'multivalue' is true, produce an attribute reference using the given
1.8 - 'name' of the following form:
1.9 + If 'multivalue' is true and 'attribute_ref' is set, produce an attribute
1.10 + reference using the given 'name':
1.11
1.12 /package$1/categories$1/category$$name
1.13 +
1.14 + If 'multivalue' is true and 'attribute_ref' is not set, produce an attribute
1.15 + reference using the given 'name' of form (element, attribute):
1.16 +
1.17 + /package$1/categories$1/element$$attribute
1.18 """
1.19
1.20 l = []
1.21 @@ -71,10 +76,19 @@
1.22 node = node.parentNode
1.23 l.insert(0, Constants.path_separator)
1.24 # Otherwise, treat the element name as an attribute name.
1.25 + # NOTE: Not sure how useful this is.
1.26 else:
1.27 l.insert(0, node.nodeName)
1.28 l.insert(0, Constants.path_separator)
1.29 node = node.parentNode
1.30 + # Otherwise insert any multivalue references (eg. list-attribute).
1.31 + elif multivalue:
1.32 + element_name, attribute_name = name
1.33 + l.insert(0, attribute_name)
1.34 + l.insert(0, Constants.multi_separator)
1.35 + l.insert(0, element_name)
1.36 + l.insert(0, Constants.path_separator)
1.37 +
1.38 # Element references.
1.39 while node is not None and node.nodeType != node.DOCUMENT_NODE:
1.40 l.insert(0, str(int(node.xpath("count(preceding-sibling::*) + 1"))))
1.41 @@ -150,14 +164,48 @@
1.42 r = ",".join(names)
1.43 return r.encode("utf-8")
1.44
1.45 +# New implementations.
1.46 +
1.47 +def list_attribute(context, element_name, attribute_name):
1.48 + #print "list_attribute"
1.49 + r = path_to_context(context, 0, (element_name, attribute_name))
1.50 + return r.encode("utf-8")
1.51 +
1.52 +def other_list_attributes(context, element_name, attribute_name, nodes):
1.53 + #print "other_list_attributes"
1.54 + names = []
1.55 + for node in nodes:
1.56 + name = path_to_node(libxml2dom.Node(node), 0, (element_name, attribute_name), 1)
1.57 + if name not in names:
1.58 + names.append(name)
1.59 + r = ",".join(names)
1.60 + return r.encode("utf-8")
1.61 +
1.62 +def other_attributes(context, attribute_name, nodes):
1.63 + #print "other_attributes"
1.64 + # NOTE: Cannot directly reference attributes in the nodes list because
1.65 + # NOTE: libxml2dom does not yet support parent element discovery on
1.66 + # NOTE: attributes.
1.67 + names = []
1.68 + for node in nodes:
1.69 + name = path_to_node(libxml2dom.Node(node), 1, attribute_name, 0)
1.70 + if name not in names:
1.71 + names.append(name)
1.72 + r = ",".join(names)
1.73 + return r.encode("utf-8")
1.74 +
1.75 +# New functions.
1.76 +
1.77 +libxsltmod.xsltRegisterExtModuleFunction("list-attribute", "http://www.boddie.org.uk/ns/xmltools/template", list_attribute)
1.78 +libxsltmod.xsltRegisterExtModuleFunction("other-list-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_list_attributes)
1.79 +libxsltmod.xsltRegisterExtModuleFunction("other-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_attributes)
1.80 +
1.81 # New names.
1.82
1.83 libxsltmod.xsltRegisterExtModuleFunction("this-element", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.84 libxsltmod.xsltRegisterExtModuleFunction("this-attribute", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
1.85 -libxsltmod.xsltRegisterExtModuleFunction("list-attribute", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
1.86 libxsltmod.xsltRegisterExtModuleFunction("new-attribute", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
1.87 -libxsltmod.xsltRegisterExtModuleFunction("other-nodes", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
1.88 -libxsltmod.xsltRegisterExtModuleFunction("other-list-attributes", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names)
1.89 +libxsltmod.xsltRegisterExtModuleFunction("other-elements", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
1.90
1.91 # Old names.
1.92