1.1 --- a/XSLForms/Output.py Mon Dec 20 21:56:53 2004 +0000
1.2 +++ b/XSLForms/Output.py Mon Dec 20 21:59:30 2004 +0000
1.3 @@ -15,14 +15,22 @@
1.4 libxml2.registerErrorHandler(quiet, None)
1.5 """
1.6
1.7 -def path_to_node(node):
1.8 +def path_to_node(node, name):
1.9
1.10 - "Generate an XSLForms path to the given 'node'."
1.11 + """
1.12 + Generate an XSLForms path to the given 'node', using the given 'name' to
1.13 + complete the path if an attribute reference is required (otherwise 'name'
1.14 + will be None).
1.15 + """
1.16
1.17 l = []
1.18 # Skip attribute reference.
1.19 if node.type == "attribute":
1.20 node = node.parent
1.21 + # Manually insert the attribute name if defined.
1.22 + if name is not None:
1.23 + l.insert(0, name)
1.24 + l.insert(0, "/")
1.25 # Element references.
1.26 while node is not None and node.type != "document_xml":
1.27 l.insert(0, str(int(node.xpathEval("count(preceding-sibling::*) + 1"))))
1.28 @@ -36,13 +44,20 @@
1.29
1.30 """
1.31 As a libxslt extension function, return a string containing the XSLForms
1.32 - path to the 'context' node.
1.33 + path to the 'context' node, using the special "this-name" variable to
1.34 + complete the path if an attribute reference is required.
1.35 """
1.36
1.37 pctxt = libxslt.xpathParserContext(_obj=context)
1.38 context = pctxt.context()
1.39 node = context.contextNode()
1.40 - return path_to_node(node)
1.41 + transform_context = context.transformContext()
1.42 + name_var = transform_context.variableLookup("this-name", None)
1.43 + if name_var is not None:
1.44 + name = name_var[0].content
1.45 + else:
1.46 + name = None
1.47 + return path_to_node(node, name)
1.48
1.49 libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.50