<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Använd det här exemplet med förstånd, dvs ta inte för givet att du här har
den bästa, eller ens en bra lösning. Modifiera, radera och utöka -->
	<xsl:output indent="no" method="html"/>
	<!-- Skelettet, matchar rotnoden, genererar endast innehåll i title-elementet 
	och skickar sen
	vidare noduppsättningen för behandling av presentationens inledande block av
	titel- och författare-deklarationer, mm
	-->
	<xsl:template match="/">
		<html>
			<head>
				<title>
				<xsl:choose>
				<xsl:when test="TEI.2/teiHeader/fileDesc/titleStmt/title[@type='main']">
				     <xsl:value-of select="TEI.2/teiHeader/fileDesc/titleStmt/title[@type='main']"/>
				</xsl:when>
				<xsl:otherwise>
						<xsl:value-of select="TEI.2/teiHeader/fileDesc/titleStmt/title"/>
				</xsl:otherwise>
					</xsl:choose>
					<xsl:text> </xsl:text>
					<xsl:value-of select="TEI.2/teiHeader/fileDesc/titleStmt/author"/>
				</title>
				<style type="text/css">
				body {margin : 50px ;
				font-family : Verdana, sans-serif ;
				font-size : 10pt ;}
				</style>
			</head>
			<body>
			<xsl:apply-templates select="TEI.2/teiHeader/fileDesc/titleStmt"/>
			<xsl:apply-templates select="TEI.2/teiHeader/fileDesc/publicationStmt"/>
			<xsl:apply-templates select="TEI.2/teiHeader/fileDesc/sourceDesc"/>
			<xsl:apply-templates select="TEI.2/text/body"/>
			</body>
		</html>
	</xsl:template>
	
	<!-- 
	Genererar "titel" och upphov, som hämtas från teiHeadern. Notera att den förutsätter en 
	titel med attribut-värde-paret type:main, och om inte så får type-attributet förekomma.
	Lägg till alternativ om detta inte stämmer med kodningen
	-->
	<xsl:template match="TEI.2/teiHeader/fileDesc/titleStmt">
	<xsl:if test="./title[@type='main']">
	<h1><xsl:apply-templates select="./title[@type='main']"/></h1>
	<h2 style="color:maroon"><xsl:apply-templates select="./author"/></h2>
	</xsl:if>
	<xsl:if test="./title[not(@type)]">
	<h1><xsl:apply-templates select="./title"/></h1>
	<h2 style="color:maroon"><xsl:apply-templates select="./author"/></h2>
	<h3>En digital utgåva</h3>
	</xsl:if>
	<!-- Notera utformningen av XPathen här! -->
	<xsl:apply-templates select="//titleStmt//date"/>
	</xsl:template>
	
	<!-- Notera att denna fångar upp flera möjliga 'date'
	Så vill man kanske inte ha det...
	-->
	<xsl:template match="//titleStmt//date">
		<xsl:text> (</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>) </xsl:text>
		<xsl:apply-templates select="publicationStmt"/>
	</xsl:template>
	
	<!-- Här kan det bli lite bökigt när det finns flera förekomster
	av någonting. Den explicita tillagda texten kan också bli konstig 
	om man gör en annorlunda tolkning av semantiken
	-->
	<xsl:template match="publicationStmt"><p style="margin : 20px">
	<xsl:choose>
	<xsl:when test="./publisher">
	Publicerad av <i><xsl:value-of select="."/></i><xsl:text> </xsl:text>
	</xsl:when>
	<xsl:when test="./authority|./distributor">
	Tillgängliggjord av <xsl:for-each select="./authority|./distributor">
	<xsl:apply-templates/>
	<xsl:text> </xsl:text>
	</xsl:for-each>
	</xsl:when>
	</xsl:choose>
	<xsl:value-of select="./date"/>.
	<xsl:text> </xsl:text><xsl:for-each select="./availability/p"><p><xsl:apply-templates/></p></xsl:for-each>	</p>
	</xsl:template>
	
	<!-- Vad händer här om det finns flera p, bibl eller fullbibl? -->
	<xsl:template match="sourceDesc">
	<p style="margin-top : 20px">Utgåvan är gjord efter <span style="font-size : 0.9em ; color:blue ; font-style:italic"><xsl:apply-templates/></span>
	</p></xsl:template>
	
	<!-- Här definieras ett målankare för stycken som har ett id-attribut. 
	Kan va bra att ha... 
	-->
	<xsl:template match="p">
	<p>
	<xsl:if test="@id">
	<a name="{@id}"></a>
	</xsl:if>
	<xsl:apply-templates/>
	</p>
	</xsl:template>
	
	<!-- Notera här att typade div-element åsätts
	ett html-attribut 'class'. Det kan användas med CSS. Notera också
	att om det finns ett n-attribut så genereras dess värde som en rubrik.
	-->
	<xsl:template match="div|div0|div1|div2">
	<xsl:choose>
	<xsl:when test="@type">
	<div class="{@type}">
	<xsl:if test="@n">
	<a name="{@n}">
	<h2><xsl:value-of select="@n"/></h2>
	</a>
	</xsl:if>
	<xsl:apply-templates/>
	</div>
	</xsl:when>
	<xsl:otherwise>
	<div>
	<xsl:if test="@n">
	<a name="{@n}">
	<h2><xsl:value-of select="@n"/></h2>
	</a>
	</xsl:if>
	<xsl:apply-templates/>
	</div>
	</xsl:otherwise>
	</xsl:choose>
	</xsl:template>
	
	
	<xsl:template match="*[@rend='italic']">
	<i>	
	<xsl:apply-templates/>
	</i>
	</xsl:template>
	
	<xsl:template match="q">
	<i>	
	<xsl:apply-templates/>
	</i>
	</xsl:template>
	
	<xsl:template match="lb">	
	<br/>
	</xsl:template>
	
	<xsl:template match="l">	
	<br/>
	<xsl:apply-templates/>
	</xsl:template>

</xsl:stylesheet>


