1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/XSLForms/Output.py Mon Dec 20 00:30:39 2004 +0000
1.3 @@ -0,0 +1,50 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +XSL-based form templating.
1.8 +"""
1.9 +
1.10 +import libxslt
1.11 +
1.12 +"""
1.13 +import libxml2
1.14 +
1.15 +def quiet(context, s):
1.16 + pass
1.17 +
1.18 +libxml2.registerErrorHandler(quiet, None)
1.19 +"""
1.20 +
1.21 +def path_to_node(node):
1.22 +
1.23 + "Generate an XSLForms path to the given 'node'."
1.24 +
1.25 + l = []
1.26 + # Attribute reference.
1.27 + l.insert(0, node.name)
1.28 + l.insert(0, "/")
1.29 + node = node.parent
1.30 + # Element references.
1.31 + while node is not None and node.type != "document_xml":
1.32 + l.insert(0, str(int(node.xpathEval("count(preceding-sibling::*) + 1"))))
1.33 + l.insert(0, "#")
1.34 + l.insert(0, node.name)
1.35 + l.insert(0, "/")
1.36 + node = node.parent
1.37 + return "".join(l)
1.38 +
1.39 +def this_position(context):
1.40 +
1.41 + """
1.42 + As a libxslt extension function, return a string containing the XSLForms
1.43 + path to the 'context' node.
1.44 + """
1.45 +
1.46 + pctxt = libxslt.xpathParserContext(_obj=context)
1.47 + context = pctxt.context()
1.48 + node = context.contextNode()
1.49 + return path_to_node(node)
1.50 +
1.51 +libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
1.52 +
1.53 +# vim: tabstop=4 expandtab shiftwidth=4