<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [
	<!ENTITY newline  "<xsl:text>&#x0A;</xsl:text>" >
]>
<xsl:stylesheet 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:t="http://www.tei-c.org/ns/1.0"
	xmlns:w="wulfila/ns/functions"
	exclude-result-prefixes="#all"
	version="3.0">
<!--
	===========================================================================
	Generates a plain text version of the TEI P5 edition.
	===========================================================================
	
	History:
	[2004-06-06] XSLT 1.0 version for TEI P4 
	[2026-02-06] XSLT 3.0; adapted for TEI P5; updated header info 
	[2026-02-19] adapted for modifications to the TEI source (pc for punctuation; milestone element pb)
	
	Tom De Herdt
	https://www.wulfila.be/
	
	===========================================================================
-->
	
	<xsl:output
		method="text"
		indent="no"
		encoding="UTF-8"/><!-- use-character-maps="temp" -->
	
	<xsl:strip-space elements="*"/>
	<xsl:preserve-space elements="t:bibl t:note"/>
	
	<!-- For automated comparison with old text file; disable after testing. -->
	<xsl:character-map name="temp">
		<xsl:output-character character="ƕ" string="hv"/>
		<xsl:output-character character="“" string='"'/>
		<xsl:output-character character="”" string='"'/>
		<xsl:output-character character="‘" string="'"/>
		<xsl:output-character character="’" string="'"/>
		<xsl:output-character character="—" string="-"/>
		<xsl:output-character character="→" string="--&gt;"/>
	</xsl:character-map>
	
	<!-- Returns $string right-justified with spaces for a total length of $length. -->
	<xsl:function name="w:justify" as="xs:string">
		<xsl:param name="string" as="xs:string"/>
		<xsl:param name="length" as="xs:integer"/>
		<xsl:value-of select="$string || string-join(for $i in (1 to ($length - string-length($string))) return ' ')"/>
	</xsl:function>
	
	<xsl:template match="/">###############################################################################
# 
# THE GOTHIC BIBLE
# 
# Based on the edition of Wilhelm Streitberg (1919)
# 
###############################################################################
# 
# SOURCE AND COPYRIGHT
#
# Die gotische Bibel / Herausgegeben von Wilhelm Streitberg. 
# 1. Teil: Der gotische Text und seine griechische Vorlage. Mit Einleitung, 
# Lesarten und Quellennachweisen sowie den kleineren Denkmälern als Anhang.
# Heidelberg: Carl Winter, 1919. (Germanische Bibliothek, 2. Abt., 3. Band)
# 
# Online edition provided by Project Wulfila (https://www.wulfila.be/),
# University of Antwerp. Text scanned and edited by Robert Tannert, 
# David Landau &amp; Tom De Herdt (1997-1998).
# 
# This electronic edition may be used for academic or other non-commercial
# purposes. It is expected that, in accordance with normal scholarly etiquette,
# use of the material will be acknowledged appropriately, i.e. stating the
# information above.
# 
# Contact: https://www.wulfila.be/project/contact/
# 
# File derived from a TEI P5 master document with XSLT. ** DO NOT EDIT **
# Generated on <xsl:value-of select="current-dateTime()"/>.
# 
# -----------------------------------------------------------------------------
#
# EDITORIAL CONVENTIONS
# 
# Angular brackets &lt; &gt; indicate additions to the text,
# square brackets [ ] indicate deletions,
# parenthesis ( ) indicates that certain chracters or words can not be 
# identified with complete certainty (italic text in Streitberg's edition).
# 
# Tilde ~ indicates assimilation, as in "jaþ~þan" (for "jah þan").
#
# Incipit and explicit have verse number 0 and 255, resp.
# 
# -----------------------------------------------------------------------------
# 
# ABBREVIATIONS
# 
<xsl:apply-templates select="id('books')"/>
# 
# -----------------------------------------------------------------------------
# 
# MANUSCRIPT SIGLA
# 
<xsl:apply-templates select="id('manuscripts')"/>
# 
# -----------------------------------------------------------------------------
# 
# DEVIATIONS FROM STREITBERG'S 1919 EDITION
# 
<xsl:apply-templates select="id('deviations')"/>
#
###############################################################################


<xsl:apply-templates select="t:TEI/t:text/t:body"/>
</xsl:template>
	
	<xsl:template match="id('books')">
		<xsl:for-each select="t:list/t:item/t:ref/t:choice">
			<xsl:text># </xsl:text>
			<xsl:value-of select="w:justify(t:abbr, 15)"/>
			<xsl:value-of select="t:expan"/>
			<xsl:if test="not(position()=last())">&newline;</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="id('manuscripts')">
		<xsl:for-each select="t:listWit/t:witness">
			<xsl:variable name="wit" select="@xml:id"/>
			<xsl:text># </xsl:text>
			<xsl:value-of select="w:justify($wit, 15)"/>
			<xsl:value-of select="."/>
			<xsl:if test="not(position()=last())">&newline;</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="id('deviations')">
		<xsl:text># </xsl:text>
		<xsl:value-of select="t:p"/>
		&newline;
		<xsl:for-each select="t:list/t:item">
			<xsl:text># </xsl:text>
			<xsl:value-of select="t:cit/t:ref"/>
			<xsl:text>: </xsl:text>
			<xsl:apply-templates select="t:cit/t:quote"/>
			<xsl:apply-templates select="t:note"/>
			<xsl:if test="not(position()=last())">&newline;</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="t:item/t:cit/t:quote">
		<xsl:for-each select="t:hi">
			<xsl:apply-templates mode="sic"/>
			<xsl:text> → </xsl:text>
			<xsl:apply-templates mode="corr"/>
			<xsl:if test="not(position()=last())">, </xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="t:choice" mode="sic">
		<xsl:value-of select="t:sic"/>
	</xsl:template>
	
	<xsl:template match="t:choice" mode="corr">
		<xsl:value-of select="t:corr"/>
	</xsl:template>
	
	<xsl:template match="id('deviations')//t:note"> (<xsl:apply-templates/>)</xsl:template>
	<xsl:template match="id('deviations')//t:title">‘<xsl:apply-templates/>’</xsl:template>
	<xsl:template match="id('deviations')//t:q">“<xsl:apply-templates/>”</xsl:template>
	<xsl:template match="id('deviations')//t:note/t:quote">“<xsl:apply-templates/>”</xsl:template>
	
	<xsl:template match="t:body">
		<xsl:apply-templates select="t:div/(t:div/t:ab | t:opener | t:closer)"/>
	</xsl:template>
	
	<!-- Verse: -->
	<xsl:template match="t:body/t:div/t:div/t:ab">
		<xsl:apply-templates select="t:app/t:rdg" mode="verse">
			<xsl:with-param name="book" select="../../@n"/>
			<xsl:with-param name="chapter" select="../@n"/>
			<xsl:with-param name="verse" select="@n"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<!-- Opener: -->
	<xsl:template match="t:body/t:div/t:opener">
		<xsl:apply-templates select="t:app/t:rdg" mode="verse">
			<xsl:with-param name="book" select="../@n"/>
			<xsl:with-param name="chapter" select="1"/>
			<xsl:with-param name="verse" select="0"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<!-- Closer: -->
	<xsl:template match="t:body/t:div/t:closer">
		<xsl:apply-templates select="t:app/t:rdg" mode="verse">
			<xsl:with-param name="book" select="../@n"/>
			<xsl:with-param name="chapter" select="preceding-sibling::t:div[1]/@n"/>
			<xsl:with-param name="verse" select="255"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<!-- Verse reading: -->
	<xsl:template match="t:rdg" mode="verse">
		<xsl:param name="book" select="-1"/>
		<xsl:param name="chapter" select="-1"/>
		<xsl:param name="verse" select="-1"/>
		<xsl:variable name="bookname" select="id('books')/t:list/t:item/t:ref[@target=concat('#B',$book)]/t:choice/t:abbr/data()"/>
		
		<xsl:value-of select="$bookname"/>
		<xsl:text> </xsl:text>
		<xsl:value-of select="$chapter"/>
		<xsl:text>:</xsl:text>
		<xsl:value-of select="$verse"/>
		<xsl:text> [</xsl:text>
		<xsl:value-of select="substring(@wit,2)"/><!-- remove initial '#' -->
		<xsl:text>] </xsl:text>
		<xsl:apply-templates select="node()"/>
		&newline;
	</xsl:template>
	
	<!-- Manuscript markers: -->
	<xsl:template match="t:pb"/>
	
	<!-- Tokens (words): -->
	<xsl:template match="t:w">
		<xsl:call-template name="space-before"/>
		<xsl:apply-templates/>
	</xsl:template>
	
	<!-- Variants: -->
	<xsl:template match="t:seg[@type='diff']">
		<xsl:if test="preceding-sibling::*[not(self::t:pb)] and not(child::*[not(self::t:pb)][1][self::t:pc])">
			<xsl:text> </xsl:text>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:template>
	
	<!-- Punctuation: -->
	<xsl:template match="t:pc">
		<xsl:value-of select="."/>
	</xsl:template>
	
	<!-- Em dash: -->
	<xsl:template match="t:pc[text()='&#x2014;']"> &#x2014;</xsl:template>
	
	<!-- Additions: -->
	<xsl:template match="t:add">
		<xsl:call-template name="space-before"/>
		<xsl:text>&lt;</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>&gt;</xsl:text>
	</xsl:template>
	
	<!-- contained within a token: -->
	<xsl:template match="t:w/t:add">
		<xsl:text>&lt;</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>&gt;</xsl:text>
	</xsl:template>
	
	<!-- Deletions: -->
	<xsl:template match="t:del">
		<xsl:call-template name="space-before"/>
		<xsl:text>[</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>]</xsl:text>
	</xsl:template>
	
	<!-- contained within a token: -->
	<xsl:template match="t:w/t:del">
		<xsl:text>[</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>]</xsl:text>
	</xsl:template>
	
	<!-- Unclear text (always contained within a token, fragmentation): -->
	<xsl:template match="t:unclear">
		<xsl:text>(</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>)</xsl:text>
	</xsl:template>
	
	<!-- Lacunae: -->
	<xsl:template match="t:lacunaStart|t:lacunaEnd|t:gap">
		<xsl:call-template name="space-before"/>
		<xsl:text>. . . .</xsl:text>
	</xsl:template>
	
	<!-- Numbers: --> 
	<xsl:template match="t:num">
		<xsl:call-template name="space-before"/>
		<xsl:apply-templates/>
		<xsl:text> (</xsl:text>
		<xsl:value-of select="@value"/>
		<xsl:text>)</xsl:text>
	</xsl:template>

	<!-- Quotations: -->
	<xsl:template match="t:quote">
		<xsl:call-template name="space-before"/>
		<xsl:text>«</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>»</xsl:text>
	</xsl:template>
	
	<xsl:template match="t:q">
		<xsl:call-template name="space-before"/>
		<xsl:text>‘</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>’</xsl:text>
	</xsl:template>
	
	<!-- Inserts space, unless the context element is the first element of its parent, ignoring pb elements: -->
	<xsl:template name="space-before">
		<xsl:if test="preceding-sibling::*[not(self::t:pb)]">
			<xsl:text> </xsl:text>
		</xsl:if>
	</xsl:template>
	
</xsl:stylesheet>