<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY and '&amp;'>
<!ENTITY eds '(Eds.)'>
<!ENTITY ed '(Ed.)'>
]>
<xsl:stylesheet 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns="http://www.w3.org/1999/xhtml"
	version="1.0">
<xsl:output 
	method="xml"
	encoding="UTF-8"
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
	indent="yes"
	/>
<xsl:preserve-space elements="p"/>

	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
			<head>
				<title>Wulfila project: bibliographical references</title>
				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
				<link rel="stylesheet" type="text/css" href="../res/style/main.css" title="main"/>
				<link rel="stylesheet" type="text/css" href="../res/style/bibliography.css"/>
			</head>
			<body>
				<div id="map">
					<a href="../">home</a> 
					<span class="separator"> &#x25BA; </span>
					<a href="../project/">project</a> 
					<span class="separator"> &#x25BA; </span> 
					<span class="current">bibliography</span>
				</div>
				<div id="menu">
					<a href="../project/" title="About the project">introduction</a> | 
					<a href="../news/" title="What's new...?">news</a> | 
					<a href="../bibliography/" title="Bibliographical references">bibliography</a> | 
					<a href="../project/credits/" title="People involved">credits</a> | 
					<a href="../project/copyright/" title="Copyright information">copyright</a> | 
					<a href="../project/contact/" title="Contact information">contact</a>
				</div>
				<div id="body">
					<h1>References</h1>
					<xsl:apply-templates select="TEI.2/text/body/div"/>
				</div>
				<div id="bottom-menu">
					<a href="#map">back to top</a> | 
					<a href="bibliography.xml" title="TEI P4 source file">xml source</a> | 
					<a href="bibliography.xsl" title="Stylesheet used to generate this page">xslt stylesheet</a>
				</div>
				<div id="footer">Provided by <a href="http://www.wulfila.be/">Project Wulfila</a> 2004, University of Antwerp, Belgium. Last modified on <span class="date">2006-02-21</span> by <a href="http://www.wulfila.be/project/contact/" title="Tom De Herdt">TDH</a>.</div>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="div">
		<div>
			<xsl:variable name="heading-level">
				<xsl:choose>
					<xsl:when test="count(ancestor::div) &lt; 5"><xsl:value-of select="count(ancestor::div)+2"/></xsl:when>
					<xsl:otherwise>6</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:element name="h{$heading-level}">
				<xsl:number level="multiple"  format="1.1" count="div"/>
				<xsl:text>.&#x00A0;</xsl:text>
				<xsl:choose>
					<xsl:when test="head"><xsl:value-of select="head"/></xsl:when>
					<xsl:otherwise>[untitled]</xsl:otherwise>
				</xsl:choose>
			</xsl:element>
			<xsl:apply-templates select="listBibl|div"/>
		</div>
	</xsl:template>
	
	<xsl:template match="listBibl">
		<xsl:apply-templates select="biblStruct|bibl">
			<!--<xsl:sort select="@id"/>-->
			<xsl:sort select="(descendant::author|descendant::editor)[1]"/><!-- sort on first author or editor -->
			<xsl:sort select="descendant::date"/><!-- sort on publishing year -->
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="listBibl[@id='Bookmarks']">
		<ul>
			<xsl:apply-templates select="bibl" mode="bookmarks">
				<xsl:sort select="bibl/title"/>
			</xsl:apply-templates>
		</ul>
	</xsl:template>
	
	<xsl:template match="bibl[title[@level='u']]">
		<p id="{@id}" class="entry">
			<span class="authors">
				<xsl:call-template name="process-authors"><xsl:with-param name="year" select="date"/></xsl:call-template>
			</span>
			<span class="u-title"><xsl:apply-templates select="title"/></span>. 
			<xsl:choose>
				<xsl:when test="note[@type='source']">
					Accessed at <a href="{note/xptr/@url}"><xsl:value-of select="note/xptr/@url"/></a> on <xsl:value-of select="note/date/."/>.
				</xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
		</p>
	</xsl:template>
		
	<xsl:template match="bibl" mode="bookmarks">
		<li>
			<a href="{xptr/@url}"><xsl:value-of select="title"/></a>
			<xsl:if test="editor|author|pubPlace">
				 [<xsl:value-of select="editor|author|pubPlace"/>]
			</xsl:if>
		</li>
	</xsl:template>
	
	
	<xsl:template match="biblStruct">
		<p id="{@id}" class="entry">
			<xsl:apply-templates select="monogr" mode="monographic">
				<xsl:with-param name="url" select="note[@type='links']/xptr[1]/@url"/>
			</xsl:apply-templates>
			<xsl:apply-templates select="series|idno"/>
			<xsl:if test="//note[string(@target)=string(current()/@id)]"> [<a href="#NOTE-{@id}">note</a>]</xsl:if>
		</p>
	</xsl:template>
	
	<xsl:template match="biblStruct[analytic]">
		<p id="{@id}" class="entry"> 
			<xsl:apply-templates select="analytic">
				<xsl:with-param name="url" select="note[@type='links']/xptr[1]/@url"/>
			</xsl:apply-templates>
			<xsl:apply-templates select="monogr" mode="analytic"/>
			<xsl:apply-templates select="series|idno"/>
			<xsl:apply-templates select="note[not(@type)]"/><!-- toegevoegd 2006-02-21 -->
			<xsl:if test="//note[string(@target)=string(current()/@id)]"> [<a href="#NOTE-{@id}">note</a>]</xsl:if>
		</p>
	</xsl:template>
		
	<xsl:template match="analytic">
	<!-- Matches a title published in a collection of titles (typically a paper or report): -->
		<xsl:param name="url"/>
		<span class="authors">
			<xsl:call-template name="process-authors">
				<xsl:with-param name="year" select="following-sibling::monogr/imprint/date/text()"/>
			</xsl:call-template>
		</span>
		<span class="a-title">
			<xsl:choose>
				<xsl:when test="$url"><a href="{$url}"><xsl:apply-templates select="title"/></a></xsl:when>
				<xsl:otherwise><xsl:apply-templates select="title"/></xsl:otherwise>
			</xsl:choose>
		</span>
		<xsl:text>. </xsl:text>
	</xsl:template>
	
	<xsl:template match="monogr" mode="monographic">
	<!-- Matches a title published as a separate physical volume (typically a book or journal): -->
		<xsl:param name="url"/>
		<span class="authors">
			<xsl:call-template name="process-authors">
				<xsl:with-param name="year" select="imprint/date/text()"/>
			</xsl:call-template>
		</span>
		<span class="m-title">
			<xsl:choose>
				<xsl:when test="$url"><a href="{$url}"><xsl:apply-templates select="title"/></a></xsl:when>
				<xsl:otherwise><xsl:apply-templates select="title"/></xsl:otherwise>
			</xsl:choose>
		</span>
		<xsl:text>. </xsl:text>
		<xsl:apply-templates select="respStmt"/>
		<xsl:apply-templates select="edition"/>
		<xsl:apply-templates select="note"/>
		<xsl:apply-templates select="imprint"/>
	</xsl:template>
	
	<xsl:template match="monogr" mode="analytic">
	<!-- Matches the book or journal that contains the paper described in the bibliographic reference: -->
		<xsl:if test="not(title[1][@level='j'])">
			<!-- NOT a JOURNAL: -->
			<xsl:text>In </xsl:text>
			<xsl:if test="author|editor">
				<xsl:call-template name="process-authors"/>
				<xsl:text>, </xsl:text>
			</xsl:if>
		</xsl:if>
		<span class="j-title">
			<xsl:apply-templates select="title"/>
		</span>
		<xsl:apply-templates select="imprint/biblScope"/>. 
		<xsl:apply-templates select="imprint"/>
	</xsl:template>
		
	<xsl:template match="monogr[preceding-sibling::monogr]">
	<!-- Used when a paper has been published in more than one book or journal: -->
		<!-- (not yet supported) -->
	</xsl:template>

<!-- AUTHORS and EDITORS: -->
	<xsl:template name="process-authors">
		<xsl:param name="year"/>
		<xsl:call-template name="process-names"><xsl:with-param name="names" select="author"/></xsl:call-template>
		<xsl:if test="count(author)&gt;0 and count(editor)&gt;0"> / </xsl:if>
		<xsl:call-template name="process-names"><xsl:with-param name="names" select="editor"/></xsl:call-template>			
		<xsl:if test="count(editor)&gt;0">
			<xsl:choose>
				<xsl:when test="count(editor)=1"><xsl:text> </xsl:text>&ed;</xsl:when>
				<xsl:otherwise><xsl:text> </xsl:text>&eds;</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
		<xsl:if test="$year"> (<xsl:value-of select="$year"/>). </xsl:if>
	</xsl:template>
	
	<xsl:template name="process-names">
		<xsl:param name="names"/>
		<xsl:for-each select="$names">
			<xsl:apply-templates select="current()"/>
			<xsl:if test="position()!=last()">
				<xsl:choose>
					<xsl:when test="position()=(last() - 1)"><xsl:text> &and; </xsl:text></xsl:when>
					<xsl:when test="position()&lt;(last() - 1)">, </xsl:when>
				</xsl:choose>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="normalize-name">
		<xsl:param name="inputstring"/>
		<xsl:value-of select="normalize-space(substring-before($inputstring, ','))"/><xsl:text>, </xsl:text>
		<xsl:call-template name="get-initials">
			<xsl:with-param name="inputstring" select="concat(normalize-space(translate(substring-after($inputstring, ','), '.', ' ')), ' ')"/>
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template name="get-initials">
		<xsl:param name="inputstring"/>
		<xsl:if test="$inputstring">
			<xsl:value-of select="concat(substring(substring-before($inputstring, ' '), 1, 1), '.')"/>
			<xsl:call-template name="get-initials">
				<xsl:with-param name="inputstring" select="substring-after($inputstring, ' ')"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="author|editor">
		<xsl:call-template name="normalize-name">
			<xsl:with-param name="inputstring" select="."/>
		</xsl:call-template><xsl:if test="@role='e.a.'"> et. al.</xsl:if>
	</xsl:template>
	
	<xsl:template match="abbr"><abbr title="{@expan}"><xsl:apply-templates/></abbr></xsl:template>
	
	<xsl:template match="series">
		(<xsl:apply-templates select="title"/><xsl:apply-templates select="biblScope"/>)
	</xsl:template>
	
	<xsl:template match="respStmt">
		<xsl:apply-templates select="resp"/>
	</xsl:template>
	
	<xsl:template match="resp">
		<xsl:apply-templates/>
		<xsl:text>. </xsl:text>
	</xsl:template>
	
	<xsl:template match="title">
		<xsl:apply-templates/>
		<xsl:if test="following-sibling::title"><xsl:text>. </xsl:text></xsl:if>
	</xsl:template>
	<xsl:template match="title/title"><i><xsl:apply-templates/></i></xsl:template>
	
	<xsl:template match="edition"><xsl:value-of select="."/>. </xsl:template>
	
<!-- IMPRINT: -->
	<xsl:template match="imprint">
		<xsl:apply-templates select="publisher"/>
		<xsl:apply-templates select="pubPlace"/>
	</xsl:template>
	<xsl:template match="publisher[not(../pubPlace)]">
		<xsl:apply-templates/>
		<xsl:text>. </xsl:text>
	</xsl:template>
	<xsl:template match="publisher[../pubPlace]">
		<xsl:apply-templates/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	<xsl:template match="pubPlace">
		<xsl:apply-templates/>
		<xsl:text>. </xsl:text>
	</xsl:template>

	<xsl:template match="biblScope[@type='pages']">
		<xsl:text>, pp. </xsl:text>
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="biblScope[@type='volume']">
		<xsl:text>, vol. </xsl:text>
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="biblScope">
		<xsl:text>, </xsl:text>
		<xsl:if test="@type">
			<xsl:value-of select="@type"/>
			<xsl:text> </xsl:text>
		</xsl:if>
		<xsl:value-of select="."/>
	</xsl:template>
	
	<xsl:template match="xref"><a href="{@url}"><xsl:value-of select="."/></a></xsl:template>
	
<!-- ISBN: -->
	<xsl:template match="idno">
		<xsl:text> [</xsl:text>
		<xsl:value-of select="@type"/>
		<xsl:text>&#x00A0;</xsl:text>
		<xsl:value-of select="."/>
		<xsl:text>]</xsl:text>
	</xsl:template>
	
	<xsl:template match="monogr/note">
		<xsl:apply-templates/>
		<xsl:text>. </xsl:text>
	</xsl:template>
		
</xsl:stylesheet>
