Permalink
Browse files

Merge TEI2EOADjango

  • Loading branch information...
kthoden committed Mar 8, 2018
2 parents 429b619 + e2b1b6c commit cc2f136e64ceaa638ed314dd2219788d7663757a
@@ -1,6 +1,10 @@
output
examples

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
@@ -42,13 +46,22 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
@@ -58,3 +71,25 @@ target/

# Macos turds
.DS_Store

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Max Planck Institute for the History of Science
Copyright (c) 2016-2018 Max Planck Institute for the History of Science

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -31,7 +31,7 @@ you the PDF version of the document.

Next, comment line 9 in `EOASample.tex` (the EOA preambel) and
uncomment line 10 (the XML preambel) and run the older version of
biber (biber v2.1).
biber (biber v2.1).

biber_2.1 EOASample

@@ -48,5 +48,15 @@ If everything went well, you can also try and run
These scripts don't take any arguments and will produce output in the
`CONVERT` directory.

# Convert TEI to EOADjango #

Suite of functions to get from TEI encoded XML into the workflow of Edition Open Access. The main output file is an XML file called `IntermediateXML.xml` which can subsequently processed with `tralics2django`, a tool found in the `EOASkripts` repository.

Code written in Python3.

External dependencies
---------------------
- lxml
- BeautifulSoup
- pandoc
- pandoc-citeproc

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +657 KB data/images/0002.jpg
Binary file not shown.
BIN +2.11 MB data/images/002.jpg
Binary file not shown.
BIN +471 KB data/images/1.jpg
Binary file not shown.
BIN +471 KB data/images/1_rot.jpg
Binary file not shown.
BIN +9.48 KB data/inline/A.jpg
Binary file not shown.
@@ -0,0 +1,274 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
version="1.0"
exclude-result-prefixes="tei cc rdf"
>
<!--
things missing:
- EOAparthtml
- numbering and ordering
- footnotes have a sup above and are gathered below
-
-->

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:template match="/">
<xsl:element name="EOAdocument">
<xsl:apply-templates select="//tei:div[@type='chapter']"/>
</xsl:element>
</xsl:template>

<!--
<div type="part" n="1" xml:id="part1">
<head>This is the first part</head>
-->

<xsl:template match="//tei:div[@type='part']/tei:head">
<xsl:element name="EOAparthtml">
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter'][not(@rend='nonumber')]">
<xsl:element name="EOAchapter">
<xsl:attribute name="language">
<xsl:value-of select="//tei:langUsage/tei:language/@ident"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:apply-templates/>
<xsl:element name="EOAsection">
<xsl:element name="head">
<xsl:text>Footnotes</xsl:text>
</xsl:element>
</xsl:element>
<xsl:apply-templates select="//tei:note[@place='bottom']"/>
<xsl:element name="EOAfootnote">
<xsl:attribute name="anchor">
<xsl:value-of select="tei:note/@n"/>
</xsl:attribute>
<xsl:value-of select="tei:note[@place='bottom']/tei:p"/>
<!-- </xsl:template> -->
</xsl:element>

</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter'][@rend='nonumber']">
<xsl:element name="EOAchapter">
<xsl:attribute name="language">
<xsl:value-of select="//tei:langUsage/tei:language/@ident"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='section'][not(@rend='nonumber')]/tei:head">
<xsl:element name="EOAsection">
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='section'][@rend='nonumber']/tei:head">
<xsl:element name="EOAsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsection'][not(@rend='nonumber')]/tei:head">
<xsl:element name="EOAsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:attribute name="number">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsection'][@rend='nonumber']/tei:head">
<xsl:element name="EOAsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='subsubsection']/tei:head">
<xsl:element name="EOAsubsubsection">
<xsl:attribute name="order">
<xsl:value-of select="@n"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="//tei:div[@type='chapter']/tei:head">
<xsl:element name="head">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:p">
<xsl:element name="EOAparagraph">
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<!-- <xsl:value-of select="."/> -->
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:p[@rend='Quote']">
<xsl:element name="EOAparagraph">
<xsl:attribute name="order">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:attribute name="rend">
<xsl:text>quoted</xsl:text>
</xsl:attribute>
<!-- <xsl:value-of select="."/> -->
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<!--
<span rel="popover" class="citation" data-toggle="popover" html="true" data-placement="bottom" data-title="Descartes 1644, 37–44" data-content="Principia philosophiae.">Descartes 1644, 37–44</span>
-->

<xsl:template match="tei:bibl/tei:abbr[@type='authoryear']">
<xsl:element name="span">
<xsl:attribute name="rel">
<xsl:text>popover</xsl:text>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>citation</xsl:text>
</xsl:attribute>
<xsl:attribute name="data-toggle">
<xsl:text>popover</xsl:text>
</xsl:attribute>
<xsl:attribute name="html">
<xsl:text>true</xsl:text>
</xsl:attribute>
<xsl:attribute name="citekey">
<xsl:value-of select="substring-after(../tei:ref/@target, '#')"/>
</xsl:attribute>
<xsl:attribute name="data-placement">
<xsl:text>bottom</xsl:text>
</xsl:attribute>
<xsl:attribute name="data-title">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:attribute name="data-content">
<xsl:value-of select="../tei:abbr[@type='title']"/>
<!-- <xsl:text>Here goes the title of the publication</xsl:text> -->
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:figure">
<xsl:element name="EOAfigure">
<xsl:attribute name="file">
<xsl:value-of select="tei:graphic/@url"/>
</xsl:attribute>
<!-- <xsl:apply-templates/> -->
<xsl:element name="caption">
<xsl:value-of select="tei:head/text()"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- <EOAfigure file="images1.jpg" width="66px;" order="8" number="4.1"><caption>An image with a caption. It resembles a bird looking at you. Doesn't it? And do you think it looks angry?</caption></EOAfigure> -->

<xsl:template match="tei:note[@place='bottom']/tei:p">
<xsl:element name="sup">
<xsl:attribute name="class">
<xsl:text>footnote</xsl:text>
</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="concat('#fn', ../@n)"/>
</xsl:attribute>
<xsl:value-of select="../@n"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- <sup class="footnote"><a href="#fn1">1</a></sup> -->

<!--
<xsl:template match="tei:note[@place='bottom']/tei:p">
<xsl:element name="EOAfootnote">
<xsl:attribute name="anchor">
<xsl:value-of select="../@n"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
-->

<xsl:template match="tei:hi[@rend='italic']">
<xsl:element name="em">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:hi[@rend='sup']">
<xsl:element name="sup">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="tei:hi[@rend='sub']">
<xsl:element name="sub">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!--
<xsl:template match="tei:hi[@rend='math']">
<xsl:element name="em">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
-->
<xsl:template match="tei:hi[@rend='bold']">
<xsl:element name="b">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>


</xsl:stylesheet>
Oops, something went wrong.

0 comments on commit cc2f136

Please sign in to comment.