XSLT script for cleaning up ECCO texts TEI P5 conversion
LicenseThis software is dual-licensed:
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
Unported License http://creativecommons.org/licenses/by-sa/3.0/
2. http://www.opensource.org/licenses/BSD-2-Clause
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This software is provided by the copyright holders and contributors
"as is" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall the copyright
holder or contributors be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not
limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any
theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
Milestones:
a) if there is no @n, just @unit == marginal note
b) if there is no @unit, just a @n, == marginal note, @type='milestone'
c) if @unit is from a closed list of words (page, line, folio), it
seems editorial, add as subtype on @note
d) otherwise, make a label from @unit + @n, and put in a
marginal note, @type='milestone'
Namespace
No namespace
Match
MILESTONE
Mode
#default
Import precedence
0
Source
<xsl:template match="MILESTONE"><xsl:choose><xsl:when test="parent::NOTE and not(@N)"/><xsl:when test="@UNIT and (not(@N) or @N='')"><note place="margin"><xsl:value-of select="@UNIT"/></note></xsl:when><xsl:when test="not(@UNIT) and @N"><note place="margin" type="milestone"><xsl:value-of select="@N"/></note></xsl:when><xsl:when test="@UNIT='unspec' and @N"><note place="margin" type="milestone"><xsl:value-of select="@N"/></note></xsl:when><!-- this short list seem like editorial words. are there more? --><xsl:when test=" @UNIT='article' or @UNIT='canon' or @UNIT='chapter' or @UNIT='commandment' or @UNIT='date' or @UNIT='day' or @UNIT='folio' or @UNIT='ground of' or @UNIT='indulgence' or @UNIT='leaf' or @UNIT='line' or @UNIT='monarch' or @UNIT='motive' or @UNIT='month' or @UNIT='reason' or @UNIT='verse' or @UNIT='year' "><note place="margin" type="milestone" subtype="{@UNIT}"><!--
<xsl:if test="$debug='true'">
<xsl:message>Milestone 1: <xsl:value-of
select="@UNIT"/>/<xsl:value-of select="@N"/></xsl:message>
</xsl:if>
--><xsl:value-of select="@N"/></note></xsl:when><xsl:when test="parent::SP"><p><label type="milestone"><xsl:value-of select="@UNIT"/><xsl:text></xsl:text><xsl:value-of select="@N"/></label></p></xsl:when><xsl:when test="parent::LIST or parent::SPEAKER"><note place="margin" type="milestone"><xsl:value-of select="@UNIT"/><xsl:text></xsl:text><xsl:value-of select="@N"/></note></xsl:when><xsl:otherwise><!--
<xsl:if test="$debug='true'">
<xsl:message>Milestone 2: <xsl:value-of
select="@UNIT"/><xsl:text> </xsl:text><xsl:value-of
select="@N"/></xsl:message>
</xsl:if>
--><label place="margin" type="milestone"><xsl:value-of select="@UNIT"/><xsl:text></xsl:text><xsl:value-of select="@N"/></label></xsl:otherwise></xsl:choose></xsl:template>
Template
HEADNOTE[P/FIGURE and not(following-sibling::HEAD or following-sibling::OPENER)]
Documentation
Description
the HEADNOTE element can be bypassed if it just has a figure
in, and no following head or opener
Namespace
No namespace
Match
HEADNOTE[P/FIGURE and not(following-sibling::HEAD or following-sibling::OPENER)]
Mode
#default
Import precedence
0
Source
<xsl:template match="HEADNOTE[P/FIGURE and not(following-sibling::HEAD or following-sibling::OPENER)]"><xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()"/></xsl:template>
@PLACE has both inconsistencies and mistakes; some values
should obviously be @n
Namespace
No namespace
Match
@PLACE
Mode
#default
Import precedence
0
Source
<xsl:template match="@PLACE"><xsl:choose><xsl:when test=".='marg' or .='marg;' or .='marg)' or .='marg=' or .='ma / rg' or .='6marg'"><xsl:attribute name="place">margin</xsl:attribute></xsl:when><xsl:when test=". = 'unspecified'"/><xsl:when test=".='foot;' or .='foor;' or .='foot'"><xsl:attribute name="place">bottom</xsl:attribute></xsl:when><xsl:when test=".='foot1' or .='foot2'"><xsl:attribute name="place">bottom</xsl:attribute><xsl:attribute name="type" select="."/></xsl:when><xsl:when test=".='inter'"><xsl:attribute name="rend" select="."/></xsl:when><xsl:when test=".='‡' or .='†' or .='‖' or .='6' or .='“' or .='1' or .='*'"><xsl:attribute name="n"><xsl:value-of select="."/></xsl:attribute></xsl:when><xsl:otherwise><xsl:attribute name="place"><xsl:value-of select="."/></xsl:attribute></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="@TYPE"><xsl:choose><xsl:when test=".='poem (rebus)'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">rebus</xsl:attribute></xsl:when><xsl:when test=".='poem(s)'"><xsl:attribute name="type">poems</xsl:attribute></xsl:when><xsl:when test=".='poem and response'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">response</xsl:attribute></xsl:when><xsl:when test=".='poem collection'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">collection</xsl:attribute></xsl:when><xsl:when test=".='poem fragment'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">fragment</xsl:attribute></xsl:when><xsl:when test=".='poem fragments'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">fragments</xsl:attribute></xsl:when><xsl:when test=".='poem from author to the reader'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">from_author_to_the_reader</xsl:attribute></xsl:when><xsl:when test=".='poem in honor of Gustavus'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">in_honor_of_Gustavus</xsl:attribute></xsl:when><xsl:when test=".='poem incorporating anagrams'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">incorporating_anagrams</xsl:attribute></xsl:when><xsl:when test=".='poem incorporating the Creed'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">incorporating_the_Creed</xsl:attribute></xsl:when><xsl:when test=".='poem on frontispiece'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">on_frontispiece</xsl:attribute></xsl:when><xsl:when test=".='poem on the seven virtues'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">on_the_seven_virtues</xsl:attribute></xsl:when><xsl:when test=".='poem to Archpapist'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_Archpapist</xsl:attribute></xsl:when><xsl:when test=".='poem to God from second edition'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_God_from_second_edition</xsl:attribute></xsl:when><xsl:when test=".='poem to author'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_author</xsl:attribute></xsl:when><xsl:when test=".='poem to book'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_book</xsl:attribute></xsl:when><xsl:when test=".='poem to king'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_king</xsl:attribute></xsl:when><xsl:when test=".='poem to pupils'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_pupils</xsl:attribute></xsl:when><xsl:when test=".='poem to readers'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_readers</xsl:attribute></xsl:when><xsl:when test=".='poem to subjects'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_subjects</xsl:attribute></xsl:when><xsl:when test=".='poem to the author'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_the_author</xsl:attribute></xsl:when><xsl:when test=".='poem to the censorious reader'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_the_censorious_reader</xsl:attribute></xsl:when><xsl:when test=".='poem to the censors'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_the_censors</xsl:attribute></xsl:when><xsl:when test=".='poem to the pious reader'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_the_pious_reader</xsl:attribute></xsl:when><xsl:when test=".='poem to the reader'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">to_the__reader</xsl:attribute></xsl:when><xsl:when test=".='poem with commentary'"><xsl:attribute name="type">poem</xsl:attribute><xsl:attribute name="subtype">commentary</xsl:attribute></xsl:when><xsl:when test=".='poem(s) by one author'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">by_one_author</xsl:attribute></xsl:when><xsl:when test=".='poems and commentary'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">commentary</xsl:attribute></xsl:when><xsl:when test=".='poems gratulatory'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">gratulatory</xsl:attribute></xsl:when><xsl:when test=".='poems of acknowledgment'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">acknowledgment</xsl:attribute></xsl:when><xsl:when test=".='poems on the Symbols'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">on_the_Symbols</xsl:attribute></xsl:when><xsl:when test=".='poems to the reader'"><xsl:attribute name="type">poems</xsl:attribute><xsl:attribute name="subtype">to_the_reader</xsl:attribute></xsl:when><xsl:when test="not(normalize-space(.)='')"><xsl:attribute name="type"><xsl:analyze-string regex="([0-9]+)(.*)" select="translate(translate(.,'( &/', '____'),$intype,'')"><xsl:matching-substring><xsl:text>n</xsl:text><xsl:value-of select="regex-group(1)"/><xsl:value-of select="regex-group(2)"/></xsl:matching-substring><xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring></xsl:analyze-string></xsl:attribute></xsl:when></xsl:choose></xsl:template>
You sometimes find a milestone inside a marginal note, where
the note has the same value for @type as the milestone has for unit.
Kill the @type on note in this situation.
Figures inside paragraphs can generally be free-standing,
unless they are the only paragraph of this type (ie inside a
div consisting only of pictures).
<xsl:template match="ENCODINGDESC/PROJECTDESC"><projectDesc><p>Created by converting TCP files to TEI P5 using tcp2tei.xsl,
TEI @ Oxford.
</p></projectDesc></xsl:template>
Template
tei:p[not(parent::tei:sp or parent::tei:headnote or parent::tei:postscript
or parent::tei:argument) and count(*)=1 and not(text()) and (tei:list or
tei:table)]
Documentation
Description
A p with list, floatingText or table as singletons can lose itself
Namespace
No namespace
Match
tei:p[not(parent::tei:sp or parent::tei:headnote or parent::tei:postscript
or parent::tei:argument) and count(*)=1 and not(text()) and (tei:list or
tei:table)]
Mode
#default
Import precedence
0
Source
<xsl:template match="tei:p[not(parent::tei:sp or parent::tei:headnote or parent::tei:postscript or parent::tei:argument) and count(*)=1 and not(text()) and (tei:list or tei:table)]"><xsl:apply-templates select="*|text()|processing-instruction()|comment()" mode="pass2"/></xsl:template>