# HG changeset patch # User paulb # Date 1103579970 0 # Node ID b7a19be862e53ee884a34b03eefb0c04b6c51489 # Parent bf578d9e17b1462cd2f32932179d41541d54a6ef [project @ 2004-12-20 21:59:30 by paulb] Fixed the "this-position" external function to give the full path to each attribute, relying on the "this-name" variable where the context node is the parent element of a future attribute (ie. the attribute does not exist yet). diff -r bf578d9e17b1 -r b7a19be862e5 XSLForms/Output.py --- a/XSLForms/Output.py Mon Dec 20 21:56:53 2004 +0000 +++ b/XSLForms/Output.py Mon Dec 20 21:59:30 2004 +0000 @@ -15,14 +15,22 @@ libxml2.registerErrorHandler(quiet, None) """ -def path_to_node(node): +def path_to_node(node, name): - "Generate an XSLForms path to the given 'node'." + """ + Generate an XSLForms path to the given 'node', using the given 'name' to + complete the path if an attribute reference is required (otherwise 'name' + will be None). + """ l = [] # Skip attribute reference. if node.type == "attribute": node = node.parent + # Manually insert the attribute name if defined. + if name is not None: + l.insert(0, name) + l.insert(0, "/") # Element references. while node is not None and node.type != "document_xml": l.insert(0, str(int(node.xpathEval("count(preceding-sibling::*) + 1")))) @@ -36,13 +44,20 @@ """ As a libxslt extension function, return a string containing the XSLForms - path to the 'context' node. + path to the 'context' node, using the special "this-name" variable to + complete the path if an attribute reference is required. """ pctxt = libxslt.xpathParserContext(_obj=context) context = pctxt.context() node = context.contextNode() - return path_to_node(node) + transform_context = context.transformContext() + name_var = transform_context.variableLookup("this-name", None) + if name_var is not None: + name = name_var[0].content + else: + name = None + return path_to_node(node, name) libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)