<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
	doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<!--
written by Jarom
modified  
@ modified by amit 3/03/2003; 
@ modified 10-13-04 by Susan and Jarom to add and del to display super and
	subscripts on the rend element
@ modified 12-8-04 to add xsl output type, allowing for local machine support
	through firefox, mozilla, and netscape
@ modified 01-06-06  to add support for notes display options -Amit
@ modified 03-16-06 removed  inline-horizontal for notes display options. -Amit
@ modified 04-10-06 fixed add/del templates, they were not working correctly
	-Amit
-->		
	<!-- variables to parse witness list for XSL use -->
	<xsl:variable name="witnessList">
		<xsl:for-each select="//witList/witness">
			<xsl:value-of select="./@sigil" />
			<xsl:if test="position()!=last()">
				<xsl:text> </xsl:text>
			</xsl:if>
		</xsl:for-each>
	</xsl:variable>

	<xsl:variable name="indent"> &#160;</xsl:variable>

	<xsl:variable name="witnumbers" select="//witList/witness" />

	<xsl:variable name="witlimit">
		<xsl:value-of select="count($witnumbers)" />
	</xsl:variable>

	<!-- rendering template for paragraph level styles -->
	<xsl:template name="render">
		<xsl:param name="style" />
		<xsl:choose>
			<!-- bold text -->
			<xsl:when test="$style='bold'">
				<strong><xsl:apply-templates /></strong>
			</xsl:when>
			<!-- italicized text -->
			<xsl:when test="$style='italic'">
				<em><xsl:apply-templates /></em>
			</xsl:when>
			<!-- small-caps text -->
			<xsl:when test="$style='small-caps'">
				<small><xsl:apply-templates /></small>
			</xsl:when>
			<!-- all-caps text -->
			<xsl:when test="$style='all-caps'">
				<span class="all-caps"><xsl:apply-templates /></span>
			</xsl:when>
			<!-- encase text in single quotes -->
			<xsl:when test="$style='singlequote'">
				'<xsl:apply-templates />'
			</xsl:when>
			<!-- encase text in double quotes -->
			<xsl:when test="$style='doublequote'">
				"<xsl:apply-templates />"
			</xsl:when>
			<!-- underline text -->
			<xsl:when test="$style='underline'">
				<span class="underline"><xsl:apply-templates /></span>
			</xsl:when>
			<!-- strikethrough text -->
			<xsl:when test="$style='strike'">
				<del><xsl:apply-templates /></del>
			</xsl:when>
			<xsl:when test="$style='strikethrough'">
				<del><xsl:apply-templates /></del>
			</xsl:when>
			<!-- place text in a blockquote -->
			<xsl:when test="$style='blockquote'">
				<blockquote><p><xsl:apply-templates /></p></blockquote>
			</xsl:when>
			<!-- big text -->
			<xsl:when test="$style='large'">
				<big><xsl:apply-templates /></big>
			</xsl:when>
			<!-- small text -->
			<xsl:when test="$style='small'">
				<small><xsl:apply-templates /></small>
			</xsl:when>
			<!-- indented text -->
			<xsl:when test="$style='indent'">
				&#09;<xsl:apply-templates />
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<!-- <xsl:template name="whichImage">
		<xsl:choose>
			<xsl:when test="//figure">
		 	<img onclick="imageViewAll(window.location.href);" alt="View All Images"
			title="Click to view all associated images in a popup window"
			src="../vm-images/viewimages.gif" class="menuimg" />
			</xsl:when>
		</xsl:choose>
	</xsl:template> -->

	<!-- Begin document templates -->
	<!-- Root template creates major page divisions -->
	<xsl:template match="/">
		<html>
			<head>
				<xsl:apply-templates select=".//teiHeader" mode="htmlHead" />
			</head>
			<body onLoad="init(); createManuscript();" onresize="resizeManuscripts();">
				<div id="masterControl" class="maincontrol">
					<div class="leftcontrol">
						<img src="../vm-images/poweredby.gif" id="poweredby"
						alt="Powered by Versioning Machine v3" onclick="callHome()" />
					</div>
					<div class="middlecontrol">
						<div class="textinfo">
							This text has <span class="count"><xsl:value-of select="count($witnumbers)" /></span> versions
						</div>
						<div class="buttons">
							<img onclick="createManuscript();" alt="Display New Version"
							title="Evoke a new version of the text in a new vertical pane"
							src="../vm-images/newversion.png" onmousedown="this.src='../vm-images/newversion_dn.png'"
							onmouseup="this.src='../vm-images/newversion.png'" />
							<img onclick="document.location.href='browseindex.html';"
							alt="Back to List of Texts" title="Return to the main index of texts"
							src="../vm-images/returnindex.png" onmousedown="this.src='../vm-images/returnindex_dn.png'"
							onmouseup="this.src='../vm-images/returnindex.png'" />
							<img onclick="showBiblio(event);" alt="Bibliographic Information"
							title="View bibliographic/colophon information" src="../vm-images/biblioinfo.png"
							onmousedown="this.src='../vm-images/biblioinfo_dn.png'"
							onmouseup="this.src='../vm-images/biblioinfo.png'" />
						</div>
						<div>
							Display Line Numbers
							<input type="checkbox" id="toggleLineNumbers" checked="checked" onclick="toggleLineNumbers(this.checked);" />&#160;&#160;&#8226;&#160;&#160;Note&#160;Format&#160;&#160;<select name="notesoption" id="notesoption" onchange="notesFormat(this);">
								<option value="hide">Hide Notes</option>
								<option value="popup" selected="selected">Show Popup Notes</option>
								<option value="inline">Show Inline Notes</option>
							</select>
						</div>
					</div>
					<div class="rightcontrol">
						<div class="poweruser">Need help?</div>
						<div class="popup" onclick="showPanel(event,'imageandnote');">Image and Note Viewer</div>
						<div class="popup" onclick="showPanel(event,'versioncontrols',0,0);">Version Controls</div>
						<div class="popup" onclick="showPanel(event,'notedisplay',0,0);">Note Display</div>
						<div class="popup" onclick="showPanel(event,'linenumbers',0,0);">Line Numbering</div>
					</div>
					<br style="clear: both;" />
				</div>
				<xsl:apply-templates select=".//teiHeader" mode="docInfo" />
				<xsl:apply-templates select=".//body" />
				<div id="allnotes">
					<div id="controlpanel" class="control" name="controlpanel" onmousedown="return false;" onclick="return true;">
						<span class="remove" onclick="notesFormat('hide');">X</span>
						Notes
					</div>
					<div id="allnotesdata" class="notes"></div>
				</div>
				<!-- end of allnotes -->
				<div style="visibility: hidden;" oncontextmenu="return false;" id="panel_imageviewer">
					<div title="Click to drag panel." id="handle_imageviewer">
						<span class="viewerlt" id="title_imageviewer">Image Viewer</span>
						<span class="viewerrt" title="Close this image" onclick="return hidePanel('imageviewer');">X</span>
					</div>
					<p id="content_imageviewer"></p>
				</div>
				<div style="visibility: hidden;" id="panel_noteviewer">
					<div title="Click to drag panel." id="handle_noteviewer">
						<span class="viewerlt" id="title_noteviewer">Note</span>
						<span class="viewerrt" title="Close this note" onclick="return hidePanel('noteviewer');">X</span>
					</div>
					<div id="content_noteviewer"></div>
				</div>
				<!-- Help popup notes -->
				<div id="panel_imageandnote" class="panel">
					<div title="Click to drag panel." id="handle_imageandnote" class="handle">
						<span class="viewerlt" id="title_imageandnote">About the Image and Note Viewer</span>
						<span class="viewerrt" title="Close this note" onclick="return hidePanel('imageandnote');">X</span>
					</div>
					<div id="content_imageandnote" class="content">
						<p>The image and note viewer may be dragged anywhere within
						the browser window. It is closed by clicking on the
						<strong>X</strong> button. Only one image and one popup
						note can be viewed at a time.</p>
						<p>Because of a limitation in the way the browser handles
						XSLT transformations, users of Firefox and other
						Mozilla-based browsers cannot view images within
						untransformed XML documents. In order to view manuscript
						images in Firefox, it is recommended that readers use HTML
						versions of the text. This restriction applies only to the
						image viewer: the note viewer work across all browsers.</p>
					</div>
				</div>
				<div id="panel_versioncontrols" class="panel">
					<div title="Click to drag panel." id="handle_versioncontrols" class="handle">
						<span class="viewerlt" id="title_versioncontrols">About Version Controls</span>
						<span class="viewerrt" title="Close this note" onclick="return hidePanel('versioncontrols');">X</span>
					</div>
					<div id="content_versioncontrols" class="content">
						<p>Each witness functions independently of each other. The
						first two witnesses are opened in the VM by default and
						displayed according to the order established by the
						editor/encoder. Users can open further witnesses through
						the <strong>Display New Version</strong> button. Witnesses
						can then be displayed in any order via the pull down menu.
						The <strong>X</strong> button removes the current version
						and resizes the remaining versions to maximize available
						space. All but one version can be removed.</p>
					</div>
				</div>
				<div id="panel_notedisplay" class="panel">
					<div title="Click to drag panel." id="handle_notedisplay" class="handle">
						<span class="viewerlt" id="title_notedisplay">About Note Display</span>
						<span class="viewerrt" title="Close this note" onclick="return hidePanel('notedisplay');">X</span>
					</div>
					<div id="content_notedisplay" class="content">
						<p>The <strong>Display Notes</strong> menu provides three
						choices for viewing notes when viewing texts encoded using
						the parallel segmentation method, and two when viewing texts
						encoded as discrete witnesses. In both cases, the default
						displays notes in a JavaScript popup whenever the reader
						clicks upon the footnote icons. When viewing parallel
						segmentation-encoded texts in Internet Explorer and
						Firefox, there is also the option to display all notes
						simultaneously within an inline panel. Lastly, there is
						an option to hide all notes.</p>
					</div>
				</div>
				<div id="panel_linenumbers" class="panel">
					<div title="Click to drag panel." id="handle_linenumbers" class="handle">
						<span class="viewerlt" id="title_linenumbers">About Line Numbering</span>
						<span class="viewerrt" title="Close this note" onclick="return hidePanel('linenumbers');">X</span>
					</div>
					<div id="content_linenumbers" class="content">
						<p>The <strong>Show Line Numbers</strong> checkbox toggles
						the display of line numbers on and off. Proper display of
						line numbers depends upon the TEI encoding of the document.
						This option is only available for documents that have been
						encoding using the parallel segmentation method.</p>
						<p>To track the changes in a line across witnesses,
						click the line number before the start of the line. To
						remove the bolding, click the line number again.</p>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>

	<!-- two different templates for header info, based on position -->
	<xsl:template match="teiHeader" mode="htmlHead">
		<title><xsl:value-of select=".//title" /> &#8211; The Versioning Machine 3.2</title>
		<link rel="stylesheet" href="../src/vmachine.css" type="text/css" />
		<script type="text/javascript" src="../src/vmachine.js"></script>
		<script type="text/javascript">
			<xsl:for-each select="//witList/witness">
				witnesses[<xsl:value-of select="position()-1" />] = '<xsl:value-of select="@sigil" />';
			</xsl:for-each>
			images = new Array;
			<xsl:for-each select="//figure">
				images[<xsl:value-of select="position()-1" />] = 
				'<xsl:call-template name="filenameClip">
					<xsl:with-param name="filestring"
					select="unparsed-entity-uri(@entity)" />
				</xsl:call-template>';
			</xsl:for-each>
			notes = new Array;
		</script>
	</xsl:template>
	
	<xsl:template match="teiHeader" mode="docInfo">
		<div id="panel_biblioarea" class="panel">
			<div title="Click to drag panel." id="handle_biblioarea" class="handle">
				<span class="viewerlt" id="title_biblioarea">Bibliographic Information</span>
				<span class="viewerrt" title="Close this note" onclick="hideBiblio();">X</span>
			</div>
			<div id="content_biblioarea" class="content">
				<xsl:apply-templates select=".//fileDesc" /> Original
				Source:<xsl:apply-templates select=".//sourceDesc" />
				<xsl:apply-templates select="//witList" />
				<strong>Textual Notes</strong>:
				<xsl:apply-templates select="//fileDesc/notesStmt" />
				<strong>Electronic Edition Information</strong>
				<br />
				<xsl:if test="//resp">
					<xsl:for-each select="//resp">
						<xsl:value-of select="." />
						<br />
					</xsl:for-each>
				</xsl:if>
				<xsl:if test=".//publicationStmt/publisher |
				.//publicationStmt/address | .//fileDesc/seriesStmt |
				.//availability | //fileDesc/publicationStmt/date">
					<br />
					<xsl:apply-templates select=".//publicationStmt/publisher" />
					<xsl:apply-templates select=".//publicationStmt/address" />
					<xsl:apply-templates select=".//fileDesc/seriesStmt" />
					<xsl:apply-templates select=".//availability" />
					<xsl:if test="//fileDesc/publicationStmt/date">
						<xsl:value-of select="//fileDesc/publicationStmt/date" />
					</xsl:if>
				</xsl:if>
				<xsl:if test="//encodingDesc/editorialDecl |
				//fileDesc/editionStmt | //encodingDesc/projectDesc">
					<strong>Encoding Principles</strong>
					<br />
					<xsl:apply-templates select="//encodingDesc/projectDesc" />
					<xsl:apply-templates select="//encodingDesc/editorialDecl" />
					<xsl:apply-templates select="//fileDesc/editionStmt" />
				</xsl:if>
			</div>
		</div>
	</xsl:template>

	<!-- individual header element templates -->
	<xsl:template match="fileDesc">
		<h3>
			<xsl:apply-templates select="./titleStmt/title" />
		</h3>
		<h4>
			<xsl:apply-templates select="./titleStmt/author" />
		</h4>
		<h4>
			<xsl:apply-templates select="./titleStmt/editor" />
		</h4>
		<xsl:if test="//note[@type='head']">
			<xsl:apply-templates select="//note[@type='head']" />
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="sourceDesc">
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="availability">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="address">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="publisher"> Published by <xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="seriesStmt">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="projectDesc">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="editorialDecl">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="editionStmt">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="notesStmt">
		<xsl:for-each select="note">
			<xsl:if test="not(@type='image')">
				<xsl:if test="not(@type='head')">
					<xsl:choose>
						<xsl:when test="@type='witness-specific'">
							<xsl:for-each select="witDetail">
								<em>
									<xsl:value-of select="@wit" />
								</em>
								<xsl:if test="@type">-<xsl:value-of select="@type" />
								</xsl:if>:<xsl:apply-templates />
								<br />
							</xsl:for-each>
							<br />
						</xsl:when>
						<xsl:otherwise>
							<xsl:if test="@type">
								<xsl:value-of select="@type" />:</xsl:if>
							<xsl:apply-templates />
							<br />
							<br />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:if>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="witList">
		<xsl:for-each select="witness">
			<strong>Witness <xsl:value-of select="@sigil" />
			</strong>: <xsl:apply-templates />
			<xsl:variable name="thisWit">
				<xsl:value-of select="@sigil" />
			</xsl:variable>
			<xsl:if test="//witDetail[@wit=$thisWit]/figure">
				<xsl:for-each select="//witDetail[@wit=$thisWit]/figure">
					(<xsl:call-template name="showImage">
						<xsl:with-param name="wit" select="parent::*/@wit" />
						<xsl:with-param name="figNum">
							<xsl:number value="position()" />
						</xsl:with-param>
					</xsl:call-template>)
				</xsl:for-each>
			</xsl:if>
			<br />
		</xsl:for-each>
		<br />
	</xsl:template>

	<!-- looping template to achieve relative file name -->
	<xsl:template name="showImage">
		<xsl:param name="wit" />
		<xsl:param name="figNum" />
		<a href="#">
			<xsl:variable name="file">
				<xsl:call-template name="filenameClip">
					<xsl:with-param name="filestring"
					select="unparsed-entity-uri(//witDetail[@wit=$wit]/figure[position()=$figNum]/@entity)" />
				</xsl:call-template>
			</xsl:variable>
			<!-- <xsl:attribute name="onClick">imageView('<xsl:value-of
			select="$wit" />','<xsl:value-of select="$file" />',window.location);</xsl:attribute>
			Show Image <xsl:value-of select="@wit" /> -->
			<xsl:attribute name="onClick">return imageView(event, 'imageviewer','images/<xsl:value-of select="$file" />'
			,'0','0',window.location);</xsl:attribute>
		</a>
	</xsl:template>
	
	<xsl:template name="showImageMS">
		<xsl:param name="wit" />
		<xsl:param name="figNum" />
		<span class="imageicon">
			<xsl:attribute name="wit">
				<xsl:value-of select="$wit" />
			</xsl:attribute>
			<xsl:variable name="file">
				<xsl:call-template name="filenameClip">
					<xsl:with-param name="filestring"
					select="unparsed-entity-uri(//witDetail[@wit=$wit]/figure[position()=$figNum]/@entity)" />
				</xsl:call-template>
			</xsl:variable>
			<xsl:attribute name="onclick">return imageView(event, 'imageviewer','images/<xsl:value-of select="$file" />','0','0',window.location,'<xsl:value-of
			select="$wit" />');</xsl:attribute>
			<img src="../vm-images/view.gif" class="viewimages" alt="View Images" title="View associated image" />
		</span>
	</xsl:template>
	
	<xsl:template name="filenameClip">
		<xsl:param name="filestring" />
		<xsl:choose>
			<xsl:when test="contains($filestring,'/')">
				<xsl:call-template name="filenameClip">
					<xsl:with-param name="filestring"
					select="substring-after($filestring,'/')" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$filestring" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- basic body template, creating areas for manuscript display and help
	info, and selecting encoding mode -->
	<xsl:template match="body">
		<div id="manuscriptarea">
			<div id="manuscript" class="manuscript">
				<div id="controlpanel" class="control">
					<!-- Please note: the text content of each of the "navigate" spans
					is used to identify each control in vmachine.js. If you wish to
					change the label (for instance, from "Previous" to "Prev," or to
					use images instead of text), you must also edit the corresponding
					JavaScript function navControls() in vmachine.js -->
					<span class="remove" onclick="removeManuscript(this);">X</span>
					Version <!-- <span id="msID" style="display: none;"
					title="The manuscript version number">initializing</span> -->
					<select id="idlist" onchange="showWitness(this.parentNode.parentNode,
					this.selectedIndex);"><option>Test</option></select>
					<script type="text/javascript">
						function addwitnesstolist(num,witness) {
							var selectbox = document.getElementById("idlist");
							selectbox.options.length = <xsl:value-of select="$witlimit" />;
							selectbox.options[num - 1] = new Option(witness, witness);
						}
						<xsl:for-each select="//witList/witness">
							addwitnesstolist(<xsl:value-of select='position()' />,"<xsl:value-of select='@sigil' />");
						</xsl:for-each>
					</script>
					<!-- &#8212; <span class="navigate"
					onclick="showWitness(this.parentNode.parentNode,
					'first');">First</span>&#160;| <span class="navigate"
					onclick="showWitness(this.parentNode.parentNode,
					'previous');">Previous</span>&#160;| <span class="navigate"
					onclick="showWitness(this.parentNode.parentNode,
					'next');">Next</span>&#160;| <span class="navigate"
					onclick="showWitness(this.parentNode.parentNode,
					'last');">Last</span> -->
				</div>
				<div id="manuscriptpaper" class="paper">
					<xsl:for-each select="//witList/witness">
						<xsl:variable name="thisWit">
							<xsl:value-of select="@sigil" />
						</xsl:variable>
						<xsl:for-each select="//witDetail[@wit=$thisWit]/figure">
							<xsl:call-template name="showImageMS">
								<xsl:with-param name="wit" select="parent::*/@wit" />
								<xsl:with-param name="figNum">
									<xsl:number value="position()" />
								</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</xsl:for-each>
					<xsl:choose>
						<xsl:when
						test="//variantEncoding/@method='double-end-point'">
							<xsl:apply-templates select="div0"
							mode="double-end-point" />
						</xsl:when>
						<xsl:when
						test="//variantEncoding/@method='location-referenced'">
							<xsl:apply-templates select="div0"
							mode="location-referenced" />
						</xsl:when>
						<xsl:when
						test="//variantEncoding/@method='parallel-segmentation'">
							<xsl:apply-templates select="./*"
							mode="parallel-segmentation" />
						</xsl:when>
					</xsl:choose>
				</div>
			</div>
		</div>
	</xsl:template>

	<!-- begin text transformation based on enoding mode -->
	<xsl:template match="div0" mode="double-end-point">
		<xsl:apply-templates mode="double-end-point" />
	</xsl:template>
	
	<xsl:template match="div0" mode="location-referenced">
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="div|div0|div1|div2|div3|div4|div5|div6|div7"
	mode="parallel-segmentation">
		<xsl:apply-templates mode="parallel-segmentation" />
	</xsl:template>

	<!-- parallel segmentation -->
	<xsl:template match="l" mode="parallel-segmentation">
		<xsl:choose>
			<xsl:when test="@rend='indent'">
				<xsl:call-template name="witParse">
					<xsl:with-param name="texttype">line</xsl:with-param>
					<xsl:with-param name="num" select="generate-id()" />
					<xsl:with-param name="indent">Y</xsl:with-param>
					<xsl:with-param name="linenum">
						<xsl:value-of select="@n" />
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="witParse">
					<xsl:with-param name="texttype">line</xsl:with-param>
					<xsl:with-param name="num" select="generate-id()" />
					<xsl:with-param name="indent">N</xsl:with-param>
					<xsl:with-param name="linenum">
						<xsl:value-of select="@n" />
					</xsl:with-param>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="ab" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">AB</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="p" mode="parallel-segmentation">
		<span>
			<xsl:attribute name="id">stanza</xsl:attribute>
			<xsl:attribute name="wit">all</xsl:attribute>
			<br />
		</span>
		<xsl:choose>
			<xsl:when test="@rend='indent'">
				<xsl:call-template name="witParse">
					<xsl:with-param name="texttype">para</xsl:with-param>
					<xsl:with-param name="num" select="generate-id()" />
					<xsl:with-param name="indent">Y</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="witParse">
					<xsl:with-param name="texttype">para</xsl:with-param>
					<xsl:with-param name="num" select="generate-id()" />
					<xsl:with-param name="indent">N</xsl:with-param>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="seg" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">seg</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="s" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">sentence</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="word" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">word</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="closer" mode="parallel-segmentation">
		<span>
			<xsl:attribute name="id">stanza</xsl:attribute>
			<xsl:attribute name="wit">all</xsl:attribute>
			<br />
		</span>
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">closer</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="opener" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">opener</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="epigraph" mode="parallel-segmentation">
		<xsl:call-template name="witParse">
			<xsl:with-param name="texttype">epigraph</xsl:with-param>
			<xsl:with-param name="num" select="generate-id()" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="head" mode="parallel-segmentation">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="witParse">
					<xsl:with-param name="texttype">head</xsl:with-param>
					<xsl:with-param name="num" select="generate-id()" />
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="lg" mode="parallel-segmentation">
		<span>
			<xsl:attribute name="id">stanza</xsl:attribute>
			<xsl:attribute name="wit">all</xsl:attribute>
			<br />
		</span>
		<xsl:apply-templates mode="parallel-segmentation" />
	</xsl:template>
	
	<xsl:template match="div[@type='dedication']">
		<span>
			<xsl:attribute name="id">stanza</xsl:attribute>
			<xsl:attribute name="wit">all</xsl:attribute>
			<br />
		</span>
	</xsl:template>
	
	<xsl:template match="witList" mode="parallel-segmentation"></xsl:template>
	<!-- select out the text of each current witness and transform it -->
	<xsl:template name="witParse">
		<xsl:param name="texttype" />
		<xsl:param name="num" />
		<xsl:param name="indent" />
		<xsl:param name="current" select="1" />
		<xsl:param name="linenum" select="''" />
		<xsl:param name="whichwitness">
			<xsl:value-of select="//witList/witness[position()=$current]/@sigil" />
		</xsl:param>
		<xsl:choose>
			<xsl:when test="$current &lt;= $witlimit">
				<span class="textline">
					<xsl:attribute name="id">
						<xsl:value-of select="$texttype" />
						<xsl:value-of select="$num" />
					</xsl:attribute>
					<xsl:attribute name="wit">
						<xsl:value-of select="$whichwitness" />
					</xsl:attribute>
					<span class="linenumber">
						<xsl:attribute name="onclick">
							getMatching('<xsl:value-of select="$texttype" />
							<xsl:value-of select="$num" />')
						</xsl:attribute>
						<xsl:value-of select="$linenum" />
					</span>
					<span class="linetext">
						<xsl:call-template name="parsingWits">
							<xsl:with-param name="currentwit" select="$whichwitness" />
							<xsl:with-param name="indent" select="$indent" />
							<xsl:with-param name="linenum" select="$linenum" />
						</xsl:call-template>
					</span>
					<br class="clear" />
				</span>
				<xsl:call-template name="witParse">
					<xsl:with-param name="current" select="$current + 1" />
					<xsl:with-param name="texttype" select="$texttype" />
					<xsl:with-param name="num" select="$num" />
					<xsl:with-param name="indent" select="$indent" />
					<xsl:with-param name="linenum" select="$linenum" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<span>
					<xsl:attribute name="id">linebreak</xsl:attribute>
					<xsl:attribute name="wit">all</xsl:attribute>
				</span>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- special template for apparatus -->
	<xsl:template name="appParse">
		<xsl:param name="currentwit" />
		<xsl:for-each select="rdg|lem">
			<xsl:if test="contains(./@wit,$currentwit)">
				<xsl:call-template name="parsingWits">
					<xsl:with-param name="currentwit" select="$currentwit" />
				</xsl:call-template>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<!--
		<xsl:template name="lineLengthParse">
			<xsl:param name="currentwit" />
			<xsl:for-each select="rdg|lem">
				<xsl:if test="contains(./@wit,$currentwit)">
					<xsl:call-template name="getLineLength">
						<xsl:with-param name="currentwit" select="$currentwit" />
					</xsl:call-template>
				</xsl:if>
			</xsl:for-each>
		</xsl:template>
		<xsl:template name="getLineLength">
			<xsl:value-of select="string-length(normalize-space(.))" />
			<xsl:param name="currentwit" />
			<xsl:for-each select="./node()">
				<xsl:choose>
					<xsl:when test="self::*">
						<xsl:choose>
							<xsl:when test="self::app">
								<xsl:call-template name="lineLengthParse">
									<xsl:with-param name="currentwit"
									select="$currentwit" />
								</xsl:call-template>
							</xsl:when>
							<xsl:when test=".//app">
								<xsl:if test="self::div[@type='dedication']">
									<xsl:apply-templates select="." />
								</xsl:if>
								<xsl:call-template name="getLineLength">
									<xsl:with-param name="currentwit"
									select="$currentwit" />
								</xsl:call-template>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="string-length(.)" />
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="string-length(.)" />
						<xsl:text> </xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</xsl:template>
	-->
	<!-- looping to pick up nested elements -->
	<xsl:template name="parsingWits">
		<xsl:param name="currentwit" />
		<xsl:param name="indent" />
		<xsl:param name="linenum" />
		<xsl:for-each select="./node()">
			<xsl:choose>
				<xsl:when test="self::*">
					<xsl:choose>
						<xsl:when test="self::app">
							<xsl:call-template name="appParse">
								<xsl:with-param name="currentwit"
								select="$currentwit" />
								<xsl:with-param name="linenum" select="$linenum" />
							</xsl:call-template>
						</xsl:when>
						<xsl:when test=".//app">
							<xsl:if test="self::div[@type='dedication']">
								<xsl:if test="$indent='Y'">
									&#160;&#160;&#160;&#160;&#160;
								</xsl:if>
								<xsl:apply-templates select="." />
							</xsl:if>
							<xsl:call-template name="parsingWits">
								<xsl:with-param name="currentwit"
								select="$currentwit" />
								<xsl:with-param name="linenum" select="$linenum" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:if test="$indent='Y'">
								&#160;&#160;&#160;&#160;&#160;
							</xsl:if>
							<xsl:apply-templates select="." />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$indent='Y'">
						&#151;&#160;&#160;&#160;&#160;
					</xsl:if>
					<xsl:text> </xsl:text>
					<!--<xsl:value-of select="normalize-space(.)" />
					:<xsl:value-of select="string-length(normalize-space(.))" />:-->
					<xsl:apply-templates select="." />
					<xsl:text> </xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<!-- miscellaneous paragraph level elements, all default (when differing
	based on encoding method, see that mode) -->
	<xsl:template match="head">
		<div class="center">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</div>
	</xsl:template>
	
	<xsl:template match="opener">
		<p><xsl:apply-templates /></p>
	</xsl:template>
	
	<xsl:template match="closer">
		<p><xsl:apply-templates /></p>
	</xsl:template>
	
	<xsl:template match="signed">
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="hi">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<strong><xsl:apply-templates /></strong>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="emph">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<strong><xsl:apply-templates /></strong>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="soCalled">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise> "<xsl:apply-templates />" </xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="title">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="author">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="name">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="foreign">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="mentioned">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="rs">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="term">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="q">
		<xsl:choose>
			<xsl:when test="@rend">
				<xsl:call-template name="render">
					<xsl:with-param name="style" select="@rend" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="lb">
		<br />
	</xsl:template>
	
	<xsl:template match="p">
		<p>
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</p>
	</xsl:template>
	
	<xsl:template match="list">
		<ul>
			<xsl:apply-templates />
		</ul>
	</xsl:template>
	
	<xsl:template match="item">
		<li><xsl:apply-templates /></li>
	</xsl:template>
	
	<xsl:template match="pb">
		<a>
			<xsl:attribute name="name">page<xsl:value-of select="@n" />
			</xsl:attribute>
		</a>
		<span style="color: #999999;">
			[begin page <xsl:value-of select="@n" />]
		</span>
	</xsl:template>
	
	<xsl:template match="note|witDetail">
		<script>
			notes[<xsl:value-of
			select="count(preceding::note)-count(preceding::notesStmt//note)" />]=
			'<xsl:value-of select="generate-id(.)" />';
		</script>
		<span id="noteicon" class="noteicon">
			<xsl:attribute name="onclick">displayNote('note.<xsl:value-of select="generate-id()" />','<xsl:value-of select="@type" />',event, 'noteviewer','0','0'); </xsl:attribute>
			<xsl:choose>
				<xsl:when test="@type='physical'">
					<span title="Physical object note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>
					</span>
				</xsl:when>
				<xsl:when test="@type='biographical'">
					<span title="Biographical note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>b
					</span>
				</xsl:when>
				<xsl:when test="@type='gloss'">
					<span title="Gloss/definition note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>g
					</span>
				</xsl:when>
				<xsl:when test="@type='critical'">
					<span title="Critical note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>c
					</span>
				</xsl:when>
				<xsl:when test="@type='contextual'">
					<span title="Contextual note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>c
					</span>
				</xsl:when>
				<xsl:otherwise>
					<span title="Generic note">
						<xsl:attribute name="id">note<xsl:value-of
						select="generate-id()" /></xsl:attribute>n
					</span>
				</xsl:otherwise>
			</xsl:choose>
		</span>
		<span class="notearea">
			<xsl:attribute name="linenum">
				<xsl:value-of select="ancestor::l/@n" />
			</xsl:attribute>
			<xsl:attribute name="id">note.<xsl:value-of select="generate-id()" />
			</xsl:attribute>
			<xsl:apply-templates />
		</span>
	</xsl:template>
	
	<xsl:template match="note/lg | witDetail/lg">
		<br />
		<br />
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="space">
		<xsl:choose>
			<xsl:when test="@dim='horizontal'">
				<xsl:call-template name="spacer">
					<xsl:with-param name="num" select="@n" />
					<xsl:with-param name="dimen">hor</xsl:with-param>
					<xsl:with-param name="starting">1</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="@dim='vertical'">
				<xsl:call-template name="spacer">
					<xsl:with-param name="num" select="@n" />
					<xsl:with-param name="dimen">vert</xsl:with-param>
					<xsl:with-param name="starting">1</xsl:with-param>
				</xsl:call-template>
			</xsl:when>
		</xsl:choose>
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template name="spacer">
		<xsl:param name="num" />
		<xsl:param name="dimen" />
		<xsl:param name="starting" />
		<xsl:if test="$starting&lt;=$num">
			<xsl:choose>
				<xsl:when test="$dimen='hor'"> &#160;</xsl:when>
				<xsl:when test="$dimen='vert'">
					<br />
				</xsl:when>
			</xsl:choose>
			<xsl:call-template name="spacer">
				<xsl:with-param name="num" select="$num" />
				<xsl:with-param name="dimen" select="$dimen" />
				<xsl:with-param name="starting" select="$starting + 1" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="note/lg/l | witDetail/lg/l">
		<xsl:apply-templates />
		<br />
	</xsl:template>
	
	<xsl:template match="del">
		<xsl:choose>
			<xsl:when test="@rend='superscript'">
				<xsl:element name="del">
					<xsl:element name="sup">
						<xsl:choose>
							<xsl:when test="@rend">
								<xsl:call-template name="render">
									<xsl:with-param name="style" select="@rend" />
								</xsl:call-template>
							</xsl:when>
							<xsl:otherwise>
								<xsl:apply-templates />
							</xsl:otherwise>
						</xsl:choose>
					</xsl:element>
				</xsl:element>
			</xsl:when>
			<xsl:when test="@rend='subscript'">
				<xsl:element name="del">
					<xsl:element name="sub">
						<xsl:choose>
							<xsl:when test="@rend">
								<xsl:call-template name="render">
									<xsl:with-param name="style" select="@rend" />
								</xsl:call-template>
							</xsl:when>
							<xsl:otherwise>
								<xsl:apply-templates />
							</xsl:otherwise>
						</xsl:choose>
					</xsl:element>
				</xsl:element>
			</xsl:when>
			<xsl:when test="'del'">
				<xsl:element name="del">
					<xsl:choose>
						<xsl:when test="@rend">
							<xsl:call-template name="render">
								<xsl:with-param name="style" select="@rend" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:element>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="add">
		<xsl:choose>
			<xsl:when test="@rend='superscript'">
				<xsl:element name="sup">
					<xsl:attribute name="class">add</xsl:attribute>
					<xsl:choose>
						<xsl:when test="@rend">
							<xsl:call-template name="render">
								<xsl:with-param name="style" select="@rend" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:element>
			</xsl:when>
			<xsl:when test="@rend='subscript'">
				<xsl:element name="sub">
					<xsl:attribute name="class">add</xsl:attribute>
					<xsl:choose>
						<xsl:when test="@rend">
							<xsl:call-template name="render">
								<xsl:with-param name="style" select="@rend" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:element>
			</xsl:when>
			<xsl:when test="'add'">
				<xsl:element name="span">
					<xsl:attribute name="class">add</xsl:attribute>
					<xsl:choose>
						<xsl:when test="@rend">
							<xsl:call-template name="render">
								<xsl:with-param name="style" select="@rend" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:element>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="sic">
		<span class="sic">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="corr">
		<span class="corr">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="gap">
		<span class="gap">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="damage">
		<span class="damage">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="unclear">
		<span class="unclear">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="supplied">
		<span class="supplied">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="restore">
		<span class="restore">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="handShift">
		<span class="handShift">
			<xsl:choose>
				<xsl:when test="@rend">
					<xsl:call-template name="render">
						<xsl:with-param name="style" select="@rend" />
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates />
				</xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	
	<xsl:template match="milestone[@unit='stanza']">
		<br />
		<br />
	</xsl:template>
</xsl:stylesheet>

