Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resolve choice element
  • Loading branch information
kthoden committed Jul 19, 2019
1 parent eada4af commit 9a9df79
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tei2imxml.py
Expand Up @@ -422,6 +422,24 @@ def hi_lookup(hi_id):
return hi_code
# def hi_lookup ends here


def resolve_choice_to_expan(element_containing_choice, original_element):
"""Check whether an element contains choice and if so return expanded version."""

element_children = element_containing_choice.getchildren()
if element_children and element_children[0].tag == "{" + ns_tei + "}choice":
cleaned_element = element_children[0].find("t:expan", namespaces=NS_MAP)
cleaned_element.tag = original_element
element_containing_choice.insert(-1, cleaned_element)
element_containing_choice.tag = "tagtobestripped"
etree.strip_elements(element_containing_choice, "{%s}choice" % ns_tei)
else:
cleaned_element = element_containing_choice

return cleaned_element
# def resolve_choice_to_expan ends here


def transform_body(xml_tree, cited_data, translation_file, publang, hyperimage=False):
"""Transform the body of XML document into IntermediateXML file"""

Expand Down Expand Up @@ -470,7 +488,8 @@ def handle_refs_hyperimage(ref):
chapter.tag = "div1"
chapter.set("language", publang)

chapter_title = chapter.find("t:head", namespaces=NS_MAP)
chapter_title_element = chapter.find("t:head", namespaces=NS_MAP)
chapter_title = resolve_choice_to_expan(chapter_title_element, "head")

author_ids = chapter.get("resp")
if author_ids is not None:
Expand All @@ -483,7 +502,7 @@ def handle_refs_hyperimage(ref):
chapter_title.insert(0, eoa_author)
else:
logging.info("No chapter author.")
chapter.insert(0, chapter_title)
chapter.insert(0, chapter_title_element)

eoa_sections = xml_tree.xpath("//t:div[@type='section']", namespaces=NS_MAP)
for section in eoa_sections:
Expand Down

0 comments on commit 9a9df79

Please sign in to comment.