# HG changeset patch # User paulb # Date 1130430630 0 # Node ID f9e5276f49cc4a6859e54dca40c499718b7bf1a9 # Parent 5e8a468d568fe07129e0cf774fd266abe3e8bb5e [project @ 2005-10-27 16:30:30 by paulb] Reorganised the functions slightly. Added a schema generating function. diff -r 5e8a468d568f -r f9e5276f49cc XSLForms/Prepare.py --- a/XSLForms/Prepare.py Wed Oct 26 00:37:53 2005 +0000 +++ b/XSLForms/Prepare.py Thu Oct 27 16:30:30 2005 +0000 @@ -34,6 +34,12 @@ fn(template_name, output_name, *args, **kw) +def _make_document(input_name, output_name, stylesheet_names, encoding=None): + stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names] + proc = XSLOutput.Processor(stylesheets) + input = libxml2dom.parse(input_name) + proc.send_output(open(output_name, "wb"), encoding, input) + # Web template functions. def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding=None): @@ -43,10 +49,7 @@ 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) + _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): @@ -91,10 +94,7 @@ 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(input_name, "wb"), encoding, template) + _make_document(template_name, input_name, stylesheet_names, encoding) def ensure_input_stylesheet(template_name, input_name): @@ -106,6 +106,17 @@ _ensure_stylesheet(template_name, input_name, make_input_stylesheet) +# Schema-related functions. + +def make_schema(template_name, output_name, stylesheet_names=["Schema.xsl"], encoding=None): + + """ + Make a schema document using the file with the given 'template_name', + producing a file with the given 'output_name'. + """ + + _make_document(template_name, output_name, stylesheet_names, encoding) + # Qt Designer functions. def make_qt_fragment(template_name, output_name, widget_name, stylesheet_name="QtDesignerExtract.xsl", encoding=None):