1.1 --- a/XSLForms/Prepare.py Mon Oct 31 23:54:45 2005 +0000
1.2 +++ b/XSLForms/Prepare.py Mon Oct 31 23:55:38 2005 +0000
1.3 @@ -34,9 +34,9 @@
1.4
1.5 fn(template_name, output_name, *args, **kw)
1.6
1.7 -def _make_document(input_name, output_name, stylesheet_names, encoding=None):
1.8 +def _make_document(input_name, output_name, stylesheet_names, encoding=None, parameters=None):
1.9 stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names]
1.10 - proc = XSLOutput.Processor(stylesheets)
1.11 + proc = XSLOutput.Processor(stylesheets, parameters=parameters or {})
1.12 input = libxml2dom.parse(input_name)
1.13 proc.send_output(open(output_name, "wb"), encoding, input)
1.14
1.15 @@ -51,7 +51,7 @@
1.16
1.17 _make_document(template_name, output_name, stylesheet_names, encoding)
1.18
1.19 -def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding=None):
1.20 +def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_names=["Extract.xsl"], encoding=None):
1.21
1.22 """
1.23 Make an output stylesheet using the file with the given 'template_name',
1.24 @@ -59,9 +59,7 @@
1.25 identified by the given 'element_id'.
1.26 """
1.27
1.28 - proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"element-id" : element_id})
1.29 - template = libxml2dom.parse(template_name)
1.30 - proc.send_output(open(output_name, "wb"), encoding, template)
1.31 + _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"element-id" : element_id})
1.32
1.33 def ensure_stylesheet(template_name, output_name):
1.34
1.35 @@ -86,25 +84,35 @@
1.36
1.37 # Document initialisation functions.
1.38
1.39 -def make_input_stylesheet(template_name, input_name, stylesheet_names=["Schema.xsl", "Input.xsl"], encoding=None):
1.40 +def make_input_stylesheet(template_name, input_name, init_enumerations=1, stylesheet_names=["Schema.xsl", "Input.xsl"], encoding=None):
1.41
1.42 """
1.43 Make an input stylesheet using the file with the given 'template_name',
1.44 producing a file with the given 'input_name'. Such stylesheets are used to
1.45 ensure the general structure of an input document.
1.46 +
1.47 + The optional 'init_enumerations' (defaulting to true) may be used to
1.48 + indicate whether enumerations are to be initialised from external documents.
1.49 """
1.50
1.51 - _make_document(template_name, input_name, stylesheet_names, encoding)
1.52 + if init_enumerations:
1.53 + init_enumerations_str = "yes"
1.54 + else:
1.55 + init_enumerations_str = "no"
1.56 + _make_document(template_name, input_name, stylesheet_names, encoding, parameters={"init-enumerations" : init_enumerations_str})
1.57
1.58 -def ensure_input_stylesheet(template_name, input_name):
1.59 +def ensure_input_stylesheet(template_name, input_name, init_enumerations=1):
1.60
1.61 """
1.62 Ensure the presence of an input stylesheet, preparing it if necessary
1.63 using the file with the given 'template_name', producing a file with the
1.64 given 'input_name'.
1.65 +
1.66 + The optional 'init_enumerations' (defaulting to true) may be used to
1.67 + indicate whether enumerations are to be initialised from external documents.
1.68 """
1.69
1.70 - _ensure_stylesheet(template_name, input_name, make_input_stylesheet)
1.71 + _ensure_stylesheet(template_name, input_name, make_input_stylesheet, init_enumerations)
1.72
1.73 # Schema-related functions.
1.74
1.75 @@ -119,10 +127,8 @@
1.76
1.77 # Qt Designer functions.
1.78
1.79 -def make_qt_fragment(template_name, output_name, widget_name, stylesheet_name="QtDesignerExtract.xsl", encoding=None):
1.80 - proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"widget-name" : widget_name})
1.81 - template = libxml2dom.parse(template_name)
1.82 - proc.send_output(open(output_name, "wb"), encoding, template)
1.83 +def make_qt_fragment(template_name, output_name, widget_name, stylesheet_names=["QtDesignerExtract.xsl"], encoding=None):
1.84 + _make_document(template_name, output_name, stylesheet_names, encoding, parameters={"widget-name" : widget_name})
1.85
1.86 def ensure_qt_fragment(template_name, output_name, widget_name):
1.87 _ensure_stylesheet(template_name, output_name, make_qt_fragment, widget_name)