TEI stylesheet for converting Word docx files to TEI
This 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
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.
<xsl:template match="tei:hi[tei:match(@rend,'footnote_reference') and count(*)=1 and tei:seg and normalize-space(.)='']" mode="pass2" priority="99"><xsl:text></xsl:text></xsl:template>
<xsl:template match="tei:hi[tei:match(@rend,'footnote_reference') and count(*)=1 and tei:note]" mode="pass2" priority="99"><xsl:apply-templates select="tei:note" mode="pass2"/></xsl:template>
<xsl:template match="tei:hi[(@rend or @style) and (* or text())]" mode="pass2"><xsl:variable name="r" select="concat(@rend,@style)"/><xsl:choose><xsl:when test="count(parent::tei:speaker/*)=1 and not (parent::tei:speaker/text())"><xsl:apply-templates/></xsl:when><xsl:when test="parent::tei:head and .=' '"/><xsl:when test="parent::tei:item/parent::tei:list[@type='gloss'] and tei:g[@ref='x:tab']"/><!--
The following when statements make sure that tei:hi with the same @rend and @style are merged
together. We assume that the first tei:hi with text data will be processed and will pull in
text data from immediately following tei:hi elements. Therefore, tei:hi elements with a preceding
tei:hi with the same @rend and @style will *not* be processed.
--><xsl:when test="preceding-sibling::node()[1][self::tei:hi[concat(@rend,@style)=$r][* or text()]]"/><xsl:when test="preceding-sibling::node()[1][self::tei:seg and .=' '] and preceding-sibling::node()[2][self::tei:hi[concat(@rend,@style)=$r]]"/><xsl:when test="($r='bold' or $r='italic') and .=' '"><xsl:text></xsl:text><xsl:if test="following-sibling::node()[1][self::tei:hi[concat(@rend,@style)=$r]]"><xsl:variable name="ename" select="tei:nameOutputElement(.)"/><xsl:element name="{$ename}"><xsl:copy-of select="@*[not(starts-with(.,'tei:'))]"/><xsl:call-template name="nextHi"><xsl:with-param name="r" select="$r"/></xsl:call-template></xsl:element></xsl:if></xsl:when><xsl:otherwise><xsl:variable name="ename" select="tei:nameOutputElement(.)"/><xsl:element name="{$ename}"><xsl:apply-templates mode="pass2" select="@*[not(starts-with(.,'tei:'))]"/><xsl:choose><xsl:when test="$ename='gap'"><desc><xsl:apply-templates mode="pass2"/><xsl:call-template name="nextHi"><xsl:with-param name="r" select="$r"/></xsl:call-template></desc></xsl:when><xsl:otherwise><xsl:apply-templates mode="pass2"/><xsl:call-template name="nextHi"><xsl:with-param name="r" select="$r"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:element></xsl:otherwise></xsl:choose></xsl:template>
<CAPTION> belongs to nearest figure or table. Tables with multi-paragraph preceding
CAPTIONs or with following captions are wrapped in a figure and the first para becomes
a <head>,
while subsequent ones become <figDescs>. A single preceding CAPTION paragraph becomes
an
internal header. Figure captions become headers and figDescs in a similar way.
Template
tei:div[count(parent::*/tei:div)=1 and not(tei:div) and tei:head[not(node())]]pass2
Documentation
Description
a singleton div with an empty head and no div children is bypassed
Namespace
No namespace
Match
tei:div[count(parent::*/tei:div)=1 and not(tei:div) and tei:head[not(node())]]
Mode
pass2
Import precedence
6
Source
<xsl:template match="tei:div[count(parent::*/tei:div)=1 and not(tei:div) and tei:head[not(node())]]" mode="pass2"><xsl:apply-templates select="*[not(self::tei:head)]" mode="pass2"/></xsl:template>