# HG changeset patch # User paulb # Date 1130802938 0 # Node ID d5323c740aab8297caf1251dccc91fd09338c6af # Parent 5a34b5514b6a80326568b357bae39f7667f41541 [project @ 2005-10-31 23:55:38 by paulb] Added an option to suppress input stylesheet enumeration initialisation. Tidied various functions so that those using parameters can call _make_document. diff -r 5a34b5514b6a -r d5323c740aab XSLForms/Prepare.py --- a/XSLForms/Prepare.py Mon Oct 31 23:54:45 2005 +0000 +++ b/XSLForms/Prepare.py Mon Oct 31 23:55:38 2005 +0000 @@ -34,9 +34,9 @@ fn(template_name, output_name, *args, **kw) -def _make_document(input_name, output_name, stylesheet_names, encoding=None): +def _make_document(input_name, output_name, stylesheet_names, encoding=None, parameters=None): stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names] - proc = XSLOutput.Processor(stylesheets) + proc = XSLOutput.Processor(stylesheets, parameters=parameters or {}) input = libxml2dom.parse(input_name) proc.send_output(open(output_name, "wb"), encoding, input) @@ -51,7 +51,7 @@ _make_document(template_name, output_name, stylesheet_names, encoding) -def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding=None): +def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_names=["Extract.xsl"], encoding=None): """ Make an output stylesheet using the file with the given 'template_name', @@ -59,9 +59,7 @@ identified by the given 'element_id'. """ - proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"element-id" : element_id}) - template = libxml2dom.parse(template_name) - proc.send_output(open(output_name, "wb"), encoding, template) + _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"element-id" : element_id}) def ensure_stylesheet(template_name, output_name): @@ -86,25 +84,35 @@ # Document initialisation functions. -def make_input_stylesheet(template_name, input_name, stylesheet_names=["Schema.xsl", "Input.xsl"], encoding=None): +def make_input_stylesheet(template_name, input_name, init_enumerations=1, stylesheet_names=["Schema.xsl", "Input.xsl"], encoding=None): """ Make an input stylesheet using the file with the given 'template_name', producing a file with the given 'input_name'. Such stylesheets are used to ensure the general structure of an input document. + + The optional 'init_enumerations' (defaulting to true) may be used to + indicate whether enumerations are to be initialised from external documents. """ - _make_document(template_name, input_name, stylesheet_names, encoding) + if init_enumerations: + init_enumerations_str = "yes" + else: + init_enumerations_str = "no" + _make_document(template_name, input_name, stylesheet_names, encoding, parameters={"init-enumerations" : init_enumerations_str}) -def ensure_input_stylesheet(template_name, input_name): +def ensure_input_stylesheet(template_name, input_name, init_enumerations=1): """ Ensure the presence of an input stylesheet, preparing it if necessary using the file with the given 'template_name', producing a file with the given 'input_name'. + + The optional 'init_enumerations' (defaulting to true) may be used to + indicate whether enumerations are to be initialised from external documents. """ - _ensure_stylesheet(template_name, input_name, make_input_stylesheet) + _ensure_stylesheet(template_name, input_name, make_input_stylesheet, init_enumerations) # Schema-related functions. @@ -119,10 +127,8 @@ # Qt Designer functions. -def make_qt_fragment(template_name, output_name, widget_name, stylesheet_name="QtDesignerExtract.xsl", encoding=None): - proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"widget-name" : widget_name}) - template = libxml2dom.parse(template_name) - proc.send_output(open(output_name, "wb"), encoding, template) +def make_qt_fragment(template_name, output_name, widget_name, stylesheet_names=["QtDesignerExtract.xsl"], encoding=None): + _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"widget-name" : widget_name}) def ensure_qt_fragment(template_name, output_name, widget_name): _ensure_stylesheet(template_name, output_name, make_qt_fragment, widget_name)