Skip to content

Commit

Permalink
Convert all n attributes to rend
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed May 27, 2020
1 parent 1077a40 commit 3c10d2f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/tei2imxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,15 @@ def resolve_choice_to_expan(element_containing_choice, original_element):
def transform_body(xml_tree, cited_data, translation_file, template_path, xml_hyperimagexml_code, olddesign, publang, temp_dir, output_dir, hyperimage=False):
"""Transform the body of XML document into IntermediateXML file"""

def convert_n_to_rend(div_element):
"""Convert n attribute to rend attribute"""

n_value = div_element.get("n")
if n_value == "nonumber":
div_element.set("rend", "nonumber")
# def convert_n_to_rend end here


def retain_original_contents(ref):
"""Store original contents in a separate element"""

Expand Down Expand Up @@ -796,9 +805,10 @@ def handle_refs_default(ref):
for chapter in eoa_chapters:
chapter.tag = "div1"
chapter.set("language", publang)
n_value = chapter.get("n")
if n_value == "nonumber":
chapter.set("rend", "nonumber")
convert_n_to_rend(chapter)
# n_value = chapter.get("n")
# if n_value == "nonumber":
# chapter.set("rend", "nonumber")
# del chapter.attrib["n"]

chapter_title_element = chapter.find("t:head", namespaces=NS_MAP)
Expand All @@ -820,6 +830,8 @@ def handle_refs_default(ref):
eoa_sections = xml_tree.xpath("//t:div[@type='section']", namespaces=NS_MAP)
for section in eoa_sections:
section.tag = "div2"
convert_n_to_rend(section)


eoa_milestones = xml_tree.xpath("//t:milestone[@type='divider']", namespaces=NS_MAP)
for milestone in eoa_milestones:
Expand All @@ -830,10 +842,12 @@ def handle_refs_default(ref):
eoa_subsections = xml_tree.xpath("//t:div[@type='subsection']", namespaces=NS_MAP)
for subsection in eoa_subsections:
subsection.tag = "div3"
convert_n_to_rend(subsection)

eoa_subsubsections = xml_tree.xpath("//t:div[@type='subsubsection']", namespaces=NS_MAP)
for subsubsection in eoa_subsubsections:
subsubsection.tag = "div4"
convert_n_to_rend(subsubsection)

##############
# Paragraphs #
Expand Down Expand Up @@ -1470,7 +1484,7 @@ def assign_ids(xml_tree, data, suppress_chapter_number):
def update_ids(xml_tree, ignore_ref_errors):
"""Update the references in EOAref to the id value assigned in assign_ids"""

xmlReferences = xml_tree.findall(".//EOAref")
xmlReferences = xml_tree.xpath(".//EOAref|.//EOApageref")
logging.debug("Found %d references", len(xmlReferences))

for xmlReference in xmlReferences:
Expand Down

0 comments on commit 3c10d2f

Please sign in to comment.