XSLTools

Changeset

420:4b1a998aa4d1
2005-11-28 paulb raw files shortlog changelog graph [project @ 2005-11-28 16:44:45 by paulb] Added choice extension function.
README.txt (file) XSLForms/Output.py (file)
     1.1 --- a/README.txt	Mon Nov 28 01:28:31 2005 +0000
     1.2 +++ b/README.txt	Mon Nov 28 16:44:46 2005 +0000
     1.3 @@ -64,7 +64,7 @@
     1.4    * Added set_document to XSLForms.Fields.Form.
     1.5    * Added prepare_parameters to the XSLFormsResource class in the
     1.6      XSLForms.Resources.WebResources module.
     1.7 -  * Added element-path and url-encode XSLForms extension functions.
     1.8 +  * Added element-path, url-encode and choice XSLForms extension functions.
     1.9    * Improved Unicode support in the XSLForms extension functions.
    1.10    * Changed in-page requests to contain proper POST data.
    1.11    * Updated the code to work with WebStack 1.0 changes and adopted the
     2.1 --- a/XSLForms/Output.py	Mon Nov 28 01:28:31 2005 +0000
     2.2 +++ b/XSLForms/Output.py	Mon Nov 28 16:44:46 2005 +0000
     2.3 @@ -316,6 +316,22 @@
     2.4  
     2.5  # Utility functions.
     2.6  
     2.7 +def choice(context, value, true_string, false_string=None):
     2.8 +
     2.9 +    """
    2.10 +    Exposed as {template:choice(value, true_string, false_string)}.
    2.11 +
    2.12 +    Using the given boolean 'value', which may itself be an expression evaluated
    2.13 +    by the XSLT processor, return the 'true_string' if 'value' is true or the
    2.14 +    'false_string' if 'value' is false. If 'false_string' is omitted and if
    2.15 +    'value' evaluates to a false value, an empty string is returned.
    2.16 +    """
    2.17 +
    2.18 +    if value:
    2.19 +        return true_string
    2.20 +    else:
    2.21 +        return false_string or ""
    2.22 +
    2.23  def url_encode(context, nodes, charset="utf-8"):
    2.24  
    2.25      """
    2.26 @@ -410,6 +426,7 @@
    2.27  
    2.28  # Utility functions.
    2.29  
    2.30 +libxsltmod.xsltRegisterExtModuleFunction("choice", "http://www.boddie.org.uk/ns/xmltools/template", choice)
    2.31  libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode)
    2.32  libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path)
    2.33