diff --git a/tei2imxml.py b/tei2imxml.py
index e7a7bf6..f9fa3f0 100644
--- a/tei2imxml.py
+++ b/tei2imxml.py
@@ -565,74 +565,52 @@ def transform_body(xml_tree, cited_data, publang):
##########
eoa_tables = xml_tree.xpath("//t:table", namespaces=NS_MAP)
-# turn
- #
- # This is a table
- #
- # Heading 1 |
- # Heading 2 |
- # Heading 3 |
- # Heading 4 |
- #
- #
- # Here |
- # you |
- # may |
- # find |
- #
- #
- # some |
- # data |
- # spread |
- # over |
- #
- #
- # the |
- # table |
- # in |
- # cells |
- #
- #
-
-# into
-
-#
-# sec3table1
-# This is a table
-# L2.3cmL2.3cmL2.3cmL2.3cm
-#
-#
-# TRUEHeading 1 |
-# Heading 2 |
-# Heading 3 |
-# Heading 4 |
-#
-#
-# Here |
-# you |
-# may |
-# find |
-#
-#
-# some |
-# data |
-# spread |
-# over |
-#
-#
-# the |
-# table |
-# in |
-# cells |
-#
-#
-#
-
for table in eoa_tables:
- table.tag = "EOAtable"
- table_id = (table.get("{http://www.w3.org/XML/1998/namespace}id"))
+ tablechildren = table.findall("t:row", namespaces=NS_MAP)
+ table_caption = table.find("t:head", namespaces=NS_MAP)
+ number_of_cells = len(table.findall("t:row[1]/t:cell", namespaces=NS_MAP))
+
+ if table_caption is not None:
+ # print(etree.tostring(table))
+ table_id = table.attrib["{http://www.w3.org/XML/1998/namespace}id"]
+ # table_id = table.get("{httbp://www.w3.org/XML/1998/namespace}id")
+ table.clear()
+ table_label = etree.Element("EOAtablelabel")
+ table_label.text = table_id
+ table.append(table_label)
+ table_caption.tag = "EOAtablecaption"
+ table.tag = "EOAtable"
+ else:
+ table.tag = "EOAtablenonumber"
+ table.clear()
+ # not sure if this is evaluated later.
+ table_label = etree.SubElement(table, "EOAtablecolumns").text = "L3cm" * number_of_cells
- table_label = etree.SubElement(table, "EOAtablelabel").text = table_id
+ if table_caption is not None:
+ table.insert(1, table_caption)
+ else:
+ pass
+
+ real_table_element = etree.SubElement(table, "table")
+ real_table_element.set("place", table_id)
+ real_table_element.set("rend", "display")
+ # how are those two constructed?
+ real_table_element.set("id-text", "1")
+ real_table_element.set("id", "uid38")
+
+ for row in tablechildren:
+ if row.get("role") == "label":
+ tableheader = etree.Element("tableheader")
+ tableheader.text = "TRUE"
+ # TRUE
+ row.insert(0, tableheader)
+ else:
+ pass
+ del row.attrib["role"]
+ cells = row.findall("t:cell", namespaces=NS_MAP)
+ for cell in cells:
+ del cell.attrib["role"]
+ real_table_element.append(row)
##############
# References #
@@ -747,6 +725,10 @@ def update_ids(xml_tree):
xmlReferences = xml_tree.findall(".//EOAref")
logging.debug("Found %d references", len(xmlReferences))
+ all_ids = xml_tree.xpath('//*[@xml:id]')
+ for xmlid in all_ids:
+ print(xmlid, "all ids")
+
for xmlReference in xmlReferences:
eoa_reference = xmlReference.find("ref")
@@ -759,8 +741,8 @@ def update_ids(xml_tree):
# else:
corresponding_eoa_id_element = xml_tree.xpath("//*[@xml:id='{}']".format(label_text))
logging.debug("The corresponding id element is %s", corresponding_eoa_id_element)
- # if len(corresponding_eoa_id_element) == 0:
- if corresponding_eoa_id_element is None:
+ # if corresponding_eoa_id_element is None:
+ if len(corresponding_eoa_id_element) == 0:
print("There seems to be no corresponding xml:id for %s. Exiting." % label_text)
sys.exit()
elif len(corresponding_eoa_id_element) > 1: