1.1 --- a/XSLForms/Prepare.py Sun Oct 02 01:20:06 2005 +0000
1.2 +++ b/XSLForms/Prepare.py Sun Oct 02 01:33:47 2005 +0000
1.3 @@ -77,17 +77,30 @@
1.4
1.5 make_stylesheet_fragment(template_name, output_name, element_id)
1.6
1.7 -def make_input_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None):
1.8 +def make_input_stylesheet(template_name, input_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None):
1.9
1.10 """
1.11 Make an input stylesheet using the file with the given 'template_name',
1.12 - producing a file with the given 'output_name'. Such stylesheets are used to
1.13 + producing a file with the given 'input_name'. Such stylesheets are used to
1.14 ensure the general structure of an input document.
1.15 """
1.16
1.17 stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names]
1.18 proc = XSLOutput.Processor(stylesheets)
1.19 template = libxml2dom.parse(template_name)
1.20 - proc.send_output(open(output_name, "wb"), encoding, template)
1.21 + proc.send_output(open(input_name, "wb"), encoding, template)
1.22 +
1.23 +def ensure_input_stylesheet(template_name, input_name):
1.24 +
1.25 + """
1.26 + Ensure the presence of an input stylesheet, preparing it if necessary
1.27 + using the file with the given 'template_name', producing a file with the
1.28 + given 'input_name'.
1.29 + """
1.30 +
1.31 + if not os.path.exists(input_name) or \
1.32 + os.path.getmtime(input_name) < os.path.getmtime(template_name):
1.33 +
1.34 + make_input_stylesheet(template_name, input_name)
1.35
1.36 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/XSLForms/Resources.py Sun Oct 02 01:20:06 2005 +0000
2.2 +++ b/XSLForms/Resources.py Sun Oct 02 01:33:47 2005 +0000
2.3 @@ -47,6 +47,12 @@
2.4 mark a region of those documents as the fragment
2.5 to be updated upon "in-page" requests
2.6
2.7 + * init_resources - a dictionary mapping initialiser/input
2.8 + identifiers to (template_filename,
2.9 + input_filename) tuples, indicating the template
2.10 + and initialiser/input stylesheet filenames to be
2.11 + employed
2.12 +
2.13 * transform_resources - a dictionary mapping transform identifiers to
2.14 lists of stylesheet filenames for use with the
2.15 transformation methods
2.16 @@ -162,6 +168,22 @@
2.17 proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references)
2.18 return proc.get_result(document)
2.19
2.20 + def prepare_initialiser(self, input_identifier):
2.21 +
2.22 + """
2.23 + Prepare an initialiser/input transformation using the given
2.24 + 'input_identifier'.
2.25 +
2.26 + Return the full path to the input stylesheet for use with 'send_output'
2.27 + or 'get_result'.
2.28 + """
2.29 +
2.30 + template_filename, input_filename = self.init_resources[input_identifier]
2.31 + input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename))
2.32 + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
2.33 + XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path)
2.34 + return input_path
2.35 +
2.36 def prepare_transform(self, transform_identifier):
2.37
2.38 """