<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
  exclude-result-prefixes="xd exsl estr edate a fo local rng tei teix"
  extension-element-prefixes="exsl estr edate" version="1.0"
  xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
  xmlns:edate="http://exslt.org/dates-and-times"
  xmlns:estr="http://exslt.org/strings" xmlns:exsl="http://exslt.org/common"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:local="http://www.pantor.com/ns/local"
  xmlns:rng="http://relaxng.org/ns/structure/1.0"
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  xmlns:teix="http://www.tei-c.org/ns/Examples"
  xmlns:xd="http://www.pnp-software.com/XSLTdoc"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xd:doc type="stylesheet">
    <xd:short> TEI stylesheet for The Folger Shakespeare (formerly Folger Digital Texts). </xd:short>
    <xd:detail> This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public License as
      published by the Free Software Foundation; either version 2.1 of the
      License, or (at your option) any later version. This library is
      distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
      without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
      PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
      details. You should have received a copy of the GNU Lesser General Public
      License along with this library; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </xd:detail>
  </xd:doc>
  <xsl:output method="html" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="tei:c"/>
<xsl:param name="sessionId" />
  <xsl:template match="/">
	<html>
	<head>
	  <title><xsl:value-of select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <style>
    @media print { .noprint { display:none; }}
body { font-family: 'Times New Roman'; font-size:13pt; margin:10px 0px; padding:0px;}
br { clear:both; }

.hidden {display:none;}
.pageBlock { width:500px; padding:10px; margin-left:60px; border:1px solid black;}
.textBlock { position:relative; width:480px; padding:10px;}
.pageBorder { width:480px; height:1px; margin-top:50px; }
.pageHeading { width:420px; padding:10px; padding-top:30px; margin: 20px 0px; border-bottom:3px solid black; font-style:normal; font-weight: normal; color:black; page-break-before:always; }
.pageNbr { float:left; width:75px; }
.pageTitle { float:left; width:240px; text-align:center; font-style:italic; font-size:14pt; }
.pageDesc { float:right; text-align:right; font-size:8pt; font-variant:small-caps; }
.actFooter { width:430px; text-align:center; padding-top:5px; font-style:normal; }
.titleImg { width: 400px; padding: 0px 20px; }

.div1 { text-align:left; width:100%; }
.frontHeader { position:relative; width:480px; text-align:center; font-weight:bold; font-size:16pt; margin-bottom:50px; margin-top:10px;}
.charHeader { position:relative; width:480px; text-align:center; font-weight:bold; font-size:16pt; margin-bottom:50px; margin-top:10px;}
.castDiv { position:relative; float:left; }
.castHeadDiv { float:left;display:table; }
.castHead { font-style:italic; display:table-cell; vertical-align:middle; }
.bracketDiv { position:relative; float:left; padding:0px 5px; width:5px;}
.castName { font-size:12pt; font-variant:small-caps; }
.actHeader { position:relative; width:430px; text-align:center; font-style:italic; font-weight:bold; font-size:16pt; border-bottom:5px solid black; padding-bottom:5px; margin-bottom:50px; margin-top:100px;}
.poemHeader { position:relative; width:430px; text-align:center; font-style:italic; font-weight:bold; font-size:16pt; padding-bottom:5px; margin-bottom:00px; margin-top:50px;}
.sceneHeader { position:relative; width:430px; text-align:center; }
.page { page-break-before:always; }
.credits { position:relative;padding-top:200px;width:480px;text-align:center; }
.signed { display:block; float:right; text-align:right; width:auto; padding-right:00px; }


.emendation { font-style:normal; font-weight:normal; }
.lineNbr { position:absolute; left:475px; top:auto; width:auto; font-style:normal; font-weight:normal; font-size:12pt; line-height:20px;  }
.ftln { color:gray; position:absolute; left:-68px; top:auto; width:auto; font-style:normal; font-weight:normal; font-size:8pt; line-height:20px; }
.alignment {}

.centered { display:inline-block; text-align:center; width:430px; }
.centred { display:inline-block; text-align:center; width:430px; }
.right { display:inline-block; float:right; text-align:right; width:auto; padding-right:60px; }
.indentProse { padding-left:30px; }
.indentVerse { padding-left:15px; }
.indentRunOn { padding-left:30px; }
.indentSplit { padding-left:00px; }
.indentInline { padding-left:10px; }
.indentClosing { padding-left:50px; }
.indent { padding-left:8px; }
.inline { padding-left:0px; }
.indentTest { padding-left:50px; }
.closing { display:inline-block; padding-left:30px;  }
.closingSig { display:inline-block; float:right; text-align:right; width:auto;}
.closingSig { display:inline-block; padding-left:20px; float:right; text-align:left; width:auto; }
.signature { display:inline-block; float:right; text-align:left; width:auto; padding-right:60px; }

.speaker { clear:both; float:left; font-style:normal; font-variant:small-caps; font-size:10pt; line-height:20px; }
.speakerName { font-style:normal; font-variant:small-caps; font-size:10pt; line-height:20px;}


.stage { font-style:italic; }

.imgEmend { position:relative; height:16px; }
.imgTextX { position:relative; top:3px; height:16px; width:6px; }

.w { border: 1px solid blue; }
.pc { border: 1px solid green; }
.c { background-color: red; }


.docTitle {text-align:center; font-style:italic; font-size:40px;}
.titlePage { text-align: center; width: 100% }
.head { text-align: center; width: 100% }
.runningHeader { float:left;text-align:center;width:100%; padding: 15px 0px;}
.trailer { text-align: center; width: 100%; }

.bold { font-weight: bold; }
.italic { font-style: italic; }
.roman { font-style: normal; }
.underlined { text-decoration: underline; }
.underlining { text-decoration: underline; }
.superscript { vertical-align: super; }
.indented { padding-left: 60px; }

.gap { color:red; }
.add { color:blue; }
.del { color:black; }
.note { color:gray; }

.red { color:red; }
.blue { color:blue; }
.black { color:black; }
.gray { color:gray; }
.bckblue { background-color:blue; }

.speech { clear:both; float:left; padding:0 0px; background-color: white; font-family:times new roman; }
.line { float:left; background-color:transparent; padding: 0 15px; width:auto; }
.indented { padding-left: 60px; }
.turnunder { padding-left: 30px; }
.right-justified { text-align: justify; }
.prose { border: 0px solid blue; }
.proseIndent { padding-left: 30px; }
.song { font-style:italic; padding-left:60px; }
.poem { padding-left:60px; }
.lgIndent { padding-left:80px; }
.indent { padding-left:15px; }
.lg { width: 300px; padding-left: 60px; }
    
    </style>

	</head>
        <body>
          <div id="copyPaste" style="top:0px;left:0px;width:1px;height:1px;overflow:hidden;"></div>
          <div id="pageBlock" class="pageBlock">
            <div class="textBlock">
	            <xsl:apply-templates/>
            </div>
          </div>
        </body>
        </html>
  </xsl:template>

  <xsl:template name="contents">
    <table class="contents">
    <tbody>
      <tr>
      <td class="act">Front Matter</td>
      <td>
        <a id="locFromTheDirector" href="#FromTheDirector" class="scene">From the Director of the Folger Shakespeare Library</a><br/>
        <a id="locTextualIntroduction" href="#TextualIntroduction" class="scene">Textual Introduction</a><br/>
      </td>
      </tr>
      <tr>
      <xsl:choose>
        <xsl:when test="//tei:div2[contains(@xml:id,'Son-')]">
        <td class="act" style="vertical-align:top">Sonnets</td>
        <td>
        <xsl:for-each select="//tei:body//tei:div2[contains(@xml:id,'Son-')]">
          <a id="loc{@xml:id}" href="#{@xml:id}" class="scene">
          <xsl:value-of select="@n"/>
          <xsl:text>: </xsl:text>
          <xsl:variable name="wid" select="concat(@n,'.1')"/>
          <xsl:for-each select="//tei:body//tei:*[@n=$wid]">
          <xsl:value-of select="."/>
          </xsl:for-each>
          <xsl:text>&#8230;</xsl:text>
          </a><br/>
        </xsl:for-each>
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="act">
  	      <xsl:value-of select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/>
        </td>
        <td>
        <xsl:if test="//tei:div1[@type='dedication']">
          <a id="locdedication" href="#dedication" class="scene">Dedication</a><br/>
        </xsl:if>
        <xsl:if test="//tei:div1[@type='argument']">
          <a id="locargument" href="#argument" class="scene">Argument</a><br/>
        </xsl:if>
        <a id="locpoem" href="#poem" class="scene">
          <xsl:value-of select="//tei:div1[not(@xml:id)][not(@type)]/tei:head"/>
        </a><br/>
        </td>
      </xsl:otherwise>
      </xsl:choose>
      </tr>
    </tbody>
    </table>
  </xsl:template>

  <xsl:template name="front">
    <xsl:apply-templates select="//tei:front/tei:div"/>
  </xsl:template>

  <xsl:template match="tei:del">
  </xsl:template>
  <xsl:template match="tei:app">
  </xsl:template>

  <xsl:variable name="rdg" select="'lemma'" />
  <xsl:variable name="emendDesc" select="//tei:interp[@xml:id='emend']" />

  <xsl:template match="tei:teiHeader">
    <xsl:apply-templates select="//tei:titleStmt"/>
  </xsl:template>
  <xsl:template match="tei:front">
  </xsl:template>
  <xsl:template match="tei:back">
  </xsl:template>

  <xsl:template match="tei:titleStmt">
    <div class="div1">
	  <xsl:variable name="id" select="lower-case(//tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno)"/>
	  <xsl:variable name="title" select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/>
    
<xsl:choose>
<xsl:when test="$id eq 'ven'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mq9/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tn'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqf/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tro'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqc/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tit'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqk/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tim'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqm/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'wt'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mq6/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tn'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqg/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tgv'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mr0/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'tmp'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mqh/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'shr'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mr4/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'pht'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrf/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'wiv'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mq7/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'mv'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms0/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'err'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msz/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'Son'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mr2/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'rom'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mr5/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'r2'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrc/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'r3'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrb/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'per'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrg/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'oth'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrj/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'ado'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mx9/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'mm'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms3/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'mac'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms5/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'luc'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms7/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'lll'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msc/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'jr'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms9/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'jn'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msh/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'jc'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msj/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'h5'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msx/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq '3h6'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mxb/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq '2h6'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mxc/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq '1h6'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mxf/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'h8'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48msw/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq '2h4'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mxd/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq '1h4'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mxg/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'ham'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mst/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'cyn'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mt0/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'cor'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mt2/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'ayl'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mx6/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'ant'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mx8/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'mnd'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48ms2/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:when test="$id eq 'aww'"><img class="titleImg" src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mx7/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" alt="title"/></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>   
    <div class="credits">
      <p>Folger Shakespeare Library</p>
      <p><a href="https://shakespeare.folger.edu">https://shakespeare.folger.edu</a></p>
    </div>
     <hr/>
    </div>
    <div id="contents" class="page div1">
     <div class="frontHeader">Contents</div>
     <xsl:call-template name="contents"/>
     <hr/>
    </div>
    <xsl:call-template name="front"/>
  </xsl:template>

  <xsl:template match="tei:front/tei:div[@type='FromTheDirector']">
    <div id="FromTheDirector" class="page div1">
     <a name="FromTheDirector"/>
     <div class="frontHeader">From the Director of the Folger Shakespeare Library</div>
     <xsl:apply-templates/>
     <hr/>
   </div>
  </xsl:template>
  <xsl:template match="tei:front/tei:div[@type='TextualIntroduction']">
    <div id="TextualIntroduction" class="page div1">
     <a name="TextualIntroduction"/>
     <div class="frontHeader">Textual Introduction<br/>By Barbara Mowat and Paul Werstine</div>
     <xsl:apply-templates/>
     <hr/>
   </div>
  </xsl:template>
  <xsl:template match="tei:front//tei:lb">
    <br/>
  </xsl:template>
  <xsl:template match="tei:front//tei:p">
    <p><xsl:apply-templates/></p>
  </xsl:template>
  <xsl:template match="tei:front//tei:title">
    <span class="italic"><xsl:apply-templates/></span>
  </xsl:template>
  <xsl:template match="tei:front//tei:opener">
    <div class="centered"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:front//tei:head">
    <div class="centered"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:closer">
    <p class="signed"><xsl:apply-templates/></p>
  </xsl:template>
  <xsl:template match="tei:front//tei:signed">
    <span class="italic"><xsl:apply-templates/></span>
  </xsl:template>
  <xsl:template match="tei:epigraph">
    <span class="italic"><xsl:apply-templates/></span>
  </xsl:template>
  <xsl:template match="tei:front//tei:graphic">
    <xsl:variable name="alt" select="./tei:desc" />
    <xsl:choose>
    <xsl:when test="string(@url) eq 'fdt-textb-r.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrp/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-texta-r.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrq/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-emend-l.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrr/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-emend-r.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrs/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-textb-l.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrt/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-texta-l.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrv/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
    <xsl:when test="string(@url) eq 'fdt-bracket.png'"><img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrw/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgTextX" alt="{string(@url)}"/></xsl:when>
     <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="tei:front//tei:seg[@rend='nobr']">
    <span style="white-space:nowrap"><xsl:apply-templates/></span>
  </xsl:template>
  <xsl:template match="tei:trailer">
    <xsl:variable name="class" select="translate(@rend,',',' ')" />
    <br/>
    <br/>
    <div class="{$class}"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:head/tei:bibl">
    <div class="centered" style="margin:20px"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:div1/tei:note">
    <div class="centered" style="margin:20px"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:div2/tei:bibl">
    <br/>
    <div class="right"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:div2/tei:bibl/tei:citedRange">
    <xsl:text>[</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>]</xsl:text>
  </xsl:template>

  <xsl:template match="tei:lb">
     <br/>
  </xsl:template>

  <xsl:key name="actPage" match="tei:text/tei:body/tei:pb" use="substring(@spanTo,2)"/> 
  <xsl:key name="altRdg" match="tei:app[@from]" use="substring(@from,2)"/> 

  <xsl:key name="emend1" match="tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#emend']" use="substring(@target,2,8)"/> 
  <xsl:key name="emend2" match="tei:div/tei:ab/tei:ptr[@type='emendation'][@ana='#emend']" use="substring(@target,string-length(@target)-7)"/> 


  <xsl:template match="tei:div1">
     <xsl:choose>
     <xsl:when test="@type">
       <a name="{@type}"/>
     </xsl:when>
     <xsl:when test="@xml:id">
       <a name="{@xml:id}"/>
     </xsl:when>
     <xsl:otherwise>
       <a name="poem"/>
     </xsl:otherwise>
     </xsl:choose>
     <xsl:choose>
     <xsl:when test="@type='dedication'">
       <div class="size12pt"><xsl:apply-templates/></div>
     </xsl:when>
     <xsl:when test="@type='argument'">
       <div class="size12pt"><xsl:apply-templates/></div>
     </xsl:when>
     <xsl:otherwise>
       <div class="div1"><xsl:apply-templates/></div>
     </xsl:otherwise>
     </xsl:choose>
     <hr/>
  </xsl:template>
  <xsl:template match="tei:div1[@n]">
     <a name="Son-{@n}"/>
     <hr style="margin:50px"/>
     <div class="div1">
       <div class="page sceneHeader bold">
         <xsl:value-of select="@n"/>
       </div>
       <xsl:apply-templates/>
     </div>
  </xsl:template>

  <xsl:template match="tei:div1//tei:opener">
     <div class="sceneHeader"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:salute[@rend]">
    <xsl:variable name="class" select="translate(@rend,',',' ')" />
    <div class="{$class}"><xsl:apply-templates/></div>
    <br/>
    <br/>
  </xsl:template>
  <xsl:template match="tei:div1[@type='argument']//tei:head">
     <div class="sceneHeader"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:div1/tei:head">
     <div class="page poemHeader"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:div1/tei:head[@rend='quotes']">
    <div class="page poemHeader roman"><xsl:text>&#8220;</xsl:text><xsl:apply-templates/><xsl:text>&#8221;</xsl:text></div>
  </xsl:template>
  <xsl:template match="tei:div2">
     <a name="{@xml:id}"/>
     <div class="div1">
       <div class="page sceneHeader bold">
         <xsl:value-of select="@n"/>
       </div>
       <xsl:apply-templates/>
     </div>
     <hr style="margin:50px"/>
  </xsl:template>
  <xsl:template match="tei:div2/tei:head">
     <div class="page actHeader"><xsl:apply-templates/></div>
  </xsl:template>

  <xsl:template match="tei:w|tei:c|tei:pc|tei:w/tei:seg|tei:anchor">
    <xsl:variable name="class" select="translate(@rend,',',' ')" />
      <xsl:call-template name="openWordMarks"/>
      <xsl:call-template name="showRdg"/>
      <xsl:call-template name="closeWordMarks"/>
  </xsl:template>


  <xsl:template name="openWordMarks">
    <xsl:variable name="emend" select="key('emend1',@xml:id)"/> 
    <xsl:choose>
      <xsl:when test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)/@xml:id = ./@xml:id and count($emend)">
        <xsl:variable name="q1" select="(ancestor::tei:q[1]//tei:w)[1]/@xml:id" />
        <xsl:choose>
        <xsl:when test="$emend[contains(@target,$q1)]"> 
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrr/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
          <xsl:call-template name="openQuote"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="openQuote"/>
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrr/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
        </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="count($emend)"> 
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrr/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
        </xsl:if>
        <xsl:call-template name="openQuote"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="closeWordMarks">
    <xsl:variable name="emend" select="key('emend2',@xml:id)"/> 
    <xsl:choose>
      <xsl:when test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)[last()]/@xml:id = ./@xml:id and count($emend)">
        <xsl:variable name="q1" select="(ancestor::tei:q[1]//tei:w)[1]/@xml:id" />
        <xsl:choose>
        <xsl:when test="$emend[contains(@target,$q1)]"> 
          <xsl:call-template name="closeQuote"/>
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrs/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
        </xsl:when>
        <xsl:otherwise>
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrs/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
          <xsl:call-template name="closeQuote"/>
        </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="closeQuote"/>
        <xsl:if test="count($emend)"> 
          <img src="https://textgridlab.org/1.0/tgcrud/rest/textgrid:48mrs/data{if ($sessionId != '') then concat('?sessionId=', $sessionId) else () }" class="imgEmend" alt="{$emendDesc}" title="{$emendDesc}"/>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="openQuote">
      <xsl:if test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)[1]/@xml:id = ./@xml:id and (not(ancestor::tei:q[2]) or (ancestor::tei:q[2]//tei:w|ancestor::tei:q[2]//tei:pc)[1]/@xml:id = ./@xml:id)">
        <xsl:text>&#8220;</xsl:text>
      </xsl:if>
      <xsl:if test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)[1]/@xml:id = ./@xml:id and ancestor::tei:q[2]">
        <xsl:text>&#8216;</xsl:text>
      </xsl:if>
  </xsl:template>

  <xsl:template name="closeQuote">
      <xsl:if test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)[last()]/@xml:id = ./@xml:id and ancestor::tei:q[2]">
        <xsl:text>&#8217;</xsl:text>
      </xsl:if>
      <xsl:if test="(ancestor::tei:q[1]//tei:w|ancestor::tei:q[1]//tei:pc)[last()]/@xml:id = ./@xml:id and (not(ancestor::tei:q[2]) or (ancestor::tei:q[2]//tei:w|ancestor::tei:q[2]//tei:pc)[last()]/@xml:id = ./@xml:id)">
        <xsl:text>&#8221;</xsl:text>
      </xsl:if>
  </xsl:template>

  <xsl:template name="showTLN">
    <xsl:variable name="ftln" select="number(substring-after(@xml:id,'-'))"/>
    <a name="{@xml:id}"/>
    <xsl:choose>
    <xsl:when test="contains(@xml:id,'Son-') and (@n mod 4) = 0">
      <span class="lineNbr" name="{@xml:id}"><xsl:value-of select="@n"/></span>
    </xsl:when>
    <xsl:when test="not(contains(@xml:id,'Son-')) and ($ftln mod 5) = 0">
      <span class="lineNbr" name="{@xml:id}"><xsl:value-of select="$ftln"/></span>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="showRdg">
    <xsl:choose>
    <xsl:when test="key('altRdg',@xml:id)">
      <xsl:variable name="xmlId" select="@xml:id"/>
      <xsl:choose>
      <xsl:when test="//tei:app[contains(@from,$xmlId)]/tei:rdg[contains(@wit,$rdg)]">
        <xsl:apply-templates select="//tei:app[contains(@from,$xmlId)]/tei:rdg[contains(@wit,$rdg)]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="tei:foreign">
     <span class="italic"><xsl:apply-templates/></span>
  </xsl:template>
  <xsl:template match="tei:label">
    <div class="centered"><xsl:apply-templates/></div>
  </xsl:template>
  <xsl:template match="tei:ab[@rend='italic']">
     <span class="italic"><xsl:apply-templates/></span>
  </xsl:template>

  <xsl:template match="tei:milestone[@unit='stanza']">
    <br/>
  </xsl:template>
  <xsl:template match="tei:milestone[@unit='line']">
    <br/>
    <xsl:call-template name="showTLN"/>
    <xsl:choose>
    <xsl:when test="@n='1' and ancestor::tei:q">
      <xsl:text>&#8220;</xsl:text>
      <xsl:if test="ancestor::tei:q[2]">
        <xsl:text> &#8216;</xsl:text>
      </xsl:if>
    </xsl:when>
    <xsl:when test="contains(@xml:id,'Son-099')">
      <xsl:if test="@n='14' or @n='15'">
        <span class="alignment" style="padding-left:10px;">&#160;</span>
      </xsl:if>
    </xsl:when>
    <xsl:when test="contains(@xml:id,'Son') and (@n='13' or @n='14')">
      <span class="alignment" style="padding-left:10px;">&#160;</span>
    </xsl:when>
    <xsl:when test="contains(@xml:id,'Luc') and (@n='6' or @n='7')">
      <span class="alignment" style="padding-left:10px;">&#160;</span>
    </xsl:when>
    <xsl:when test="contains(@xml:id,'Ven') and (@n='5' or @n='6')">
      <span class="alignment" style="padding-left:10px;">&#160;</span>
    </xsl:when>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
