diff --git a/tei2imxml.py b/tei2imxml.py index ada4d85..462ded1 100644 --- a/tei2imxml.py +++ b/tei2imxml.py @@ -962,25 +962,17 @@ def main(): # print(cited_dict) tei_body = xml_tree.xpath("//t:body", namespaces=NS_MAP)[0] - - body_transformed = transform_body(tei_body, cited_dict, publang=publication_language) - - resulting_tree = etree.ElementTree(body_transformed) - - tmp_output_filename = TMP_DIR + os.path.sep + "after_transformation.xml" - - # resulting_tree.write(output_filename, pretty_print=True, xml_declaration=True,encoding="utf-8") - resulting_tree.write(tmp_output_filename, pretty_print=True, xml_declaration=True, encoding="utf-8") - logging.info("Wrote %s for debugging purposes." % tmp_output_filename) + body_transformed_tmp = transform_body(tei_body, cited_dict, publang=publication_language) + libeoaconvert.debug_xml_here(body_transformed_tmp, "body_transformed") + body_transformed = etree.ElementTree(body_transformed_tmp) if bib_data["type"] == "monograph": - xml_add_bib = add_bibliography_monograph(resulting_tree, refs_for_bib_chapter) + xml_add_bib = add_bibliography_monograph(body_transformed, refs_for_bib_chapter) elif bib_data["type"] == "anthology": - xml_add_bib = add_bibliography_anthology(resulting_tree, formatted_references_dict) - - # xml_add_bib = add_bibliography(resulting_tree, refs_for_bib_chapter) + xml_add_bib = add_bibliography_anthology(body_transformed, formatted_references_dict) etree.strip_tags(xml_add_bib, "tagtobestripped") + libeoaconvert.debug_xml_here(xml_add_bib, "xml_add_bib") elements_with_ids = xml_add_bib.xpath("//div1 | //div2 | //div3 | //note | //item | //table | //EOAfigure/anchor | //EOAequation | //formula | //theorem") element_counter = 1 @@ -988,11 +980,12 @@ def main(): element.set("id", "uid" + str(element_counter)) element_counter += 1 - assigned_ids, data_to_pickle = assign_ids(resulting_tree, data) + assigned_ids, data_to_pickle = assign_ids(xml_add_bib, data) updated_xml_tree = update_ids(assigned_ids) - - xml_root = updated_xml_tree.getroot() + # libeoaconvert.debug_xml_here(updated_xml_tree, "updated_tree") + nearly_final_tree = etree.ElementTree(updated_xml_tree) + xml_root = nearly_final_tree.getroot() xml_root.tag = "Book" @@ -1019,7 +1012,6 @@ def main(): os.mkdir(os.path.expanduser(TMP_DIR)) output_filename = TMP_DIR + os.path.sep + "IntermediateXMLFile.xml" - # resulting_tree.write(output_filename, pretty_print=True, xml_declaration=True,encoding="utf-8") final_tree.write(output_filename, pretty_print=True, xml_declaration=True, encoding="utf-8") logging.info("Wrote %s." % output_filename)