# HG changeset patch # User paulb # Date 1133196286 0 # Node ID 4b1a998aa4d10e9164fe6a266c4ab64a6a1ba7d2 # Parent 9062d0ca60ca99243fc2b60418d1c24848d987d5 [project @ 2005-11-28 16:44:45 by paulb] Added choice extension function. diff -r 9062d0ca60ca -r 4b1a998aa4d1 README.txt --- a/README.txt Mon Nov 28 01:28:31 2005 +0000 +++ b/README.txt Mon Nov 28 16:44:46 2005 +0000 @@ -64,7 +64,7 @@ * Added set_document to XSLForms.Fields.Form. * Added prepare_parameters to the XSLFormsResource class in the XSLForms.Resources.WebResources module. - * Added element-path and url-encode XSLForms extension functions. + * Added element-path, url-encode and choice XSLForms extension functions. * Improved Unicode support in the XSLForms extension functions. * Changed in-page requests to contain proper POST data. * Updated the code to work with WebStack 1.0 changes and adopted the diff -r 9062d0ca60ca -r 4b1a998aa4d1 XSLForms/Output.py --- a/XSLForms/Output.py Mon Nov 28 01:28:31 2005 +0000 +++ b/XSLForms/Output.py Mon Nov 28 16:44:46 2005 +0000 @@ -316,6 +316,22 @@ # Utility functions. +def choice(context, value, true_string, false_string=None): + + """ + Exposed as {template:choice(value, true_string, false_string)}. + + Using the given boolean 'value', which may itself be an expression evaluated + by the XSLT processor, return the 'true_string' if 'value' is true or the + 'false_string' if 'value' is false. If 'false_string' is omitted and if + 'value' evaluates to a false value, an empty string is returned. + """ + + if value: + return true_string + else: + return false_string or "" + def url_encode(context, nodes, charset="utf-8"): """ @@ -410,6 +426,7 @@ # Utility functions. +libxsltmod.xsltRegisterExtModuleFunction("choice", "http://www.boddie.org.uk/ns/xmltools/template", choice) libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode) libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path)