# HG changeset patch # User paulb # Date 1128215402 0 # Node ID e80fa9008246d83426d2f9480a05489d8207e8ba # Parent 00428442ed0368e4a4ec2b369f5c2de2f7f9be66 [project @ 2005-10-02 01:10:02 by paulb] Removed redundant comment from Output. Added preparation of input stylesheets; changed default encoding from UTF-8 to None; added docstrings to Prepare. diff -r 00428442ed03 -r e80fa9008246 XSLForms/Output.py --- a/XSLForms/Output.py Sun Oct 02 01:08:34 2005 +0000 +++ b/XSLForms/Output.py Sun Oct 02 01:10:02 2005 +0000 @@ -25,15 +25,6 @@ import libxml2dom import urllib -""" -import libxml2 - -def quiet(context, s): - pass - -libxml2.registerErrorHandler(quiet, None) -""" - def path_to_node(node, attribute_ref, name, multivalue=0): """ diff -r 00428442ed03 -r e80fa9008246 XSLForms/Prepare.py --- a/XSLForms/Prepare.py Sun Oct 02 01:08:34 2005 +0000 +++ b/XSLForms/Prepare.py Sun Oct 02 01:10:02 2005 +0000 @@ -26,27 +26,68 @@ resource_dir = os.path.join(os.path.split(__file__)[0], "XSL") -def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding="utf-8"): +def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding=None): + + """ + Make an output stylesheet using the file with the given 'template_name', + producing a file with the given 'output_name'. + """ + stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names] proc = XSLOutput.Processor(stylesheets) template = libxml2dom.parse(template_name) proc.send_output(open(output_name, "wb"), encoding, template) -def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding="utf-8"): +def make_stylesheet_fragment(template_name, output_name, element_id, stylesheet_name="Extract.xsl", encoding=None): + + """ + Make an output stylesheet using the file with the given 'template_name', + producing a file with the given 'output_name', capturing the fragment + 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) def ensure_stylesheet(template_name, output_name): + + """ + Ensure the presence of an output stylesheet, preparing it if necessary + using the file with the given 'template_name', producing a file with the + given 'output_name'. + """ + if not os.path.exists(output_name) or \ os.path.getmtime(output_name) < os.path.getmtime(template_name): make_stylesheet(template_name, output_name) def ensure_stylesheet_fragment(template_name, output_name, element_id): + + """ + Ensure the presence of an output stylesheet, preparing it if necessary + using the file with the given 'template_name', producing a file with the + given 'output_name', capturing the fragment identified by the given + 'element_id'. + """ + if not os.path.exists(output_name) or \ os.path.getmtime(output_name) < os.path.getmtime(template_name): make_stylesheet_fragment(template_name, output_name, element_id) +def make_input_stylesheet(template_name, output_name, 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 'output_name'. Such stylesheets are used to + ensure the general structure of an input document. + """ + + stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names] + proc = XSLOutput.Processor(stylesheets) + template = libxml2dom.parse(template_name) + proc.send_output(open(output_name, "wb"), encoding, template) + # vim: tabstop=4 expandtab shiftwidth=4