1.1 --- a/XSLForms/Output.py Wed Dec 07 03:03:02 2005 +0000
1.2 +++ b/XSLForms/Output.py Wed Dec 07 03:03:27 2005 +0000
1.3 @@ -318,6 +318,53 @@
1.4
1.5 # Utility functions.
1.6
1.7 +def xslforms_range(context, range_spec):
1.8 +
1.9 + """
1.10 + Exposed as {template:range(range_spec)}.
1.11 +
1.12 + The 'range_spec' is split up into 'start', 'finish' and 'step' according to
1.13 + the following format:
1.14 +
1.15 + start...finish...step
1.16 +
1.17 + Provides the Python range function by producing a list of numbers, starting
1.18 + at 'start', ending one step before 'finish', and employing the optional
1.19 + 'step' to indicate the magnitude of the difference between successive
1.20 + elements in the list as well as the "direction" of the sequence. By default,
1.21 + 'step' is set to 1.
1.22 +
1.23 + NOTE: This uses a single string because template:element and other
1.24 + NOTE: annotations use commas to separate fields, thus making the usage of
1.25 + NOTE: this function impossible if each range parameter is exposed as a
1.26 + NOTE: function parameter.
1.27 + NOTE: The returning of values from this function is not fully verified, and
1.28 + NOTE: it is probably better to use other extension functions instead of this
1.29 + NOTE: one to achieve simple results (such as str:split from EXSLT).
1.30 + """
1.31 +
1.32 + parts = range_spec.split("...")
1.33 + start, finish = parts[:2]
1.34 + if len(parts) > 2:
1.35 + step = parts[2]
1.36 + else:
1.37 + step = None
1.38 +
1.39 + start = int(start)
1.40 + finish = int(finish)
1.41 + if step is not None:
1.42 + step = int(step)
1.43 + else:
1.44 + step = 1
1.45 +
1.46 + # Create a list of elements.
1.47 + # NOTE: libxslt complains: "Got a CObject"
1.48 +
1.49 + range_elements = libxml2mod.xmlXPathNewNodeSet(None)
1.50 + for i in range(start, finish, step):
1.51 + range_elements.append(libxml2mod.xmlNewText(str(i)))
1.52 + return range_elements
1.53 +
1.54 def i18n(context, value):
1.55
1.56 """
1.57 @@ -459,6 +506,7 @@
1.58
1.59 # Utility functions.
1.60
1.61 +libxsltmod.xsltRegisterExtModuleFunction("range", "http://www.boddie.org.uk/ns/xmltools/template", xslforms_range)
1.62 libxsltmod.xsltRegisterExtModuleFunction("i18n", "http://www.boddie.org.uk/ns/xmltools/template", i18n)
1.63 libxsltmod.xsltRegisterExtModuleFunction("choice", "http://www.boddie.org.uk/ns/xmltools/template", choice)
1.64 libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode)