1.1 --- a/XSLForms/Output.py Sun Oct 02 01:08:34 2005 +0000
1.2 +++ b/XSLForms/Output.py Sun Oct 02 01:10:02 2005 +0000
1.3 @@ -25,15 +25,6 @@
1.4 import libxml2dom
1.5 import urllib
1.6
1.7 -"""
1.8 -import libxml2
1.9 -
1.10 -def quiet(context, s):
1.11 - pass
1.12 -
1.13 -libxml2.registerErrorHandler(quiet, None)
1.14 -"""
1.15 -
1.16 def path_to_node(node, attribute_ref, name, multivalue=0):
1.17
1.18 """
2.1 --- a/XSLForms/Prepare.py Sun Oct 02 01:08:34 2005 +0000
2.2 +++ b/XSLForms/Prepare.py Sun Oct 02 01:10:02 2005 +0000
2.3 @@ -26,27 +26,68 @@
2.4
2.5 resource_dir = os.path.join(os.path.split(__file__)[0], "XSL")
2.6
2.7 -def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding="utf-8"):
2.8 +def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding=None):
2.9 +
2.10 + """
2.11 + Make an output stylesheet using the file with the given 'template_name',
2.12 + producing a file with the given 'output_name'.
2.13 + """
2.14 +
2.15 stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names]
2.16 proc = XSLOutput.Processor(stylesheets)
2.17 template = libxml2dom.parse(template_name)
2.18 proc.send_output(open(output_name, "wb"), encoding, template)
2.19
2.20 -def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding="utf-8"):
2.21 +def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding=None):
2.22 +
2.23 + """
2.24 + Make an output stylesheet using the file with the given 'template_name',
2.25 + producing a file with the given 'output_name', capturing the fragment
2.26 + identified by the given 'element_id'.
2.27 + """
2.28 +
2.29 proc = XSLOutput.Processor([os.path.join(resource_dir, stylesheet_name)], parameters={"element-id" : element_id})
2.30 template = libxml2dom.parse(template_name)
2.31 proc.send_output(open(output_name, "wb"), encoding, template)
2.32
2.33 def ensure_stylesheet(template_name, output_name):
2.34 +
2.35 + """
2.36 + Ensure the presence of an output stylesheet, preparing it if necessary
2.37 + using the file with the given 'template_name', producing a file with the
2.38 + given 'output_name'.
2.39 + """
2.40 +
2.41 if not os.path.exists(output_name) or \
2.42 os.path.getmtime(output_name) < os.path.getmtime(template_name):
2.43
2.44 make_stylesheet(template_name, output_name)
2.45
2.46 def ensure_stylesheet_fragment(template_name, output_name, element_id):
2.47 +
2.48 + """
2.49 + Ensure the presence of an output stylesheet, preparing it if necessary
2.50 + using the file with the given 'template_name', producing a file with the
2.51 + given 'output_name', capturing the fragment identified by the given
2.52 + 'element_id'.
2.53 + """
2.54 +
2.55 if not os.path.exists(output_name) or \
2.56 os.path.getmtime(output_name) < os.path.getmtime(template_name):
2.57
2.58 make_stylesheet_fragment(template_name, output_name, element_id)
2.59
2.60 +def make_input_stylesheet(template_name, output_name, stylesheet_names=["Schema.xsl", "Input.xsl"], encoding=None):
2.61 +
2.62 + """
2.63 + Make an input stylesheet using the file with the given 'template_name',
2.64 + producing a file with the given 'output_name'. Such stylesheets are used to
2.65 + ensure the general structure of an input document.
2.66 + """
2.67 +
2.68 + stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names]
2.69 + proc = XSLOutput.Processor(stylesheets)
2.70 + template = libxml2dom.parse(template_name)
2.71 + proc.send_output(open(output_name, "wb"), encoding, template)
2.72 +
2.73 # vim: tabstop=4 expandtab shiftwidth=4