# HG changeset patch # User paulb # Date 1128469094 0 # Node ID e210db504cd4ee988fac3a7cf69d9c8768e4dd1d # Parent 3c59a15f1b64bf679a1d9e566a282d1a2672cce5 [project @ 2005-10-04 23:38:11 by paulb] Added expression parameter support. diff -r 3c59a15f1b64 -r e210db504cd4 XSLForms/Resources.py --- a/XSLForms/Resources.py Tue Oct 04 23:37:42 2005 +0000 +++ b/XSLForms/Resources.py Tue Oct 04 23:38:14 2005 +0000 @@ -141,14 +141,16 @@ XSLForms.Prepare.ensure_stylesheet_fragment(output_path, fragment_path, node_identifier) return fragment_path - def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, references=None): + def send_output(self, trans, stylesheet_filenames, document, stylesheet_parameters=None, + stylesheet_expressions=None, references=None): """ Send the output from the resource to the user employing the transaction 'trans', stylesheets having the given 'stylesheet_filenames', the 'document' upon which the output will be based, the optional parameters - as defined in the 'stylesheet_parameters' dictionary, and the optional - 'references' to external documents. + as defined in the 'stylesheet_parameters' dictionary, the optional + expressions are defined in the 'stylesheet_expressions' dictionary, and + the optional 'references' to external documents. """ # Sanity check for the filenames list. @@ -156,18 +158,21 @@ if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): raise ValueError, stylesheet_filenames - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references) + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, + expressions=stylesheet_expressions, references=references) proc.send_output(trans.get_response_stream(), trans.get_response_stream_encoding(), document) - def get_result(self, stylesheet_filenames, document, stylesheet_parameters=None, references=None): + def get_result(self, stylesheet_filenames, document, stylesheet_parameters=None, + stylesheet_expressions=None, references=None): """ Get the result of applying a transformation using stylesheets with the given 'stylesheet_filenames', the 'document' upon which the result will be based, the optional parameters as defined in the - 'stylesheet_parameters' dictionary, and the optional 'references' to - external documents. + 'stylesheet_parameters' dictionary, the optional parameters as defined + in the 'stylesheet_parameters' dictionaryand the optional 'references' + to external documents. """ # Sanity check for the filenames list. @@ -175,7 +180,8 @@ if isinstance(stylesheet_filenames, str) or isinstance(stylesheet_filenames, unicode): raise ValueError, stylesheet_filenames - proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references) + proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, + expressions=stylesheet_expressions, references=references) return proc.get_result(document) def prepare_initialiser(self, input_identifier): diff -r 3c59a15f1b64 -r e210db504cd4 XSLTools/XSLOutput.py --- a/XSLTools/XSLOutput.py Tue Oct 04 23:37:42 2005 +0000 +++ b/XSLTools/XSLOutput.py Tue Oct 04 23:38:14 2005 +0000 @@ -35,16 +35,20 @@ A handler which can prepare output for an XMLTools2 template. """ - def __init__(self, filenames, references=None, parameters=None): + def __init__(self, filenames, references=None, parameters=None, expressions=None): """ Initialise the handler with the 'filenames' of stylesheets producing the final output, a 'references' dictionary indicating related stylesheets. - Additional 'parameters' may also be specified as a dictionary. + Additional 'parameters' may be specified as a dictionary whose values + are converted to string values; additional 'expressions' may also be + specified as a dictionary - such expressions are actually evaluated in + stylesheet. """ self.references = references or {} self.parameters = parameters or {} + self.expressions = expressions or {} # Remember the stylesheet documents. @@ -88,6 +92,7 @@ # Attempt to get the correctly formatted document. if hasattr(stream, "fileno"): + stream.flush() fd = stream.fileno() str_result = libxsltmod.xsltSaveResultToFd(fd, result, self.stylesheets[-1]) else: @@ -129,7 +134,8 @@ parameters[name.encode("utf-8")] = ("document('%s')" % self._quote(reference)).encode("utf-8") for name, parameter in self.parameters.items(): parameters[name.encode("utf-8")] = ("'%s'" % self._quote(parameter)).encode("utf-8") - #print "**", repr(parameters) + for name, parameter in self.expressions.items(): + parameters[name.encode("utf-8")] = self._quote(parameter).encode("utf-8") last_result = document for stylesheet in self.stylesheets: