<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:mets="http://www.loc.gov/METS/"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:rdf="http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/"
	xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:mods="http://www.loc.gov/mods/v3"
	exclude-result-prefixes="tei mets xlink exist rdf" version="1.0">

	<!-- Einbindung der Standard-Templates und Variablen -->
	<xsl:import href="http://diglib.hab.de/rules/styles/param.xsl"/>
<!--	<xsl:import href="http://diglib.hab.de/rules/styles/tei-phraselevel.xsl"/>-->
	
	<!--Alternative, wenn der dl-Server nicht funktioniert-->
<!--	<xsl:import href="rules/styles/param.xsl"/>-->
<!--	<xsl:import href="../rules/styles/tei-phraselevel.xsl"/>-->


	<xsl:output encoding="UTF-8" indent="yes" method="html"/> <!--doctype-public="-//W3C//DTD HTML 4.01//EN"
	doctype-system="http://www.w3.org/TR/html4/strict.dtd"-->

<!--	<xsl:strip-space elements="*"/>-->
	<xsl:param name="dir">edoc/ed000228</xsl:param>
	<xsl:param name="q"/>
<!--	<xsl:param name="qtype"/>-->
<!--	<xsl:param name="distype"/>-->
	<xsl:param name="pvID"/>
	<xsl:param name="footerXML"/>
	<xsl:param name="footerXSL"/>
<!--	<xsl:param name="lokal"/>-->
<!--	<xsl:param name="markup"/>-->
	<xsl:variable name="metsfile" select="concat('http://diglib.hab.de/',$dir,'/mets.xml')"/>
	
	<xsl:key name="entity-ref" match="tei:rs" use="substring(@ref, 2)"/>
	<xsl:key name="term-ref" match="tei:term" use="substring(@ref, 2)"/>

	<xsl:template match="*" mode="toc">
		<xsl:apply-templates mode="toc"/>
	</xsl:template>

	<xsl:template match="tei:date/tei:note" mode="toc"/>

	<xsl:template match="/">
		
		
		<!-- Beginn -->
		<html>
			<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
				<title>WDB</title>
				<link rel="stylesheet" type="text/css" href="https://diglib.hab.de/edoc/ed000228/layout/navigator.css"/>
<!--				<link rel="stylesheet" type="text/css" href="http://diglib.hab.de/navigator2.css"/>-->
				
				<!--Alternative, wenn dl-Server nicht funktioniert-->
<!--				<link rel="stylesheet" type="text/css" href="layout/navigator.css"/>-->
<!--				<script type="text/javascript" src="javascript/jquery/jquery-1.11.0.js"/>-->
<!--				<script type="text/javascript" src="javascript/jquery/functions.js"/>-->
				<!--<link rel="stylesheet" type="text/css" media="print"
                    href="http://diglib.hab.de/edoc/ed000228/layout/print.css"/>-->
				<script type="text/javascript" src="https://diglib.hab.de/edoc/ed000228/javascript/jquery/jquery-1.11.0.js"/>
				<script type="text/javascript" src="https://diglib.hab.de/edoc/ed000228/javascript/jquery/functions.js"/>
				<script src="https://diglib.hab.de/navigator.js" type="text/javascript"/>
				<script src="https://diglib.hab.de/navigator.js" type="text/javascript"><noscript>please activate javascript to enable wdb functions</noscript></script>
			</head>

			<body>
				<!--  Dokumentkopf -->
				<div id="doc_header" style="margin-left:-100px">
					<div id="doc_header_text">Text</div>
					<hr id="doc_header_line"/>
				</div>

				<div id="wip"
					style="background-color: #EEE; padding: 0.5em; border: 1px solid black; font-size: 11pt; text-align: center; margin-bottom: 2em; margin-left:-100px">
					<p>
						<xsl:text>&#x27A8; Hinweis: Zur Zeit sind geringfügige Änderungen und Korrekturen am Text und in den Apparaten noch möglich.</xsl:text>
					</p>
					<p>
						<xsl:text>Nach Abschluss der Edition werden etwaige Korrekturen und Ergänzungen in einem Änderungsregister gelistet.</xsl:text>
					</p>
				</div>
				<!-- end WorkInProgress -->

				<!-- Titel -->
				<div id="caption">
					<div>
						<xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/>
					</div>
					<div>
						<xsl:value-of
							select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:author/tei:name/tei:forename"/>
						<xsl:text> </xsl:text>
						<xsl:value-of
							select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:author/tei:name/tei:surname"/>
						<xsl:text> </xsl:text>
					</div>
				</div>
				
				<!--Überlieferung-->				
				<xsl:if test="//tei:div[@type='volume'][@n]">
					<div id="source">
						<p>
							<span style="font-size:11pt;">
										<br/><i>Überlieferung:</i> LASA Dessau-Roßlau, Z 18 Abt. Bernburg, A 9b Nr. 14 
								<xsl:for-each select="//tei:div[@type='volume'][@n]">
									<xsl:text>Bd. </xsl:text>
									<xsl:value-of select="@n"/>
									<xsl:text>, fol. </xsl:text>
									<xsl:value-of select="descendant::tei:pb[1]/@n"/>
									<xsl:text>-</xsl:text>
									<xsl:value-of select="descendant::tei:pb[position()=last()]/@n"/>
									<xsl:if test="position()!=last()">
										<xsl:text>; </xsl:text>
									</xsl:if>									
								</xsl:for-each>
								<xsl:text> (vgl. </xsl:text>
								<a href="http://diglib.hab.de/content.php?dir=edoc/ed000228&amp;distype=optional&amp;metsID=edoc_ed000228_introduction_sourceDesc&amp;xml=introduction%2Fintroduction_sourceDesc.xml&amp;xsl=introduction/introduction.xsl#{//tei:div[@type='volume'][@n][1]/@n}">Quellenbeschreibung</a>
								<xsl:text>).</xsl:text>
							</span>							
						</p>
					</div>
				</xsl:if>
				
				<!--Zitierlink für jeweiligen Monat-->
				<p>
					<span style="font-size:11pt;">
						<i>Zitierlink für den aktuellen Monat: </i> 
						<a href="http://diglib.hab.de/edoc/ed000228/id/{/tei:TEI/@xml:id}_sm/start.htm" target="_blank">
							<xsl:text>http://diglib.hab.de/edoc/ed000228/id/</xsl:text>
							<xsl:value-of select="/tei:TEI/@xml:id"/>
							<xsl:text>_sm/start.htm</xsl:text>
						</a>
					</span>
				</p>
				
				<!--Bearbeitungsstand-->
				<p>
					<span style="font-size:11pt;">
						<i>Bearbeitungsstand: </i>
						<xsl:choose>
							<xsl:when test="//tei:resp='korrigiert von'">
								<xsl:text>transkribiert, kommentiert und korrigiert</xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>transkribiert und kommentiert</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</span>
				</p>
				
				<!--Zitiervorschlag für jeweiligen Monat-->
				<a href="javascript:switchlayer('citation');">
					<div style="margin: 1em 0 1em 0;">[Zitierhinweis]</div>
				</a>
				
				<div id="citation" style="display: none; border: 1px black solid; background-color: #EEE;">				
					<p style="font-size:11pt; margin: 0.3em 0.5em 0.3em 0.5em;">
						<xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title/tei:date"/>
						<xsl:text>, in: Digitale Edition und Kommentierung der Tagebücher des Fürsten Christian II. von Anhalt-Bernburg (1599-1656), unter Leitung von Peter Burschel und Ronald G. Asch hg. und bearb. von Arndt Schreiber, Alexander Zirr, Andreas Herz und Antoine Odier, unter Mitarbeit von Maximilian Görmar, Anna-Maria Blank, Anna Lisa Sonnenberg, Maximilian Blatt und Moritz Vogelbacher, technisch umgesetzt von Marcus Baumgarten, Maximilian Görmar und Jorma Niehoff, Wolfenbüttel 2013-2026, PURL: </xsl:text>
						<a href="http://diglib.hab.de/edoc/ed000228/id/{/tei:TEI/@xml:id}_sm/start.htm" target="_blank">
							<xsl:text>http://diglib.hab.de/edoc/ed000228/id/</xsl:text>
							<xsl:value-of select="/tei:TEI/@xml:id"/>
							<xsl:text>_sm/start.htm</xsl:text>
						</a>
						<xsl:text>, Zugriff: </xsl:text>
						<span id="date"></span>
						<xsl:text>.</xsl:text>
					</p>
				</div>

				<!-- Inhaltsuebersicht -->
				<a href="javascript:switchlayer('headings');">
					<div style="margin: 1em 0 1em 0;">[Inhaltsverzeichnis]</div>
				</a>
							
				
				<div id="headings">
					<xsl:for-each select="/tei:TEI/tei:text/tei:body//tei:div/tei:head//tei:date">
						<div class="diary_list">
							<table>
								<tbody>
									<tr>
										<td style="width: 10%;">
											<a class="date" href="#hd{position()}">
												<xsl:apply-templates select="." mode="toc"/>
												<!--<xsl:text>, </xsl:text>	-->
											</a>										
											<br/>
											<span style="margin-left:0.5em; display:block; font-size:10pt;">
												<xsl:apply-templates select="ancestor::tei:div[@type='entry']//tei:index[@indexName='place']" mode="toc"/>
											</span>
										</td>
										<td>
											<xsl:apply-templates select="ancestor::tei:div[@type='entry']//tei:index[@indexName='regest']" mode="toc"/>
										</td>
									</tr>
								</tbody>								
							</table>	
						</div>
					</xsl:for-each>
				</div>


				<div class="content">
					<!-- Haupttext -->
					<xsl:apply-templates select="tei:TEI/tei:text"/>
				</div>
				
				<!-- Apparate  -->
				<xsl:if
					test="tei:TEI/tei:text/tei:body//tei:note[@type='annotation']
                		| tei:TEI/tei:text/tei:body//tei:note[@type='footnote']
                		| tei:TEI/tei:text/tei:body//tei:handShift
                		| tei:TEI/tei:text/tei:body//tei:choice
                		| tei:TEI/tei:text/tei:body//tei:ref[@type='biblical'][@cRef][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
					<div id="annotation">
						<!-- Textapparat  -->
						<xsl:if
							test="tei:TEI/tei:text/tei:body//tei:note[@type='annotation']
							| tei:TEI/tei:text/tei:body//tei:handShift
							| tei:TEI/tei:text/tei:body//tei:choice">
							<hr/>
							<div id="textapparat">Textapparat</div>
							<xsl:for-each select="tei:TEI/tei:text/tei:body//tei:note[@type='annotation'] | //tei:handShift | //tei:choice |//tei:restore">
								<xsl:variable name="number">
									<xsl:call-template name="fnnumber" />
								</xsl:variable>
								<div style="padding-left: 1em; text-indent: -1em;">
									<a name="an{$number}" href="#ana{$number}" style="display:inline-block; margin-left: 1em;">
										<xsl:value-of select="$number"/>
									</a>
									<xsl:text> </xsl:text>
									<xsl:choose>
										<xsl:when test="self::tei:note">
											<xsl:apply-templates/>
										</xsl:when>
										<xsl:when test="self::tei:handShift">
											<xsl:text>Schreiberwechsel zu </xsl:text>
											<xsl:choose>
												<xsl:when test="@scribe='chr'">
													<i>Christian II</i>
												</xsl:when>
												<xsl:when test="@scribe='es'">
													<i>Fürstin Eleonora Sophia von Anhalt-Bernburg</i>
												</xsl:when>
												<xsl:when test="@scribe">
													<i><xsl:value-of select="@scribe" /></i>
												</xsl:when>
												<xsl:otherwise><i>unbekannt</i></xsl:otherwise>
											</xsl:choose>
											<xsl:text>.</xsl:text>
										</xsl:when>
										<xsl:when test="self::tei:choice">	
											<xsl:choose>
												<xsl:when test="tei:corr">
													<xsl:text>Im Original "</xsl:text>
													<xsl:for-each select="tei:sic">
														<xsl:call-template name="sic_corr-text"/>
													</xsl:for-each>
													<xsl:text>"</xsl:text>
													<xsl:text> korrigiert in </xsl:text>
													<xsl:text>"</xsl:text>
													<xsl:for-each select="tei:corr">
														<xsl:call-template name="sic_corr-text"/>
													</xsl:for-each>
													<xsl:text>"</xsl:text>
													<xsl:text>.</xsl:text>
												</xsl:when>
												<xsl:when test="tei:expan">
													<xsl:text>Im Original steht "</xsl:text>
													<xsl:value-of select="tei:abbr/text()"/>
													<xsl:if test="tei:abbr/tei:c/@rend='super'">
														<sup><xsl:value-of select="tei:abbr/tei:c"/></sup>
													</xsl:if>
													<xsl:if test="tei:abbr/tei:hi/@rend='super'">
														<sup><xsl:value-of select="tei:abbr/tei:hi"/></sup>
													</xsl:if>
													<xsl:if test="tei:abbr/tei:hi[@rend='super']/following-sibling::node()[1][self::text()]">
														<xsl:value-of select="tei:abbr/tei:hi[@rend='super']/following-sibling::node()[1][self::text()]"/>
													</xsl:if>													
													<xsl:text>"</xsl:text>
													<xsl:text> für </xsl:text>
													<xsl:text>"</xsl:text>
													<xsl:value-of select="tei:expan"/>
													<xsl:text>"</xsl:text>
													<xsl:text>.</xsl:text>
												</xsl:when>
											</xsl:choose>
										</xsl:when>
										<xsl:when test="self::tei:restore">
											<xsl:text>Streichung von "</xsl:text>
											<xsl:choose>
												<xsl:when test="child::tei:foreign">
													<xsl:value-of select="text()"/>
													<xsl:value-of select="tei:foreign"/>
												</xsl:when>
												<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
											</xsl:choose>	
											<xsl:text>" wieder aufgehoben.</xsl:text>
										</xsl:when>
									</xsl:choose>
								</div>
							</xsl:for-each>
						</xsl:if>

						<!-- Kommentare  -->
						<xsl:if test="tei:TEI/tei:text/tei:body//tei:note[@type='footnote'] | tei:TEI/tei:text/tei:body//tei:ref[@type='biblical'][@cRef][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
							<hr/>
							<div id="kommentar">Kommentar</div>
							<xsl:for-each select="tei:TEI/tei:text/tei:body//tei:note[@type='footnote'] | tei:TEI/tei:text/tei:body//tei:ref[@type='biblical'][@cRef][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
								<xsl:variable name="number">
									<xsl:number level="any" count="tei:note[@type ='footnote'] | tei:ref[@type='biblical'][@cRef][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]"/>
								</xsl:variable>
								<div style="padding-left: 1em; text-indent: -1em;">
									<a name="fn{$number}" href="#fna{$number}" style="display:inline-block; margin-left: 1em;">
										<xsl:if test="@xml:id">
											<xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute>
										</xsl:if>
										<xsl:value-of select="$number"/>
									</a>
									<xsl:text> </xsl:text>
									<xsl:choose>
										<xsl:when test="self::tei:ref[@type='biblical'][@cRef][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
											<a>
												<xsl:choose>
													<!--<xsl:when test="contains(@cRef,'Iob')">
														<xsl:attribute name="href">
															<xsl:text>javascript:window.open('</xsl:text>
															<xsl:value-of select="$cRef-biblical-start"/>
															<xsl:value-of select="translate(replace(@cRef,'Iob','Hiob'),' _,','++: ')"/>
															<xsl:text>&amp;id12=1&amp;set=1&amp;l=fr</xsl:text>
															<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
														</xsl:attribute>
													</xsl:when>-->
													<xsl:when test="@subtype='lu45'">
														<xsl:attribute name="href">
															<xsl:text>javascript:window.open('</xsl:text>
															<xsl:value-of select="$cRef-biblical-start"/>
															<xsl:value-of select="translate(@cRef,' _,','++: ')"/>								
															<xsl:text>&amp;id12=1&amp;set=1&amp;l=fr</xsl:text>
															<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
														</xsl:attribute>
													</xsl:when>													
													<xsl:otherwise>
														<xsl:attribute name="href">
															<xsl:text>javascript:window.open('</xsl:text>
															<xsl:value-of select="$cRef-biblical-start"/>
															<xsl:value-of select="translate(@cRef,' _,','++: ')"/>
															<xsl:value-of select="$cRef-biblical-end_de"/>
															<xsl:text>&amp;l=fr</xsl:text>
															<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
														</xsl:attribute>
													</xsl:otherwise>
												</xsl:choose>
												<xsl:choose>
													<xsl:when test="starts-with(@cRef, '1') or starts-with(@cRef, '2') or starts-with(@cRef, '3') or starts-with(@cRef, '4')">
														<xsl:value-of select="substring-before(@cRef, '_')"/>
														<xsl:text>. </xsl:text>
														<xsl:value-of select="translate(substring-after(@cRef, '_'),'_',' ')"/>
													</xsl:when>
													<xsl:otherwise>
														<xsl:choose>
															<xsl:when test="contains(@cRef, '_')">
																<xsl:value-of select="substring-before(@cRef, '_')"/>
																<xsl:text> </xsl:text>
																<xsl:value-of select="substring-after(@cRef, '_')"/>
															</xsl:when>
															<xsl:otherwise>
																<xsl:value-of select="@cRef"/>																	
															</xsl:otherwise>
														</xsl:choose>															
													</xsl:otherwise>
												</xsl:choose></a>
											<xsl:text>.</xsl:text>
										</xsl:when>
										<xsl:otherwise>
											<xsl:apply-templates/>
										</xsl:otherwise>
									</xsl:choose>
								</div>
							</xsl:for-each>
						</xsl:if>
					</div>
				</xsl:if>
				<!-- footer -->
				<div id="doc_footer">

					<xsl:choose>
						<xsl:when
							test="document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='bibliography']/@ADMID]/mets:mdRef/@xlink:href">
							<b>
								<xsl:text>© </xsl:text>
								<xsl:for-each select="document($metsfile)//mods:mods/mods:name">
									<xsl:if test="position() > 1">
										<xsl:text>, </xsl:text>
									</xsl:if>
									<xsl:value-of select="mods:displayForm"/>
								</xsl:for-each>
							</b>
							<a href="{document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='bibliography']/@ADMID]/mets:mdRef/@xlink:href}">
								<img src="http://diglib.hab.de/images/cc-by-sa.png" alt="image CC BY-SA licence" width="50px"
									align="right" hspace="10px"/>
							</a>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of
								select="document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='bibliography']/@ADMID]/mets:mdWrap/mets:xmlData"/>
							<div>
								<a href="/edoc/ed000228/print/{/tei:TEI/@xml:id}.pdf">aktuellen Monat als PDF öffnen</a>
								<img height="25px"
										name="Crystal Clear app kjobviewer by Everaldo Coelho and YellowIcon - All Crystal icons were posted by the author as LGPL on kde-look. Licensed under GNU Lesser General Public License via Wikimedia Commons"
										src="http://diglib.hab.de/edoc/ed000228/images/printer.png"/><br/>
								
								<a href="/edoc/ed000228/print/{substring(tei:TEI/@xml:id, 18,4)}_all.pdf">gesamtes Jahr als PDF öffnen</a>
								<img height="25px"
										name="Crystal Clear app kjobviewer by Everaldo Coelho and YellowIcon - All Crystal icons were posted by the author as LGPL on kde-look. Licensed under GNU Lesser General Public License via Wikimedia Commons"
										src="http://diglib.hab.de/edoc/ed000228/images/printer.png"/><br/>
								
								<!--<a href="/edoc/ed000228/print/tagebuch_christian.zip">alle bisher erschienenen Monate als ZIP-Ordner herunterladen</a>-->
								<a href="/edoc/ed000228/print/tagebuch_christian.zip">alle bisher abgeschlossenen Jahrgänge als ZIP-Ordner herunterladen</a>
								<img height="25px"
										name="Crystal Clear app kjobviewer by Everaldo Coelho and YellowIcon - All Crystal icons were posted by the author as LGPL on kde-look. Licensed under GNU Lesser General Public License via Wikimedia Commons"
										src="http://diglib.hab.de/edoc/ed000228/images/printer.png"/><br/>
								
								<xsl:text>Kontakt: </xsl:text>
								<a href="mailto: projekte@hab.de?subject={substring(tei:TEI/@xml:id, 18,7)}">projekte[at]hab.de</a><br/>
							</div>
						</xsl:otherwise>
					</xsl:choose>
				</div>				
				<div id="footerXML_XSL">
					<xsl:call-template name="footer">
						<xsl:with-param name="footerXML">
							<xsl:value-of select="$footerXML"/>
						</xsl:with-param>
						<xsl:with-param name="footerXSL">
							<xsl:value-of select="$footerXSL"/>
						</xsl:with-param>
					</xsl:call-template>
				</div>
				
				<!-- Ende main -->
				<div id="info_gloss">
					<xsl:apply-templates mode="gloss"/>
				</div>
				<div id="info_person">
					<xsl:apply-templates select="//tei:person"/>
				</div>
				<div id="info_place">
					<xsl:apply-templates select="//tei:place"/>
				</div>
				<div id="info_org">
					<xsl:apply-templates select="//tei:org"/>
				</div>
				<div id="info_bibl">
					<xsl:apply-templates select="//tei:bibl[@xml:id]"/>
				</div>
				
				<!--JavaScript, um aktuelles Datum in Zitiervorschlag mit XSL 1.0 anzuzeigen-->
				<script>
					const d = new Date();
					var year = d.getFullYear();
					var month = d.getMonth() + 1;
					var day = d.getDate();
					document.getElementById("date").innerHTML = (day &lt; 10 ? '0' : '') + day+"." + (month &lt; 10 ? '0' : '') + month + "." + year;
				</script>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="tei:body">
		<xsl:apply-templates/>
	</xsl:template>

	<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        ++++++++++++++++++++++++++++++++++++++++ editionsspezifische Anweisungen ++++++++++++++++++++++++++++++++++++++++++++
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->

	
	<!-- Inhaltsverzeichnis -->
	
	<xsl:template match="tei:date" mode="toc">
		<xsl:variable name="month" select="substring(@when, 6, 2)"/>
		<!-- Tag -->
		<xsl:value-of select="substring(@when, 9, 2)"/>
		<xsl:text>. </xsl:text>
		<!-- Monat -->
		<xsl:choose>
			<xsl:when test="$month = 1"><xsl:text>Januar</xsl:text></xsl:when>
			<xsl:when test="$month = 2"><xsl:text>Februar</xsl:text></xsl:when>
			<xsl:when test="$month = 3"><xsl:text>März</xsl:text></xsl:when>
			<xsl:when test="$month = 4"><xsl:text>April</xsl:text></xsl:when>
			<xsl:when test="$month = 5"><xsl:text>Mai</xsl:text></xsl:when>
			<xsl:when test="$month = 6"><xsl:text>Juni</xsl:text></xsl:when>
			<xsl:when test="$month = 7"><xsl:text>Juli</xsl:text></xsl:when>
			<xsl:when test="$month = 8"><xsl:text>August</xsl:text></xsl:when>
			<xsl:when test="$month = 9"><xsl:text>September</xsl:text></xsl:when>
			<xsl:when test="$month = 10"><xsl:text>Oktober</xsl:text></xsl:when>
			<xsl:when test="$month = 11"><xsl:text>November</xsl:text></xsl:when>
			<xsl:when test="$month = 12"><xsl:text>Dezember</xsl:text></xsl:when>
		</xsl:choose>
		<xsl:text> </xsl:text>
		<!-- Jahr -->
		<xsl:value-of select="substring(@when, 1, 4)"/>
	</xsl:template>
	
	<!-- Kurzregest -->
	<xsl:template match="tei:index[@indexName='regest']" mode="toc">
		<ul class="regest_all">
			<xsl:apply-templates/>
		</ul>
	</xsl:template>
	
	<xsl:template match="tei:term[(parent::tei:index[@indexName='regest'])]">
		<li class="regest_one">
			<xsl:apply-templates/>
		</li>
	</xsl:template>
	
	<!--Itinerar im TOC-->
	<xsl:template match="tei:index[@indexName='place']" mode="toc">
		<xsl:for-each select="tei:term">
			<xsl:choose>
				<xsl:when test="contains(.,'(')">
					<xsl:value-of select="substring-before(.,' (')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>			
			<xsl:if test="position()!=last()">
				<xsl:text> &#8594; </xsl:text>
			</xsl:if>
		</xsl:for-each>		
	</xsl:template>
	
	
	<!-- Schreiberwechsel -->
	<xsl:template match="tei:handShift">
		<xsl:variable name="number">
			<xsl:call-template name="fnnumber"/>
		</xsl:variable>
		<span id="ana{$number}">
			<a href="#an{$number}" style="font-size:9pt;vertical-align:super;color:blue;">
				<xsl:attribute name="title">
					<xsl:text>Schreiberwechsel zu </xsl:text>
					<xsl:choose>
						<xsl:when test="@scribe='chr'">
							<xsl:text>Christian II</xsl:text>
						</xsl:when>
						<xsl:when test="@scribe='es'">
							<xsl:text>Fürstin Eleonora Sophia von Anhalt-Bernburg</xsl:text>
						</xsl:when>
						<xsl:when test="@scribe">
							<xsl:value-of select="@scribe"/>
						</xsl:when>						
						<xsl:otherwise><xsl:text>unbekannt</xsl:text></xsl:otherwise>
					</xsl:choose>
					<xsl:text>.</xsl:text>
				</xsl:attribute>
				<xsl:value-of select="$number" />
			</a>
		</span>
	</xsl:template>

	<!-- preserve-space schützt alle Whitespaces -->

	<xsl:preserve-space elements="*"/>
	
	<!-- Zeilenumbrüche innerhalb von Hinzufügungen werden unterdrückt -->
	<xsl:template match="tei:lb[ancestor::tei:add]"/>
	
	
	<xsl:template match="tei:lb[not(parent::tei:w) and not(ancestor::tei:add)]">
		<br/>
	</xsl:template> 

	<xsl:template match="text()[parent::tei:w]">
		<xsl:value-of select="normalize-space(.)"/>
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:w][preceding-sibling::tei:ex]">
		<xsl:value-of select="."/>
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:sic[descendant::tei:w]]">
		<xsl:choose>
			<xsl:when test="parent::tei:w">
				<xsl:value-of select="normalize-space(.)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="tei:lb[parent::tei:w and not(ancestor::tei:add)]">
		<xsl:choose>
			<xsl:when test="preceding-sibling::tei:pb">
				<br/>
			</xsl:when>
			<xsl:when test="ancestor::tei:rs">
				<span style="color: #900129;"><xsl:text>-</xsl:text></span>
				<br/>
			</xsl:when>
			<xsl:when test="ancestor::tei:term">
				<span style="color: #900129;"><xsl:text>-</xsl:text></span>
				<br/>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign">
				<span style="color: darkslateblue;"><xsl:text>-</xsl:text></span>
				<br/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>-</xsl:text>
				<br/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:ref[@type='biblical']][ancestor::tei:foreign]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
	



	<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->


	<xsl:template match="tei:ex">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:choose>
			<xsl:when test="parent::tei:foreign and parent::tei:foreign/parent::tei:del">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref ex del" style="color: darkslateblue; font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:rs) and not(ancestor::tei:choice) and not(parent::tei:del) and not(parent::tei:term)">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref ex" style="color: darkslateblue; font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and parent::tei:corr">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref ex" style="color: darkslateblue; font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and ancestor::tei:rs and not(parent::tei:rs) and not(parent::tei:w)"><!--Sonderregel für 1628_08.html fol. 147v. ("Quedlinburg")-->
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref ex" style="color: darkslateblue; font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and parent::tei:rs">
				<a href="javascript:void(0);" id="{$id}" onclick="showInlineAnnotation(this, '{$ref}')" class="rs-ref ex" style=" font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="parent::tei:term">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}')" class="rs-ref ex" style=" font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:note[@type='contemporary']) and parent::tei:del">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref ex del" style="color: darkslateblue; font-style: italic;">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:rs and not(ancestor::tei:add)">
				<a href="javascript:void(0)" id="{$id}" class="rs-ref ex" onclick="showInlineAnnotation(this, '{$ref}');">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:rs and ancestor::tei:add">
				<a href="javascript:void(0)" id="{$id}" class="rs-ref ex" onclick="showInlineAnnotation(this, '{$ref}');">
					<xsl:apply-templates/>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="parent::tei:del">
						<span class="ex del">
							<xsl:apply-templates/>
						</span>
					</xsl:when>
					<xsl:otherwise>
						<span class="ex">
							<xsl:apply-templates/>
						</span>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="tei:del">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:choose>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:rs)">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:rs[not(@type='symbol')]">
				<a href="javascript:void(0)" id="{$id}" class="rs-ref del" onclick="showInlineAnnotation(this, '{$ref}');">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
			</xsl:when>
			<xsl:when test="ancestor::tei:term">
				<a href="javascript:void(0)" id="{$id}" class="rs-ref del" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
			</xsl:when>
			<xsl:otherwise>
				<span class="del">
					<xsl:apply-templates/>
				</span>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:del[parent::tei:note[@type='contemporary']]/text()"><!--Sonderregel für 14.5.1635 (Z. 1853)-->
		<span class="del">
			<xsl:value-of select="."/>
		</span>
	</xsl:template>
	
	<xsl:template match="tei:subst">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:apply-templates>
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="ref" select="$ref"/>
			<xsl:with-param name="lemma-gloss-id" select="$lemma-gloss-id"/>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="tei:unclear">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:choose>
			<xsl:when test="ancestor::tei:rs">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:term">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">					
					<xsl:apply-templates>
						<xsl:with-param name="lemma-gloss-id" select="$lemma-gloss-id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and not(parent::tei:del)">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<span id="unclear">[<xsl:apply-templates/>]</span>
			</xsl:otherwise>
		</xsl:choose>		
	</xsl:template>


	<xsl:template match="//*[@rend='line']">
		<hr class="line" align="left"/>
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="tei:add">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:choose>
			<xsl:when test="not(@place)">
				<xsl:apply-templates>
					<xsl:with-param name="id" select="$id"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:del) and not(ancestor::tei:rs)">
				<xsl:text>&lt;</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:rs)">
				<xsl:text>&lt;</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:foreign and ancestor::tei:del">
				<xsl:text>&lt;</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:rs">
				<xsl:text>&lt;</xsl:text>
				<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
						<xsl:with-param name="ref" select="$ref"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:term">
				<xsl:text>&lt;</xsl:text>				
				<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
					<xsl:value-of select="normalize-space(.)"/>
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>&lt;</xsl:text>
				<xsl:apply-templates/>
				<xsl:text>&gt;</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:add][ancestor::tei:rs]">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">
			<xsl:value-of select="."/>		
		</a>
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:add[@place]][ancestor::tei:foreign][not(ancestor::tei:rs)]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:del][ancestor::tei:foreign][not(ancestor::tei:rs)]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:w][ancestor::tei:corr][ancestor::tei:foreign][not(ancestor::tei:rs)]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
			<xsl:value-of select="normalize-space(.)"/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:expan][ancestor::tei:rs]">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">
			<xsl:value-of select="."/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:add[@place]][ancestor::tei:foreign][ancestor::tei:del][not(ancestor::tei:rs)]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:add[@place]][ancestor::tei:foreign][ancestor::tei:ref[@type='biblical']][not(ancestor::tei:ex)][not(ancestor::tei:note[@type='footnote'])]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>		
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:unclear][ancestor::tei:rs]">
		<xsl:value-of select="."/>		
	</xsl:template>
	
	<xsl:template match="text()[parent::tei:damage][ancestor::tei:rs | ancestor::tei:term]">
		<xsl:value-of select="."/>		
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:term[not(parent::tei:index)]][parent::tei:w]">
		<xsl:param name="lemma-gloss-id"/>
		<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
			<xsl:value-of select="normalize-space(.)"/>
		</a>
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:term[not(parent::tei:index)]][following-sibling::tei:w]">
		<xsl:param name="lemma-gloss-id"/>
		<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
	
	<xsl:template match="text()[ancestor::tei:term[not(parent::tei:index)]][preceding-sibling::tei:w]">
		<xsl:param name="lemma-gloss-id"/>
		<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
	
	<xsl:template match="tei:damage">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:param name="lemma-gloss-id"/>
		<xsl:choose>
			<xsl:when test="ancestor::tei:rs">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">					
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="ancestor::tei:term">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
					<xsl:apply-templates/>
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:when test="parent::tei:foreign">
				<xsl:text>[</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>]</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>[</xsl:text>
				<xsl:apply-templates/>
				<xsl:text>]</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<!-- hochgestellte einzelne Buchstaben -->
	<!--deprecated s. unter hi, vorerst noch drin lassen, falls noch versehentlich so kodiert wird, 15.06.23 MG-->
	<xsl:template match="tei:c[@rend='super']">
		<xsl:param name="id"/>
		<xsl:choose>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:rs)">
				<sup>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				</sup>
			</xsl:when>
			<xsl:otherwise>
				<sup>
					<xsl:apply-templates/>
				</sup>
			</xsl:otherwise>
		</xsl:choose>		
	</xsl:template>


	<!-- Tabellen -->

	<xsl:template match="tei:table">
		<table>			
			<tbody>
				
				<xsl:for-each select="tei:row[following-sibling::tei:milestone[1][@rend='line']]">
					<tr class="sum">
						<xsl:for-each select="tei:row">
							<td class="sum">
								<xsl:apply-templates/>
							</td>
						</xsl:for-each>
					</tr>
				</xsl:for-each>
				<xsl:apply-templates/>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template match="tei:cell">
		<xsl:element name="td">
			<xsl:if test="@style='right'">
				<xsl:attribute name="style">text-align:right</xsl:attribute>
			</xsl:if>
			<xsl:if test="@style='center'">
				<xsl:attribute name="style">text-align:center</xsl:attribute>
			</xsl:if>
			<xsl:if test="@cols">
				<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
			</xsl:if>
			<xsl:if test="@rows">
				<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>
		
	<xsl:template match="tei:row"><!--[not(local-name(following-sibling::*[1])='milestone')]-->
		<tr>
			<xsl:if test="@role='sum'">
				<xsl:attribute name="class">sum</xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</tr>	
	</xsl:template>

	<!--body-->
	<!-- main distribution-->
	
	<xsl:template match="tei:ab">
		<div class="row">
		<xsl:for-each select="tei:cb">
			<div class="column">
				<xsl:apply-templates select="following-sibling::node()[preceding-sibling::tei:cb[1]/@n = current()/@n][not(self::tei:cb)]"/>
			</div>				
		</xsl:for-each>
		</div>
	</xsl:template>
	
	<xsl:template match="tei:div[not(@type='footnotes' or descendant::tei:cb)]">		
		<div>
			<xsl:apply-templates/>
		</div>				
	</xsl:template>
	
		
	<!--    Ueberschriften-->

	<xsl:template match="tei:head">

		<xsl:if test="@xml:id[starts-with(.,'org') or starts-with(.,'ue')]">
			<a name="{@xml:id}">
				<xsl:text> </xsl:text>
			</a>
		</xsl:if>
		<a>
			<xsl:attribute name="name">
				<xsl:text>hd</xsl:text>
				<xsl:number level="any"/>
			</xsl:attribute>
			<xsl:text> </xsl:text>
			
		</a>
		<a>
			<xsl:attribute name="name">
				<xsl:value-of select="concat(substring(ancestor::tei:div[@type='entry']/@xml:id, 6), '_', preceding::tei:pb[position() = 1]/@n)"/>
			</xsl:attribute>
			<xsl:text> </xsl:text>			
		</a>
		<h2 style="background-color:#EEE;padding:0.3em;margin-top:1em;position:relative;margin-left:-100px;">
			<div style="position:relative;width:90%;margin-left:100px;">
				<xsl:apply-templates/>
			</div>
			<div style="position:absolute;right:1.5em;top:0.2em;font-weight:900;">
				<a href="#">↑</a>
			</div>
		</h2>
	</xsl:template>



	<!-- pysical pages     -->
	<xsl:template match="tei:pb">
		<xsl:variable name="url" select="concat($server,substring-before(substring(@facs,2),'_'),'/',translate(substring-before(substring-after(substring(@facs,2),'_'),'_'), '_', '/'),'/start.htm?distype=imgs&amp;image=',substring-after(substring-after(substring(@facs,2),'_'),'_'))"/>
		
		<xsl:if test="parent::tei:w">
			<xsl:text>-</xsl:text>
		</xsl:if>
		<!--    <div class="pagebreak"> -->
		<xsl:text> || </xsl:text>
		<xsl:text> [</xsl:text>
		<xsl:choose>
			<xsl:when test="@facs">
				<a>
					<xsl:attribute name="href">
						<xsl:choose>
							<xsl:when test="@facs">
								<xsl:value-of select="$url"/>
							</xsl:when>
							<xsl:when
								test="document($metsfile)//mets:file[@ID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@FILEID]/mets:FLocat/@xlink:href">
								<xsl:value-of
									select="document($metsfile)//mets:file[@ID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@FILEID]/mets:FLocat/@xlink:href"/>
								<xsl:text>&amp;image=</xsl:text>
								<xsl:value-of select="substring-after(substring-after(substring(@facs,2),'_'),'_')"/>
							</xsl:when>
							<xsl:when
								test="starts-with(document($metsfile)//mets:file[@ID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@FILEID]/mets:FLocat/@xlink:href,'http:')">
								<xsl:value-of
									select="document($metsfile)//mets:file[@ID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@FILEID]/mets:FLocat/@xlink:href"/>
								<xsl:text>&amp;image=</xsl:text>
								<xsl:value-of select="substring-after(substring-after(substring(@facs,2),'_'),'_')"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$content"/>
								<xsl:text>?dir=</xsl:text>
								<xsl:value-of select="$dir"/>
								<xsl:text>&amp;xml=</xsl:text>
								<xsl:value-of
									select="document($metsfile)//mets:file[@ID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@FILEID]/mets:FLocat/@xlink:href"/>
								<xsl:text>&amp;xsl=</xsl:text>
								<xsl:value-of
									select="document($metsfile)//mets:behavior[@STRUCTID=document($metsfile)//mets:div[@ID=$pvID]/mets:fptr/mets:par/mets:area[2]/@ID]/mets:mechanism/@xlink:href"/>
								<xsl:text>#</xsl:text>
								<xsl:value-of select="substring(@facs,2)"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					<xsl:attribute name="target">
						<!--<xsl:text>display2</xsl:text>-->
						<xsl:text>_blank</xsl:text>
					</xsl:attribute>
					<xsl:attribute name="name">
						<xsl:value-of select="concat(substring(ancestor::tei:div[@type='entry']/@xml:id, 6), '_', @n)"/>
					</xsl:attribute>
					<xsl:choose>
						<xsl:when test="@n">
							<xsl:text>[Handschrift: </xsl:text>
							<xsl:value-of select="@n"/>
							<xsl:text>]</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="substring-after(substring-after(substring(@facs,2),'_'),'_')"/>
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>-</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:text>] </xsl:text>
	</xsl:template>

	<!--    Links -->
	<xsl:template match="tei:ref">
		<xsl:param name="caption"/>
		<xsl:choose>

<!-- Bibelstellen, klassische Werke, Rechtsquellen -->
			
			<xsl:when test="@type='biblical' and @cRef">
				<xsl:apply-templates select="self::tei:ref"/>		
			</xsl:when>
			<xsl:when test="@type='classical'">
				<xsl:apply-templates/>
			</xsl:when>
			<xsl:when test="@type='medieval'">
				<xsl:apply-templates/>
			</xsl:when>
			
			<!-- Einfügen eines Spatiums vor <ref>, bisher nur in der einleitung.xsl realisiert -->
			<!--<xsl:otherwise>
				<xsl:if test="substring(preceding-sibling::text()[1],
					string-length(preceding-sibling::text()[1]) - 1) = ' ' or parent::tei:bibl">
					<xsl:text> </xsl:text>
				</xsl:if>
				<a>
					<xsl:attribute name="href">
						<xsl:value-of select="@target"/>
					</xsl:attribute>
					<xsl:value-of select="."/>
				</a>
			</xsl:otherwise>
		</xsl:choose>-->
			
			<xsl:otherwise>
				<a href="{@target}" target="_blank">
					<xsl:apply-templates/>
				</a>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:ref[@type='biblical']">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:variable name="number">
			<xsl:number level="any" count="tei:note[@type ='footnote'] | tei:ref[@type='biblical'][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="ancestor::tei:foreign and not(ancestor::tei:note)">	
				<xsl:apply-templates>
					<xsl:with-param name="id" select="$id"/>
				</xsl:apply-templates>				
			</xsl:when>
			<xsl:when test="ancestor::tei:note[@type='footnote' or @type='annotation']">
				<a>
					<xsl:choose>
						<!--<xsl:when test="contains(@cRef,'Iob')">
							<xsl:attribute name="href">
								<xsl:text>javascript:window.open('</xsl:text>
								<xsl:value-of select="$cRef-biblical-start"/>
								<xsl:value-of select="translate(replace(@cRef,'Iob','Hiob'),' _,','++: ')"/>
								<xsl:text>&amp;id12=1&amp;set=1&amp;l=fr</xsl:text>
								<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
							</xsl:attribute>
						</xsl:when>-->
						<xsl:when test="@subtype='lu45'">
							<xsl:attribute name="href">
								<xsl:text>javascript:window.open('</xsl:text>
								<xsl:value-of select="$cRef-biblical-start"/>
								<xsl:value-of select="translate(@cRef,' _,','++: ')"/>								
								<xsl:text>&amp;id12=1&amp;set=1&amp;l=fr</xsl:text>
								<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
							</xsl:attribute>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="href">
								<xsl:text>javascript:window.open('</xsl:text>
								<xsl:value-of select="$cRef-biblical-start"/>
								<xsl:value-of select="translate(@cRef,' _,','++: ')"/>
								<xsl:value-of select="$cRef-biblical-end_de"/>
								<xsl:text>&amp;l=fr</xsl:text>
								<xsl:value-of select="@xml:id"/><xsl:text>', "Zweitfenster", "width=1200, height=450, top=300, left=50").focus();</xsl:text>
							</xsl:attribute>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:value-of select="."/>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>		
		<xsl:if test="not(ancestor::tei:note[@type='footnote' or @type='annotation'])">
			<span id="fna{$number}">
				<a href="#fn{$number}">
					<xsl:choose>
						<xsl:when test="ancestor::tei:note[@type='contemporary']">
							<xsl:attribute name="style">
								<xsl:text>font-size:7pt;vertical-align:super;color:blue;</xsl:text>
							</xsl:attribute>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="style">
								<xsl:text>font-size:9pt;vertical-align:super;color:blue;</xsl:text>
							</xsl:attribute>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:choose>
						<xsl:when test="starts-with(@cRef, '1') or starts-with(@cRef, '2') or starts-with(@cRef, '3') or starts-with(@cRef, '4')">
							<xsl:attribute name="title">
								<xsl:value-of select="substring-before(@cRef, '_')"/>
								<xsl:text>. </xsl:text>
								<xsl:value-of select="translate(substring-after(@cRef, '_'),'_',' ')"/>
								<xsl:text>.</xsl:text>
							</xsl:attribute>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="title">
								<xsl:choose>
									<xsl:when test="contains(@cRef, '_')">
										<xsl:value-of select="substring-before(@cRef, '_')"/>
										<xsl:text> </xsl:text>
										<xsl:value-of select="substring-after(@cRef, '_')"/>
										<xsl:text>.</xsl:text>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="@cRef"/>
										<xsl:text>.</xsl:text>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:attribute>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:value-of select="$number" />
				</a>
			</span>
		</xsl:if>
	</xsl:template>

	<xsl:template match="tei:ptr">
		<xsl:apply-templates/>
		<xsl:choose>
			<xsl:when test="@type='google_books'"> [<a href="javascript:show_annotation_html('{$dir}','{@target}',400,600)">Google Books</a>] </xsl:when>
			<xsl:when test="starts-with(@target,'http://')"> [<a href="{@target}" target="_blank">Link</a>] </xsl:when>
			<xsl:when test="@type='opac' "> [<a href="{normalize-space(concat($opac,@cRef))}" target="_blank">Nachweis im OPAC</a>] </xsl:when>
			<xsl:when test="@type='gbv' "> [<a href="{normalize-space(concat($gbv,@cRef))}" target="_blank">Nachweis im GBV</a>] </xsl:when>
			<xsl:when test="@type='GettyThesaurus' "> [<a href="{normalize-space(concat($GettyThesaurus,(substring-after(@target, '#TGN_'))))}" target="_blank">TGN</a>] </xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<!-- Übersetzungen: Transformation als aufschiebbares Fenster analog zu Personen und Orten -->
	
	<xsl:template match="tei:foreign">
		<xsl:variable name="id" select="generate-id()"/>
		<span style="display:none;" id="{$id}">
			<xsl:apply-templates select="following-sibling::tei:note[@type='translation'][1]/node()"/>
		</span>
		<xsl:apply-templates>
			<xsl:with-param name="id" select="$id"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="tei:foreign/text() | tei:w[ancestor::tei:foreign][not(ancestor::tei:choice)][not(ancestor::tei:term)]/text() | tei:foreign/tei:choice">
		<xsl:param name="id"/>
		<xsl:choose>
			<xsl:when test="parent::tei:foreign/parent::tei:del">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
					<xsl:choose>
						<xsl:when test="ancestor::tei:w">
							<xsl:choose>
								<xsl:when test="preceding-sibling::tei:ex">
									<xsl:value-of select="."/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="normalize-space(.)"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="self::tei:choice">
							<xsl:apply-templates>
								<xsl:with-param name="id" select="$id"/>
							</xsl:apply-templates>
						</xsl:when>						
						<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
					</xsl:choose>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="parent::tei:w/parent::tei:del">
						<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
							<xsl:choose>
								<xsl:when test="ancestor::tei:w">
									<xsl:choose>
										<xsl:when test="preceding-sibling::tei:ex">
											<xsl:value-of select="."/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="normalize-space(.)"/>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="self::tei:choice">
									<xsl:apply-templates>
										<xsl:with-param name="id" select="$id"/>
									</xsl:apply-templates>
								</xsl:when>
								<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
							</xsl:choose>
						</a>
					</xsl:when>
					<xsl:otherwise>
						<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
							<xsl:choose>
								<xsl:when test="ancestor::tei:w">
									<xsl:choose>
										<xsl:when test="preceding-sibling::tei:ex">
											<xsl:value-of select="."/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="normalize-space(.)"/>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="self::tei:choice">
									<xsl:apply-templates>
										<xsl:with-param name="id" select="$id"/>
									</xsl:apply-templates>
								</xsl:when>
								<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
							</xsl:choose>
						</a>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:otherwise>
		</xsl:choose>
		
	</xsl:template>
	
	<xsl:template match="tei:foreign/tei:del/text()[ancestor::tei:rs[not(@type='symbol')]]">
		<xsl:param name="id"/>
		<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref del" style="color: darkslateblue;">
			<xsl:value-of select="."/>
		</a>
	</xsl:template>		
		
	<xsl:template match="tei:note">
		<xsl:param name="caption"/>
		<!--  zwei Typen: entweder Fussnoten am Text- oder Seitenende in einem besonderen Abschnitt oder in den Text integriert -->
		<xsl:choose>
			<xsl:when test="$caption ='true'">
				<!-- keine Anzeige -->
			</xsl:when>
			<xsl:when test="@type='footnote'">
				<xsl:variable name="number">
					<xsl:number level="any" count="tei:note[@type ='footnote'] | tei:ref[@type='biblical'][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]"/>
				</xsl:variable>
				<!--  in Text integriert, nur Verweis , Fussnotenabschnitt mit foreach generiert -->
				<xsl:choose>
					<xsl:when test="ancestor::tei:note[@type='contemporary']">
						<a name="fna{$number}" href="#fn{$number}" title="{normalize-space(.)}" style="font-size:7pt;vertical-align:super;color:blue;">
							<xsl:if test="..//tei:ref[@type='biblical'][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
								<xsl:text> </xsl:text>
							</xsl:if>
							<xsl:value-of select="$caption"/>
							<xsl:value-of select="$number"/>
						</a>
					</xsl:when>
					<xsl:otherwise>
						<a name="fna{$number}" href="#fn{$number}" title="{normalize-space(.)}" style="font-size:9pt;vertical-align:super;color:blue;">
							<xsl:if test="..//tei:ref[@type='biblical'][not(ancestor::tei:note[@type='footnote' or @type='annotation'])]">
								<xsl:text> </xsl:text>
							</xsl:if>
							<xsl:value-of select="$caption"/>
							<xsl:value-of select="$number"/>
						</a>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="@type='annotation'">
				<xsl:variable name="number">
					<xsl:call-template name="fnnumber" />
				</xsl:variable>
				<!--  in Text integriert, nur Verweis , Fussnotenabschnitt mit foreach generiert -->
				<a name="ana{$number}" href="#an{$number}" title="{normalize-space(.)}" style="font-size:9pt;vertical-align:super;color:blue;">
					<xsl:value-of select="$number" />
				</a>
			</xsl:when>
			<xsl:otherwise/>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:name">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="tei:date">
		<xsl:apply-templates/>
	</xsl:template>

	<!-- Grafiken -->
	<xsl:template match="tei:graphic">
<!--		<img border="0" style="vertical-align: sub; height:22px;" src="{@url}"></img>-->
		<div style="position:relative; z-index:1;">			
			<div style="float:left;">
				<img border="0" style="height:200px; padding-right:15px;" src="{@url}"></img>
			</div>
		</div>

	</xsl:template>
	
	<xsl:template match="tei:index"/> 

	<xsl:template match="tei:quote | tei:q">
		<xsl:param name="id"/>
		<xsl:if test="@xml:id[starts-with(.,'org') or starts-with(.,'ue')]">
			<a name="{@xml:id}">
				<xsl:text> </xsl:text>
			</a>
		</xsl:if>
		<xsl:choose>
			<xsl:when test="ancestor::tei:foreign">
				<xsl:text>&lt;</xsl:text>
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')" class="rs-ref" style="color: darkslateblue;">
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>					
				</a>
				<xsl:text>&gt;</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
				
	</xsl:template>
	
	<xsl:template match="tei:bibl[ancestor::tei:cit]">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="tei:hi | tei:rs/tei:hi">
		<xsl:param name="id"/>
		<xsl:variable name="style">
				<xsl:choose>
					<xsl:when test="@rend ='italic'">
						<xsl:text>font-style:italic;</xsl:text>
					</xsl:when>
					<xsl:when test="@rend ='underline'">
						<xsl:text>text-decoration:underline</xsl:text>
					</xsl:when>
					<xsl:when test="@rend ='underline_dotted'">
						<xsl:text>border-bottom: 2px dotted</xsl:text>
					</xsl:when>
					<xsl:when test="@rend ='bold'">
						<xsl:text>font-weight:bold</xsl:text>
					</xsl:when>
					<xsl:when test="@rend ='super'">
						<xsl:text>vertical-align:super;</xsl:text>
					</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:if test="@xml:id[starts-with(.,'org') or starts-with(.,'ue')]">
			<a name="{@xml:id}">
				<xsl:text> </xsl:text>
			</a>
		</xsl:if>		
		<xsl:choose>
			<xsl:when test="ancestor::tei:foreign">
				<a href="javascript:void(0);" onclick="showInlineAnnotation(this, '#{$id}')">
					<xsl:attribute name="style">
						<xsl:text>color: darkslateblue; </xsl:text>
						<xsl:value-of select="$style"/>
					</xsl:attribute>
					<xsl:attribute name="class">
						<xsl:text>rs-ref</xsl:text>
						<xsl:if test="ancestor::tei:del">
							<xsl:text> del</xsl:text>
						</xsl:if>
					</xsl:attribute>
					<xsl:apply-templates>
						<xsl:with-param name="id" select="$id"/>
					</xsl:apply-templates>
				</a>
			</xsl:when>	
			<xsl:otherwise>
				<span>
					<xsl:attribute name="style">
						<xsl:value-of select="$style"/>
					</xsl:attribute>
					<xsl:apply-templates/>
				</span>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- hier ggf ausschalten 
       <xsl:template match="tei:lb">
           <xsl:if test="not(@rend) or @rend !='trennstrich'">
               
               <xsl:text> </xsl:text>
            </xsl:if>
         </xsl:template>-->

	<!--<xsl:template match="tei:lb">
        <xsl:choose>
            <xsl:when test="$lokal != 'orig'">
                <xsl:choose>
                    <xsl:when test="@type='hy'">
                        <span>&#8209;<br/></span>
                    </xsl:when>
                    <xsl:otherwise>
                        <br/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                    <xsl:when test="@n">
                        <span style="position:relative;left:-0.5em;font-size:small;">(<xsl:value-of
                                select="@n"/>)</span>
                    </xsl:when>
                    <xsl:otherwise> </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
        </xsl:choose>
        <xsl:apply-templates/>
    </xsl:template>-->

	<xsl:template match="tei:p | tei:seg">
		<p>
			<xsl:call-template name="SegP"/>
		</p>
	</xsl:template>

	<xsl:template name="SegP">
		
		<!-- br erzeugt Leerzeile oberhalb jedes Absatzes; Problem: auch oberhalb von Tabellen -->
		<!--<br/>-->
		<xsl:if test="@xml:id[starts-with(.,'org') or starts-with(.,'ue')]">
			<a name="{@xml:id}">
				<xsl:text> </xsl:text>
			</a>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="exist:match">

		<xsl:variable name="divNo">
			<xsl:number count="tei:div" level="any"/>
		</xsl:variable>

		<xsl:variable name="hitNo">
			<xsl:number level="multiple"/>
		</xsl:variable>

		<xsl:variable name="hitNoAll">
			<xsl:number level="any"/>
		</xsl:variable>
		<a name="hit{$divNo}_{$hitNo}">
			<xsl:text> </xsl:text>
		</a>
		<a name="hit{$hitNoAll}">
			<xsl:text> </xsl:text>
		</a>
		<span style="background-color:yellow;">
			<xsl:apply-templates/>
		</span>
		<xsl:if test="$hitNoAll &gt; 1">
			<!--<p><xsl:value-of select="count(//exist:match)"/> _<xsl:value-of select="$hitNo"/></p>-->
			<xsl:text> [</xsl:text>
			<a href="#hit{$hitNoAll - 1}" style="font-weight:900;font-size:larger;" title="voriger Treffer">
				<xsl:text>←</xsl:text>
			</a>
			<xsl:text>]</xsl:text>
		</xsl:if>
		<xsl:if test="$hitNoAll &lt; count(//exist:match)">
			<!--<p><xsl:value-of select="count(//exist:match)"/> _<xsl:value-of select="$hitNo"/></p>-->
			<xsl:text> [</xsl:text>
			<a href="#hit{$hitNoAll + 1}" style="font-weight:900;font-size:larger;" title="nächster Treffer">
				<xsl:text>→</xsl:text>
			</a>
			<xsl:text>]</xsl:text>
		</xsl:if>
	</xsl:template>


	<xsl:template match="tei:term[not(parent::tei:index[@indexName='regest'])]">
		<xsl:variable name="lemma-gloss-id">
			<xsl:call-template name="lemma-gloss-id">
				<xsl:with-param name="lemma-id" select="substring(@ref, 1)"/>
				<xsl:with-param name="gloss-n" select="@n"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:choose>
			<xsl:when test="descendant::tei:pb">
				<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
					<xsl:value-of select="normalize-space(descendant::text()[following-sibling::tei:lb])"/>
				</a>
				<xsl:apply-templates select="descendant::tei:pb"/>
				<br/>
				<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
					<xsl:value-of select="descendant::text()[preceding-sibling::tei:lb]"/>
				</a>
			</xsl:when>
			<xsl:when test="descendant::tei:w">
				<!--<xsl:if test="descendant::text()[following-sibling::tei:w]">
					<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
						<xsl:value-of select="normalize-space(descendant::text()[following-sibling::tei:w])"/>
					</a>
				</xsl:if>-->
				<xsl:apply-templates>
					<xsl:with-param name="lemma-gloss-id" select="$lemma-gloss-id"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates>
					<xsl:with-param name="lemma-gloss-id" select="$lemma-gloss-id"/>
				</xsl:apply-templates>
				
				<!--<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
					<xsl:apply-templates/>
				</a>-->
			</xsl:otherwise>
		</xsl:choose>	
	</xsl:template>
	
	<xsl:template match="tei:term[not(parent::tei:index[@indexName='regest'])]/text()">
		<xsl:param name="lemma-gloss-id"/>
		<a href="javascript:void(0)" class="rs-ref" onclick="showInlineAnnotation(this, '{$lemma-gloss-id}');">
			<xsl:choose>
				<xsl:when test="ancestor::tei:w"><xsl:value-of select="normalize-space(.)"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
			</xsl:choose>
		</a>
	</xsl:template>

	<xsl:template match="tei:rs">
		<xsl:variable name="id" select="generate-id()"/>
		<xsl:choose>
			<xsl:when test="@ref=concat('#',$q)">
				<xsl:variable name="hitNo">
					<xsl:number level="any" count="tei:rs[@ref=concat('#',$q)]"/>
				</xsl:variable>
				<a name="hit{$hitNo}">
					<xsl:text> </xsl:text>
				</a>
				<span style="background-color:yellow;">
					<xsl:choose>
						<xsl:when test="@type='person'">
							<a href="{substring(@ref,2)}">
								<xsl:apply-templates/>
							</a>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates/>
						</xsl:otherwise>
					</xsl:choose>
				</span>
				<xsl:if test="$hitNo &gt; 1">
					<xsl:text> [</xsl:text>
					<a href="#hit{$hitNo - 1}" style="font-weight:900;font-size:larger;" title="voriger Treffer">
						<xsl:text>←</xsl:text>
					</a>
					<xsl:text>]</xsl:text>
				</xsl:if>
				<xsl:if test="$hitNo &lt; count(//tei:rs[@ref=concat('#',$q)])">
					<xsl:text> [</xsl:text>
					<a href="#hit{$hitNo + 1}" style="font-weight:900;font-size:larger;" title="nächster Treffer">
						<xsl:text>→</xsl:text>
					</a>
					<xsl:text>]</xsl:text>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="@type='abbreviation'">
						<xsl:choose>
							<xsl:when test="ancestor::tei:del">
								<a class="tooltip del">
									<span class="custom info">
										<xsl:value-of select="//tei:list/tei:item[@xml:id =substring(current()/@ref,2)]/*[position()=1]"/>
									</span>
									<xsl:apply-templates/>
								</a>								
							</xsl:when>
							<xsl:otherwise>
								<a class="tooltip">
									<span class="custom info">
										<xsl:value-of select="//tei:list/tei:item[@xml:id =substring(current()/@ref,2)]/*[position()=1]"/>
									</span>
									<xsl:apply-templates/>
								</a>
							</xsl:otherwise>
						</xsl:choose>						
					</xsl:when>
					<xsl:when test="@type='symbol'">
						<xsl:choose>
							<xsl:when test="ancestor::tei:del">
								<a class="tooltip del">
									<span class="custom info">
										<xsl:value-of select="//tei:list/tei:item[@xml:id =substring(current()/@ref,2)]/*"/>
									</span>
									<xsl:choose>
										<xsl:when test="starts-with(@ref,'#symbol_')">
											<img border="0" style="vertical-align: sub; height:22px;" src="http://diglib.hab.de/edoc/ed000228/bilder_symbole/{substring(@ref,2)}.png"></img>
										</xsl:when>
										<xsl:otherwise>
											<xsl:apply-templates/>
										</xsl:otherwise>
									</xsl:choose>
								</a>
							</xsl:when>
							<xsl:otherwise>
								<a class="tooltip">
									<span class="custom info">
										<xsl:value-of select="//tei:list/tei:item[@xml:id =substring(current()/@ref,2)]/*"/>
									</span>
									<xsl:choose>
										<xsl:when test="starts-with(@ref,'#symbol_')">
											<img border="0" style="vertical-align: sub; height:25px;" src="http://diglib.hab.de/edoc/ed000228/bilder_symbole/{substring(@ref,2)}.png"></img>
										</xsl:when>
										<xsl:otherwise>
											<xsl:apply-templates/>
										</xsl:otherwise>
									</xsl:choose>
								</a>
							</xsl:otherwise>
						</xsl:choose>
						
					</xsl:when>

					<xsl:when test="@type='person' or @type='place' or @type='org' or @type='bibl'">
						<xsl:choose>
							<xsl:when test="parent::tei:note[ancestor::tei:person or ancestor::tei:place or ancestor::tei:org or ancestor::tei:bibl]">
								<xsl:value-of select="."/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:apply-templates>
									<xsl:with-param name="id" select="$id"/>
									<xsl:with-param name="ref" select="@ref"/>
								</xsl:apply-templates>
							</xsl:otherwise>
						</xsl:choose>						
					</xsl:when>
					
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>

	</xsl:template>

	
	<xsl:template match="tei:rs[@type='person' or @type='place' or @type='org' or @type='bibl']/text()
		| tei:w[parent::tei:rs[@type='person' or @type='place' or @type='org' or @type='bibl']]/text()">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<a href="javascript:void(0)" id="{$id}" class="rs-ref" onclick="showInlineAnnotation(this, '{$ref}');">
				<xsl:choose>
					<xsl:when test="ancestor::tei:w"><xsl:value-of select="normalize-space(.)"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
			</xsl:choose>
		</a>
	</xsl:template>	
	
	<!-- Templateregel zur Erzeugung eines Index-Registers am Seitenende, das via css ausgeblendet wird -->

	<!-- Lemma im Glossar, das im Text referenziert wird -->
	<!--<xsl:template match="tei:item[key('term-ref', @xml:id)]" mode="gloss">-->
	<xsl:template match="tei:item" mode="gloss">
		<xsl:variable name="label" select="tei:label"/>
		<xsl:variable name="lemma-id" select="@xml:id"/>
		<xsl:for-each select="tei:list/tei:item">
			<xsl:variable name="id">
				<xsl:call-template name="lemma-gloss-id">
					<xsl:with-param name="lemma-id" select="$lemma-id"/>
					<xsl:with-param name="gloss-n" select="@n"/>
				</xsl:call-template>
			</xsl:variable>
			<div id="{$id}">
				<b>
					<xsl:value-of select="$label"/>
				</b>
				<br/>
				<i>
					<xsl:value-of select="."/>
				</i>
			</div>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="text()" mode="gloss"/>

	<!-- ID einer Glosse im Ausgabedokument: f(Lemma-ID, Zählung Glosse) -->
	<xsl:template name="lemma-gloss-id">
		<xsl:param name="lemma-id"/>
		<xsl:param name="gloss-n"/>
		<xsl:choose>
			<xsl:when test="contains($lemma-id,' ')">
				<xsl:value-of select="substring-before($lemma-id,' ')"/>
				<xsl:text>_1 </xsl:text>
				<xsl:value-of select="substring-after($lemma-id,' ')"/>				
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$lemma-id"/>
			</xsl:otherwise>
		</xsl:choose>		
		<xsl:text>_</xsl:text>
		<xsl:choose>
			<xsl:when test="string-length($gloss-n) &gt; 0">
				<xsl:value-of select="$gloss-n"/>
			</xsl:when>
			<xsl:otherwise>1</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template match="tei:person">
		<xsl:call-template name="format-person"/>
	</xsl:template>

	<!-- Wird mit einem tei:person als Kontextknoten aufgerufen und liefert eine für die Anzeige vorbereitete Übersicht zur Person -->
	<xsl:template name="format-person">
		<div id="{@xml:id}">
			<xsl:attribute name="class">
				<xsl:text>rs-ref</xsl:text>
			</xsl:attribute>


			<!-- TBD -->

			<xsl:for-each select="tei:persName">
				<div>
					<xsl:if test="@type='birthName'">Geburtsname: </xsl:if>
					<!-- falls nur <name> -->
					<xsl:if test="tei:name">
						<span>
							<b>
								<xsl:value-of select="tei:name/."/>
							</b>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- Rollenname -->
					<xsl:if test="tei:roleName">
						<span class="roleName">
							<xsl:value-of select="tei:roleName/."/>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- Vorname -->
					<xsl:if test="tei:forename">
						<span class="forename">
							<b>
								<xsl:value-of select="tei:forename/."/>
							</b>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- Namelink -->
					<xsl:if test="tei:nameLink">
						<span class="nameLink">
							<xsl:value-of select="tei:nameLink/."/>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- Nachname -->
					<xsl:if test="tei:surname">
						<span class="surname">
							<xsl:value-of select="tei:surname/."/>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- addName -->
					<xsl:if test="tei:addName">
						<span>
							<xsl:value-of select="tei:addName/."/>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>

					<!-- Placename -->
					<xsl:if test="tei:placeName">
						<span class="placeName">
							<xsl:value-of select="tei:placeName/."/>
						</span>
						<xsl:text> </xsl:text>
					</xsl:if>


				</div>
			</xsl:for-each>

			<!-- Sonstiges zur Person -->
			<xsl:if test="tei:birth">
				<br/>
				<xsl:text>geb. </xsl:text>
				<span class="birth">
					<xsl:value-of select="tei:birth"/>
				</span>
			</xsl:if>
			<xsl:if test="tei:death">
				<br/>
				<xsl:text>gest. </xsl:text>
				<span class="death">
					<xsl:value-of select="tei:death"/>
				</span>
			</xsl:if>
			<xsl:if test="tei:note">
				<br/>
				<xsl:text>Anm.: </xsl:text>
				<span class="note">
					<xsl:apply-templates select="tei:note"/>
				</span>
			</xsl:if>			

			<xsl:if test="tei:persName[@ref]">
				<br/><br/>
				<xsl:text>Weiterführende Informationen </xsl:text>
				<xsl:choose>
					<xsl:when test="contains(tei:persName/@ref,'viaf')">
						<xsl:text>in </xsl:text>
						<a href="{tei:persName/@ref}" target="_blank">VIAF</a>
					</xsl:when>
					<xsl:when test="contains(tei:persName/@ref,'gnd')">
						<xsl:text>in der </xsl:text>
<!--						<a href="{tei:persName/@ref}" target="_blank">GND</a>-->
						<a href="http://dev.hab.de/beacon/public/index.php?gnd={substring-after(tei:persName[@ref]/@ref,'gnd/')}" target="_blank">MWW-Personensuche</a>
					</xsl:when>
				</xsl:choose>				
			</xsl:if>
			
			<xsl:if test="tei:listBibl/tei:bibl/tei:ptr[@type='adb']">
				<xsl:choose>
					<xsl:when test="not(tei:persName/@ref)">
						<xsl:text>Weiterführende Informationen in der </xsl:text>
						<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='adb']/@target}" target="_blank">ADB</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>, </xsl:text>
						<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='adb']/@target}" target="_blank">ADB</a>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:if>
			
			<xsl:if test="tei:listBibl/tei:bibl/tei:ptr[@type='ndb']">
				<xsl:choose>
					<xsl:when test="not(tei:persName/@ref)">
						<xsl:text>Weiterführende Informationen in der </xsl:text>
						<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='ndb']/@target}" target="_blank">NDB</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>, </xsl:text>
						<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='ndb']/@target}" target="_blank">NDB</a>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if>
			<xsl:if test="tei:listBibl/tei:bibl/tei:ptr[@type='wg']">
				<xsl:text>, </xsl:text>
				<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='wg']/@target}" target="_blank">Westfälische Geschichte</a>
			</xsl:if>
			<xsl:if test="tei:listBibl/tei:bibl/tei:ptr[@type='hb']">
				<xsl:text>, </xsl:text>
				<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='hb']/@target}" target="_blank">Hessische Biographie</a>
			</xsl:if>
			<xsl:if test="tei:listBibl/tei:bibl/tei:ptr[@type='sb']">
				<xsl:text>, </xsl:text>
				<a href="{tei:listBibl/tei:bibl/tei:ptr[@type='sb']/@target}" target="_blank">Sächsische Biographie</a>
			</xsl:if>
			<xsl:if test="tei:persName[@ref] and tei:note/tei:rs[@type='org'][@ref='#fruchtbringende_gesellschaft']">
				<xsl:text>, </xsl:text>
				<a href="{concat('http://dbs.hab.de/padmin/fruchtbringer/ausgabe.php?m4=allgemein&amp;st3=&amp;trunc3=%25&amp;m2=gnd&amp;st2=',substring-after(tei:persName/@ref,'gnd/'),'&amp;trunc2=%25&amp;m1=mitgliedsnr&amp;st1=&amp;trunc1=%25&amp;submit=&amp;m3=name')}" target="_blank">Mitgliederdatenbank Fruchtbringende Gesellschaft</a>
			</xsl:if>
			
		</div>
	</xsl:template>
	
	<xsl:template match="tei:note[parent::tei:person]">
		<xsl:apply-templates/>
	</xsl:template>
	


	
	<xsl:template match="tei:org">
		<xsl:call-template name="format-org"/>
	</xsl:template>
	<!-- Wird mit einem tei:org als Kontextknoten aufgerufen und liefert eine für die Anzeige vorbereitete Übersicht zur Institution -->
	<xsl:template name="format-org">
		<div id="{@xml:id}">
			<xsl:attribute name="class">
				<xsl:text>rs-ref</xsl:text>
			</xsl:attribute>


			<!-- TBD -->

			<xsl:if test="tei:orgName">
				<span class="org">
					<xsl:value-of select="tei:orgName/."/>
					<xsl:if test="tei:orgName[@ref]">
						<br/>
						<a href="{tei:orgName/@ref}" target="_blank">weiterführende Informationen </a>
					</xsl:if>
					<xsl:if test="child::tei:note">
						<br/>
						<xsl:text>Anm.:</xsl:text>
						<xsl:text> </xsl:text>
						<xsl:value-of select="child::tei:note"/>
					</xsl:if>
				</span>
				<xsl:text> </xsl:text>
			</xsl:if>
		</div>
	</xsl:template>

	<xsl:template match="tei:place">
		<xsl:call-template name="format-place"/>
	</xsl:template>
	<!-- Wird mit einem tei:place als Kontextknoten aufgerufen und liefert eine für die Anzeige vorbereitete Übersicht zum Ort -->
	<xsl:template name="format-place">
		<div id="{@xml:id}" class="rs-ref">
			<!-- TBD -->
			<xsl:if test="tei:placeName">
				<span class="placeName">
					<xsl:value-of select="tei:placeName/."/>
					<xsl:if test="tei:placeName[@ref]">
						<br/>
						<a href="{tei:placeName/@ref}" target="_blank">weiterführende Informationen </a>
					</xsl:if>
				</span>
				<xsl:text> </xsl:text>
			</xsl:if>
			<xsl:if test="tei:note">
				<br/>
				<xsl:text>Anm.: </xsl:text>
				<span class="note">
					<xsl:value-of select="tei:note/."/>
				</span>
			</xsl:if>
		</div>
	</xsl:template>
	
	
	
	<!-- Bibliographische Verweise aus dem Literaturverzeichnis -->
	
	<xsl:template match="tei:bibl">
		<xsl:call-template name="format-bibl"/>
	</xsl:template>
	
	<xsl:template name="format-bibl">
		<div id="{@xml:id}" class="rs-ref">
			<xsl:apply-templates select="tei:author"/>
			<xsl:apply-templates select="tei:title"/>
			<xsl:apply-templates select="tei:biblScope[@unit='vol' or @unit='part']"/>
			<xsl:apply-templates select="tei:editor"/>
			<xsl:apply-templates select="tei:pubPlace"/>
			<xsl:apply-templates select="tei:publisher"/>
			<xsl:apply-templates select="tei:date"/>
			<xsl:apply-templates select="tei:biblScope[@unit='pp' or @unit='cols' or @unit='fols']"/>
			<xsl:apply-templates select="tei:series"/>
			<xsl:apply-templates select="tei:title/@ref"/>
		</div>
	</xsl:template>
	
	<xsl:template name="format-name">
		<xsl:choose>
			<xsl:when test="@ref">
				<a target="_blank">
					<xsl:attribute name="href">
						<xsl:text>http://diglib.hab.de/edoc/ed000228/register/listPerson.html</xsl:text>
						<xsl:value-of select="@ref"/>
					</xsl:attribute>
					<xsl:if test="tei:name">
						<span style="font-variant: small-caps;" class="author">
							<xsl:apply-templates select="tei:name"/>
						</span>
					</xsl:if>
					<xsl:if test="tei:roleName">
						<xsl:apply-templates select="tei:roleName"/>
					</xsl:if>
					<xsl:if test="tei:forename">
						<xsl:if test="not(preceding-sibling::tei:roleName)">
							<xsl:text> </xsl:text>
						</xsl:if>
						<xsl:choose>
							<xsl:when test="contains(tei:roleName,'König') or contains(tei:roleName, 'Kaiser') or contains(tei:roleName, 'Papst')">
								<span style="font-variant: small-caps;" class="editor">
									<xsl:apply-templates select="tei:forename"/>
								</span>                                
							</xsl:when>
							<xsl:otherwise> 
								<xsl:apply-templates select="tei:forename"/>                                
							</xsl:otherwise>
						</xsl:choose>
					</xsl:if>
					<xsl:if test="tei:nameLink">
						<xsl:text> </xsl:text>
						<xsl:apply-templates select="tei:nameLink"/>
					</xsl:if>
					<xsl:if test="tei:surname">
						<xsl:text> </xsl:text>
						<xsl:choose>
							<xsl:when test="contains(tei:roleName,'König') or contains(tei:roleName, 'Kaiser')">
								<xsl:apply-templates select="tei:surname"/>
							</xsl:when>
							<xsl:otherwise>
								<span style="font-variant: small-caps;" class="editor">
									<xsl:apply-templates select="tei:surname"/>
								</span>
							</xsl:otherwise>
						</xsl:choose>                        
					</xsl:if>
					<xsl:if test="tei:addName[not(@type='pseudonym')]">
						<xsl:text> </xsl:text>
						<xsl:apply-templates select="tei:addName"/>
					</xsl:if>
					<xsl:if test="tei:addName[@type='pseudonym']">
						<xsl:text> [=</xsl:text>
						<xsl:apply-templates select="tei:addName"/>
						<xsl:text>]</xsl:text>
					</xsl:if>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="tei:name">
					<span style="font-variant: small-caps;" class="author">
						<xsl:apply-templates select="tei:name"/>
					</span>
				</xsl:if>
				<xsl:if test="tei:roleName">
					<xsl:text> </xsl:text>
					<xsl:apply-templates select="tei:roleName"/>
				</xsl:if>
				<xsl:if test="tei:forename">
					<xsl:if test="not(preceding-sibling::tei:roleName)">
						<xsl:text> </xsl:text>
					</xsl:if>
					<xsl:choose>
						<xsl:when test="contains(tei:roleName,'König') or contains(tei:roleName, 'Kaiser') or contains(tei:roleName, 'Papst')">
							<span style="font-variant: small-caps;" class="editor">
								<xsl:apply-templates select="tei:forename"/>
							</span>                                
						</xsl:when>
						<xsl:otherwise> 
							<xsl:apply-templates select="tei:forename"/>                                
						</xsl:otherwise>
					</xsl:choose>
				</xsl:if>
				<xsl:if test="tei:nameLink">
					<xsl:text> </xsl:text>
					<xsl:apply-templates select="tei:nameLink"/>
				</xsl:if>
				<xsl:if test="tei:surname">
					<xsl:text> </xsl:text>
					<xsl:choose>
						<xsl:when test="contains(tei:roleName,'König') or contains(tei:roleName, 'Kaiser')">
							<xsl:apply-templates select="tei:surname"/>
						</xsl:when>
						<xsl:otherwise>
							<span style="font-variant: small-caps;" class="editor">
								<xsl:apply-templates select="tei:surname"/>
							</span>
						</xsl:otherwise>
					</xsl:choose>                        
				</xsl:if>
				<xsl:if test="tei:addName[not(@type='pseudonym')]">
					<xsl:text> </xsl:text>
					<xsl:apply-templates select="tei:addName"/>
				</xsl:if>
				<xsl:if test="tei:addName[@type='pseudonym']">
					<xsl:text> [=</xsl:text>
					<xsl:apply-templates select="tei:addName"/>
					<xsl:text>]</xsl:text>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:editor[not(following-sibling::tei:editor)][not(@role='translator')]">
		<xsl:if test="not(preceding-sibling::tei:editor)">
			<xsl:text>hg. von </xsl:text>
		</xsl:if>
		<xsl:call-template name="format-name"/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:editor[following-sibling::tei:editor][not(@role='translator')]">
		<xsl:if test="not(preceding-sibling::tei:editor)">
			<xsl:text>hg. von </xsl:text>
		</xsl:if>
		<xsl:call-template name="format-name"/>
		<xsl:text> / </xsl:text>        
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:editor[not(following-sibling::tei:editor)][@role='translator']">
		<xsl:if test="not(preceding-sibling::tei:editor[@role='translator'])">
			<xsl:text>übers. von </xsl:text>
		</xsl:if>
		<xsl:call-template name="format-name"/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:editor[following-sibling::tei:editor][@role='translator']">
		<xsl:if test="not(preceding-sibling::tei:editor[@role='translator'])">
			<xsl:text>übers. von </xsl:text>
		</xsl:if>
		<xsl:call-template name="format-name"/>
		<xsl:text> / </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:author[not(following-sibling::tei:author)]">
		<xsl:call-template name="format-name"/>        
		<xsl:text>: </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:author[following-sibling::tei:author]">
		<xsl:call-template name="format-name"/>
		<xsl:text> / </xsl:text>                
	</xsl:template>	
	
	<xsl:template match="tei:bibl//tei:title[@level='m']">
		<xsl:apply-templates/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:title[@level='a']">
		<xsl:apply-templates/>
		<xsl:text>, in: </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:title/@ref">
		<xsl:text> [Nachweis im </xsl:text>
		<a>
			<xsl:attribute name="href">
				<xsl:text>https://kxp.k10plus.de/DB=2.1/PPNSET?PPN=</xsl:text>
				<xsl:value-of select="substring-after(.,'_')"/>
			</xsl:attribute>
			<xsl:text>GVK</xsl:text>
		</a>
		<xsl:text>] </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:bibl">
		<xsl:text> in: </xsl:text>
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:pubPlace">
		<xsl:apply-templates/>
		<xsl:text>: </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:publisher">
		<xsl:apply-templates/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:date">
		<xsl:apply-templates/>
		<xsl:if test="not(../tei:biblScope[@unit='pp' or @unit='cols'])"><xsl:text>. </xsl:text></xsl:if>
	</xsl:template>
	
	
	<xsl:template match="tei:bibl//tei:biblScope[@unit='pp']">
		<xsl:if test="../tei:date"><xsl:text>, S. </xsl:text></xsl:if>
		<xsl:apply-templates/>
		<xsl:text>.</xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:biblScope[@unit='cols']">
		<xsl:if test="../tei:date"><xsl:text>, Sp. </xsl:text></xsl:if>
		<xsl:apply-templates/>
		<xsl:text>.</xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:biblScope[@unit='fols']">
		<xsl:if test="../tei:date"><xsl:text>, Bl. </xsl:text></xsl:if>
		<xsl:apply-templates/>
		<xsl:text>.</xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:biblScope[@unit='vol']">
		<xsl:text>Bd. </xsl:text>
		<xsl:apply-templates/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:biblScope[@unit='part']">
		<xsl:text>Tl. </xsl:text>
		<xsl:apply-templates/>
		<xsl:text>, </xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:series">
		<xsl:text> (</xsl:text>
		<xsl:value-of select="."/>
		<xsl:text>)</xsl:text>
	</xsl:template>
	
	<xsl:template match="tei:bibl//tei:abbr"/>
	
	<xsl:template match="tei:bibl/tei:title[@type='short']"/>
	
	<xsl:template name="fnnumber">
		<xsl:number level="any" format="a" count="//tei:note[@type='annotation'] | //tei:handShift | //tei:choice | //tei:restore"/>
	</xsl:template>
	
	<xsl:template match="tei:choice">
		<xsl:param name="ref"/>
		<xsl:param name="id"/>
		<xsl:apply-templates>
			<xsl:with-param name="ref" select="$ref"/>
			<xsl:with-param name="id" select="$id"/>
		</xsl:apply-templates>		
	</xsl:template>
	
	<xsl:template match="tei:corr">
		<xsl:param name="id"/>
		<xsl:apply-templates>
			<xsl:with-param name="id" select="$id"/>
		</xsl:apply-templates>
		<xsl:variable name="number">
			<xsl:call-template name="fnnumber" />
		</xsl:variable>
		<span id="ana{$number}">
			<a href="#an{$number}" style="font-size:9pt;vertical-align:super;color:blue;">
				<xsl:attribute name="title">
					<xsl:text>Im Original "</xsl:text>
					<xsl:for-each select="preceding-sibling::tei:sic">
						<xsl:call-template name="sic_corr-text"/>
					</xsl:for-each>										
					<xsl:text>"</xsl:text>
					<xsl:text> korrigiert in </xsl:text>
					<xsl:text>"</xsl:text>
					<xsl:call-template name="sic_corr-text"/>
					<xsl:text>"</xsl:text>
					<xsl:text>.</xsl:text>					
				</xsl:attribute>
				<xsl:value-of select="$number" />
			</a>
		</span>			
	</xsl:template>
	
	<xsl:template match="tei:expan">
		<xsl:param name="id"/>
		<xsl:param name="ref"/>
		<xsl:apply-templates>
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="ref" select="$ref"/>
		</xsl:apply-templates>
		<xsl:variable name="number">
			<xsl:call-template name="fnnumber" />
		</xsl:variable>
		<span id="ana{$number}">
			<a href="#an{$number}" style="font-size:9pt;vertical-align:super;color:blue;" title="{concat('Im Original steht ','&quot;',preceding-sibling::tei:abbr,'&quot;',' für ','&quot;', .,'&quot;', '.')}">
				<xsl:value-of select="$number" />
			</a>
		</span>		
	</xsl:template>
	
	<xsl:template match="tei:restore">
		<xsl:apply-templates/>
		<xsl:variable name="number">
			<xsl:call-template name="fnnumber" />
		</xsl:variable>
		<span id="ana{$number}">
			<a href="#an{$number}" style="font-size:9pt;vertical-align:super;color:blue;">
				<xsl:attribute name="title">
					<xsl:text>Streichung von "</xsl:text>
					<xsl:choose>
						<xsl:when test="child::tei:foreign">
							<xsl:value-of select="text()"/>
							<xsl:value-of select="tei:foreign"/>
						</xsl:when>
						<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
					</xsl:choose>													
					<xsl:text>" wieder aufgehoben.</xsl:text>
				</xsl:attribute>
				<xsl:value-of select="$number"/>
			</a>
		</span>
	</xsl:template>
	
	<xsl:template match="tei:sic"/>
	<xsl:template match="tei:abbr"/>
	
	<xsl:template name="sic_corr-text">
			<xsl:choose>
				<xsl:when test="descendant::tei:foreign">
					<xsl:value-of select="normalize-space(concat(descendant::tei:foreign,text()))"/>
				</xsl:when>
				<xsl:when test="descendant::tei:w">
					<xsl:apply-templates select="descendant::text()"/>
				</xsl:when>
				<xsl:when test="descendant::tei:del">
					<xsl:for-each select="node()">
						<xsl:choose>
							<xsl:when test="self::tei:subst">
								<span class="del">
									<xsl:value-of select="tei:del"/>
								</span>
								<xsl:text>&lt;</xsl:text>
								<xsl:value-of select="tei:add"/>
								<xsl:text>&gt;</xsl:text>
							</xsl:when>
							<xsl:when test="self::tei:del">
								<span class="del">
									<xsl:value-of select="."/>
								</span>
							</xsl:when>
							<xsl:when test="self::tei:ex">
								<span class="ex">
									<xsl:value-of select="."/>
								</span>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="."/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>						
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="normalize-space()"/>
				</xsl:otherwise>
			</xsl:choose>
	</xsl:template>
	
	<!--Listen und Tabellen mit geschweiften Klammern (vgl. DTABf)-->
	
	<xsl:template match="tei:list[@rendition]">
		<xsl:choose>
			<xsl:when test='@rendition="leftBraced"'>
				<span class="braced-base braced-left"><xsl:apply-templates/></span>
			</xsl:when>
			<xsl:when test='@rendition="rightBraced"'>
				<span class="braced-base braced-right"><xsl:apply-templates/></span>
			</xsl:when>
			<xsl:when test='@rendition="leftBraced rightBraced"'>
				<span class="braced-base braced-left-right"><xsl:apply-templates/></span>
			</xsl:when>
			<xsl:otherwise>
				<div>
					<xsl:apply-templates/>
				</div>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:cell[@rendition]">
		<xsl:choose>
			<xsl:when test='@rendition="leftBraced"'>
				<td class="braced-base braced-left">
					<xsl:if test="@cols">
						<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
					</xsl:if>
					<xsl:if test="@rows">
						<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
					</xsl:if>
					<xsl:apply-templates/>
				</td>
			</xsl:when>
			<xsl:when test='@rendition="rightBraced"'>
				<td class="braced-base braced-right">
					<xsl:if test="@cols">
						<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
					</xsl:if>
					<xsl:if test="@rows">
						<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
					</xsl:if>
					<xsl:apply-templates/>
				</td>
			</xsl:when>
			<xsl:when test='@rendition="leftBraced rightBraced"'>
				<td class="braced-base braced-left-right">
					<xsl:if test="@cols">
						<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
					</xsl:if>
					<xsl:if test="@rows">
						<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
					</xsl:if>
					<xsl:apply-templates/>
				</td>
			</xsl:when>
			<xsl:otherwise>
				<td>
					<xsl:apply-templates/>
				</td>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:table[@rendition]">
		<xsl:choose>
			<xsl:when test='@rendition="leftBraced"'>
				<table class="braced-base-table braced-left"><xsl:apply-templates/></table>
			</xsl:when>
			<xsl:when test='@rendition="rightBraced"'>
				<table class="braced-base-table braced-right"><xsl:apply-templates/></table>
			</xsl:when>
			<xsl:when test='@rendition="leftBraced rightBraced"'>
				<table class="braced-base-table braced-left-right"><xsl:apply-templates/></table>
			</xsl:when>
			<xsl:otherwise>
				<table>
					<xsl:apply-templates/>
				</table>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="tei:cell[preceding-sibling::tei:cell[@rendition='rightBraced']]">
		<td style="vertical-align: middle">
			<xsl:if test="@cols">
				<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
			</xsl:if>
			<xsl:if test="@rows">
				<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	
	<xsl:template match="tei:cell[preceding-sibling::tei:cell[@rendition='leftBraced rightBraced']]">
		<td style="vertical-align: middle; padding-left: 5px;">
			<xsl:if test="@cols">
				<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
			</xsl:if>
			<xsl:if test="@rows">
				<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	
	<xsl:template match="tei:cell[following-sibling::tei:cell[@rendition='leftBraced']]">
		<td style="vertical-align: middle">
			<xsl:if test="@cols">
				<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
			</xsl:if>
			<xsl:if test="@rows">
				<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	
	<xsl:template match="tei:cell[following-sibling::tei:cell[@rendition='leftBraced rightBraced']]">
		<td style="vertical-align: middle">
			<xsl:if test="@cols">
				<xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
			</xsl:if>
			<xsl:if test="@rows">
				<xsl:attribute name="rowspan"><xsl:value-of select="@rows"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	
	<!--Marginalien-->
	
	<xsl:template match="tei:note[contains(@place,'margin_left')]">
		<span class="marginalia-left">
			<xsl:apply-templates/>
		</span>
	</xsl:template>
	
	<xsl:template match="tei:note[contains(@place,'margin_right')]">
		<span class="marginalia-right">
			<xsl:apply-templates/>
		</span>
	</xsl:template>
	
</xsl:stylesheet>
