<?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:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exist="http://exist.sourceforge.net/NS/exist"
    exclude-result-prefixes="tei exist mets xlink" 
    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"/>
    

    <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"/>
    <xsl:param name="distype"/>
    <xsl:param name="pvID"/>
    <!--<xsl:variable name="pvID">pv_transcript-facs1602</xsl:variable>-->
    <xsl:param name="footerXML"/>
    <xsl:param name="footerXSL"/>
    
    <xsl:variable name="metsfile"><xsl:value-of select="concat('/',$dir,'/mets.xml')"/></xsl:variable>
    
    

    <xsl:template match="/">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title><xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/></title>
                <link rel="stylesheet" type="text/css" href="http://diglib.hab.de/navigator2.css"/>
                <script src="http://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">
                <div style="margin-bottom:0.2em;padding:0;letter-spacing:0.3em;">Text</div>
                <hr style="margin:0;padding:0;height:1px;"/>
                    <xsl:choose>  
                                <xsl:when test="document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='transcripton']/@ADMID]/mets:mdRef/@xlink:href">
                                    <a>
                                       <xsl:attribute name="href">
                                            <xsl:value-of select="document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='transcripton']/@ADMID]/mets:mdRef/@xlink:href"/>
                                       </xsl:attribute>
                                       copyright
                                    </a>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="document($metsfile)//mets:rightsMD[@ID=document($metsfile)//mets:div[@TYPE='transcripton']/@ADMID]/mets:mdWrap/mets:xmlData"/>
                                </xsl:otherwise>
                            </xsl:choose>
                    </div>
                <!-- 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"/>
                    </div>
                    </div>-->
                <!-- Inhaltsuebersicht -->
                <!--  hier nicht -->
                <div class="content" style="text-align:justify;">
                    <!-- Haupttext -->
                    <xsl:apply-templates select="tei:TEI/tei:text/tei:body"/>
                    <!-- Fussnotenbereich  -->
                    <a name="footnotes"><hr style="height:1px;margin:1em 0 1em; 0"/></a>
                    <xsl:choose>
                        <xsl:when test="tei:TEI/tei:text/tei:body/tei:div[@type='footnotes']">
                            <!--  Wenn es einen Fussnotenbereich gibt -->
                            <xsl:apply-templates select="tei:TEI/tei:text/tei:body/tei:div[@type='footnotes']"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <!--  andernfalls notes auswerten -->
                            <xsl:for-each select="tei:TEI/tei:text/tei:body//tei:note[@type='footnote']">
                                <div class="footnotes">
                                    <xsl:element name="a">
                                        <xsl:attribute name="name">
                                            <xsl:text>fn</xsl:text>
                                            <xsl:number level="any" count="tei:note[@type ='footnote']"/>
                                        </xsl:attribute>
                                        <a>
                                            <xsl:attribute name="href">
                                                <xsl:text>#fna</xsl:text><xsl:number level="any" count="tei:note[@type ='footnote']"/>
                                            </xsl:attribute>
                                            <span style="font-size:9pt;vertical-align:super;color:blue;"><xsl:number level="any" count="tei:note[@type ='footnote']"/></span>
                                        </a>
                                        <xsl:apply-templates/>
                                      </xsl:element>
                                </div>
                            </xsl:for-each>
                          </xsl:otherwise>
                    </xsl:choose>
                    <!-- Bibliographie -->
                    <!--<a name="bibliography"><hr style="height:1px;margin:1em 0 1em; 0"/></a>-->
                    <!--<xsl:apply-templates select="tei:TEI/tei:text/tei:back/tei:div[@type='bibliography']"/>-->
                    
                    <!-- Bibliographie -->
                    <div id="kritApp" style="font-size:smaller;line-height:1em;">
                    <a name="kritischerAppart"><hr style="height:1px;margin:1em 0 1em; 0"/></a>
                    <xsl:for-each select="//tei:lem">
                        <a>
                            <xsl:attribute name="name">
                                <xsl:text>kA</xsl:text><xsl:number level="any"/>
                            </xsl:attribute><xsl:text> </xsl:text>
                        </a>
                        <a>
                        <xsl:attribute name="href">
                            <xsl:text>#kAz</xsl:text><xsl:number level="any"/>
                        </xsl:attribute>
                            [<xsl:number level="any"/>]
                        </a>
                        <xsl:value-of select="../tei:rdg"/><xsl:text> </xsl:text><i><xsl:value-of select="substring-after(../tei:rdg/@wit,'#')"/></i>
                        <br/>
                      </xsl:for-each>
                    </div>
                    <!-- footer -->
                    <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 -->
            </body>
        </html>
    </xsl:template>
    
    
    <!--header-->
    <!-- editor, contributer etc. -->
    <xsl:template match="tei:respStmt">
        <xsl:if test="position() != 1">
            <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:text> </xsl:text>
        <xsl:value-of select="tei:resp"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="tei:name"/>
    </xsl:template>

    <!-- Front -->
    <xsl:template match="tei:front">
        <xsl:apply-templates select="tei:titlePage"/>
    </xsl:template>

    <xsl:template match="tei:titlePage">
        <p class="content">
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="tei:docTitle">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="tei:byline">
        <p class="content">
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="tei:imprimatur">
        <p class="content">
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="tei:docDate">
        <p class="content">
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="tei:docAuthor">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="tei:epigraph">
        <p class="legende">
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="tei:titlePart">
        <p class="content">
            <xsl:apply-templates/>
        </p>
    </xsl:template>


    <!--body-->
    <!-- main distribution-->
    <xsl:template match="tei:div[not(@type='footnotes')]">
        <a>
            <xsl:attribute name="name">
                <xsl:text>div</xsl:text>
                <xsl:number level="any"/>
            </xsl:attribute>
        </a>
        <div>
            <xsl:if test="@type = 'abstract'"><xsl:attribute name="style">font-size:smaller;</xsl:attribute></xsl:if>
            <xsl:apply-templates/>
        </div>
    </xsl:template>
    
<!--    Ueberschriften-->
    <xsl:template match="tei:head">
        <a>
            <xsl:attribute name="name"><xsl:text>hd</xsl:text><xsl:number level="any"/></xsl:attribute>
            <xsl:text> </xsl:text>
        </a>
        <h2 style="background-color:#EEE;padding:0.3em;margin-top:1em;position:relative;width:100%;">
            <div style="position:relative;width:90%;"><xsl:apply-templates/></div>
            <div style="position:absolute;right:1.5em;top:0.2em;font-weight:900;"><a href="#">↑</a></div>
        </h2>
    </xsl:template>

    <xsl:template match="tei:title">
        <span style="font-style:italic;">
            <xsl:apply-templates/>
        </span>
    </xsl:template>
    
    <!-- pysical pages     -->
    <xsl:template match="tei:pb">
        <div style="margin-top:2em;">
            <a>
                <xsl:attribute name="name">
                    <xsl:value-of select="substring(@facs,2)"/>
                </xsl:attribute>
                <xsl:text> </xsl:text>
            </a> 
            <xsl:text> || </xsl:text>
            <xsl:text> [</xsl:text>
            <xsl:choose>
                <xsl:when test="starts-with($pvID,'pv_trans-trans')">
                    <a>
                        <xsl:attribute name="href">
                            <xsl:text>javascript:sync('</xsl:text>
                            <xsl:value-of select="substring(@facs,2)"/>
                            <xsl:text>','</xsl:text>
                            <xsl:value-of select="substring(@facs,2)"/>
                            <xsl:text>','</xsl:text>
                            <xsl:value-of select="$dir"/>
                            <xsl:text>','</xsl:text>
                            <xsl:number count="tei:pb" level="any"/>
                            <xsl:text>','pb')</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="title">Synchronisieren</xsl:attribute>
                        <xsl:text>↔ </xsl:text><xsl:value-of select="@n"/>
                    </a>
                </xsl:when>
                <xsl:otherwise>
                    <a>
                        <xsl:attribute name="href">
                            <!-- convert identifier z.B. drucke_qun-59-9-1_00006 -->
                            <!-- select type of resource e.g. drucke -->
                            <xsl:text>http://diglib.hab.de/</xsl:text>
                            <xsl:value-of select="substring-before(substring(@facs,2),'_')"/>
                            <xsl:text>/</xsl:text>
                            <!-- select shelf mark e.g.qun-59-9-1 -->
                            <xsl:value-of
                                select="substring-before(substring-after(substring(@facs,2),'_'),'_')"/>
                            <!-- select Image-No , e.g. 00006  -->
                            <xsl:text>/start.htm?distype=imgs&amp;image=</xsl:text>
                            <xsl:value-of
                                select="substring-after(substring-after(substring(@facs,2),'_'),'_')"
                            />
                        </xsl:attribute>
                        <xsl:if test="starts-with($pvID,'pv_transcript-facs')">
                            <xsl:attribute name="target">display2</xsl:attribute>
                        </xsl:if>       
                        <xsl:if test="starts-with($pvID,'pv_trans-trans')">
                            <xsl:attribute name="target">display2</xsl:attribute>
                        </xsl:if>   
                        <xsl:value-of select="@n"/>
                    </a>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:text>] </xsl:text>
            </div>
    </xsl:template>
    
    
    
<!--    Links -->
    <xsl:template match="tei:ref">
        <xsl:param name="caption"/>
        <xsl:choose>
            <xsl:when test="@type='wdb'">
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="@target"/>
                    </xsl:attribute>
                    <xsl:attribute name="target">_blank</xsl:attribute>
                    <xsl:attribute name="title">WDB</xsl:attribute>
                    <xsl:apply-templates/>
                </a>
            </xsl:when>   
            <xsl:when test="@type='footnote' and $caption != 'true'">
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:text>fna</xsl:text>
                        <xsl:value-of select="."/>
                    </xsl:attribute>
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="@target"/>
                        </xsl:attribute>
                        <span style="font-size:9pt;vertical-align:super;color:blue;"><xsl:value-of select="."/></span>
                    </a>
                </xsl:element>
            </xsl:when>
         
            <!-- Google Books -->
            <xsl:when test="@type='google_books'">
                <a>
                    <xsl:attribute name="href">
                        <xsl:text>javascript:show_annotation_html('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','</xsl:text><xsl:value-of select="@target"/><xsl:text>',500,600)</xsl:text>
                    </xsl:attribute>
                    <xsl:apply-templates/>
                </a> 
            </xsl:when>
            <xsl:when test="@type='bibliography'">
                <a>
                    <xsl:if test="starts-with(@target,'#')">
                        <xsl:attribute name="title">
                            <xsl:value-of select="normalize-space(id(substring(@target,2)))"/>
                        </xsl:attribute>
                    </xsl:if>  
                    <xsl:attribute name="href"> <xsl:value-of select="@target"/></xsl:attribute>
                    <xsl:apply-templates/>
                </a>
            </xsl:when>
            <xsl:otherwise>
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="@target"/>
                    </xsl:attribute>
                     <xsl:attribute name="target">_blank</xsl:attribute>
                     <xsl:apply-templates/>
                </a>
            </xsl:otherwise>
        </xsl:choose>
     </xsl:template>
 
    <xsl:template match="tei:ptr">
        <xsl:apply-templates/>
        <xsl:choose>
            <xsl:when test="@type='google_books'">
                [<a>
                    <xsl:attribute name="href">
                        <xsl:text>javascript:show_annotation_html('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','</xsl:text><xsl:value-of select="@target"/><xsl:text>',400,600)</xsl:text>
                    </xsl:attribute>
                    <xsl:text>Google Books</xsl:text></a>]
            </xsl:when>
            <xsl:when test="starts-with(@target,'http://')">
                [<a>
                    <xsl:attribute name="href"><xsl:value-of select="@target"/></xsl:attribute>
                    <xsl:attribute name="target">_blank</xsl:attribute>
                    <xsl:text>Link</xsl:text>
                </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>
 
 
 
    <xsl:template match="tei:listBibl">
        <div style="line-height:1em;">
            <xsl:apply-templates/>
        </div>  
    </xsl:template>
 
    <xsl:template match="tei:bibl[parent::tei:listBibl and @n]">
        <xsl:element name="a">
            <xsl:attribute name="name">
                <xsl:value-of select="@xml:id"/>
            </xsl:attribute>
            <xsl:text> </xsl:text>
        </xsl:element>
        <br/>
        <xsl:text>[</xsl:text><a>
            <xsl:attribute name="href">
                <xsl:text>javascript:show_annotation('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','tei-transcript.xml','show_bibliography.xsl','</xsl:text><xsl:value-of select="@xml:id"/><xsl:text>',400,600)</xsl:text>
            </xsl:attribute>
            <xsl:text>Fol. </xsl:text><xsl:value-of select="@n"/>
        </a>
        <xsl:text>] </xsl:text>
        <xsl:apply-templates/>
    </xsl:template>
    
    

    
    <!-- footnotes, annotations -->

    <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="parent::tei:div[@type='footnotes' ]">
                <!--   Fussnoten am Text- oder Seitenende -->
                <div class="footnotes">
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:text>fn</xsl:text>
                         <xsl:value-of select="@n"/>
                    </xsl:attribute>
                    <a>
                        <xsl:attribute name="href">
                            <xsl:text>#fna</xsl:text><xsl:value-of select="@n"/>
                        </xsl:attribute>
                        <span style="font-size:9pt;vertical-align:super;color:blue;margin-right:0.3em;">
                            <xsl:value-of select="@n"/>
                        </span>
                    </a>
                </xsl:element>
                    <xsl:apply-templates/>
                </div>
            </xsl:when>
            <xsl:when test="$caption ='true'">
                <!-- keine Anzeige -->
            </xsl:when>
            <xsl:when test="@type='footnoteX'">
                <!--  noch in Bearbeitung, nicht anzeigen -->
             </xsl:when>   
            <xsl:when test="@type='footnote'">
                <!--  in Text integriert, nur Verweis , Fussnotenabschnitt mit foreach generiert -->
                <xsl:element name="a"> 
                    <xsl:attribute name="name">
                        <xsl:text>fna</xsl:text>
                        <xsl:number level="any" count="tei:note[@type ='footnote']"/>
                    </xsl:attribute>
                    <a>
                        <xsl:attribute name="href">
                            <xsl:text>#fn</xsl:text><xsl:number level="any" count="tei:note[@type ='footnote']"/>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="normalize-space(.)"/>
                        </xsl:attribute>
                        <span style="font-size:9pt;vertical-align:super;color:blue;"><xsl:value-of select="$caption"/><xsl:number level="any" count="tei:note[@type ='footnote']"/></span>
                    </a>
                </xsl:element>
              </xsl:when>
            <xsl:otherwise>
                <xsl:text>(</xsl:text><xsl:apply-templates/><xsl:text>)</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text> </xsl:text>
       
    </xsl:template>
    
    <!-- closer -->
    <xsl:template match="tei:closer">
        <xsl:apply-templates/>
    </xsl:template>
    <!-- Namen -->
    <xsl:template match="tei:name">
        <xsl:apply-templates/>
    </xsl:template>
    <!-- Datum -->
    <xsl:template match="tei:dateline">
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="tei:date">
        <xsl:apply-templates/>
    </xsl:template>
    
    <!-- Grafiken -->
    <xsl:template match="tei:graphic">
        <img src="{@url}" alt="Abbildung" class="illustration"/>
    </xsl:template>
    
    <xsl:template match="tei:figure">
        <xsl:if  test="not(starts-with($pvID,'pv_trans-trans'))">
            <div style="margin:1em;">
                 <img src="{@facs}" alt="Illustration" />
                 <xsl:apply-templates select="tei:figDesc"/>
                 <xsl:apply-templates select="tei:anchor"/>
            </div>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="tei:figDesc">
        <p style="postion:relative; width:235px; font-size:small;margin:0;line-height:1em;text-align:left;"><xsl:text>[</xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>]</xsl:text></p>
    </xsl:template>
    
    
    <!-- index  erst mal auslassen-->
    <xsl:template match="tei:index">
        
    </xsl:template>
    
    <!--  Anker fuer Spruenge im Text -->
    <xsl:template match="tei:anchor">
        <a>
            <xsl:attribute name="name">
                <xsl:value-of select="@xml:id"/>
            </xsl:attribute>
            <xsl:text> </xsl:text>
        </a>
    </xsl:template>
    <!-- lokal ################################################################################################  -->
    
    
   
    <!-- entitaeten -->
    
    <xsl:template match="tei:rs">
        <xsl:choose>
            <xsl:when test="@type='person' or @type='author'">
                <a>
                    <xsl:attribute name="href">
                        <xsl:text>javascript:show_annotation('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','register-person.xml','show_person.xsl','</xsl:text><xsl:value-of select="substring(@ref,2)"/><xsl:text>',300,500)</xsl:text>
                    </xsl:attribute>
                    <xsl:apply-templates/>
                </a>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
        
        
    </xsl:template>
    <!--  Textkritik -->
    
    <xsl:template match="tei:app">
       <xsl:apply-templates select="tei:lem"/>
    </xsl:template>
  
    <xsl:template match="tei:lem">
        <a>
            <xsl:attribute name="name">
                <xsl:text>kAz</xsl:text><xsl:number level="any"/>
            </xsl:attribute>
            <xsl:text> </xsl:text>
        </a>
            <xsl:apply-templates/>
        <a>
            <xsl:attribute name="href">
                <xsl:text>#kA</xsl:text><xsl:number level="any"/>
            </xsl:attribute>
            <xsl:attribute name="title">
                <xsl:value-of select="../tei:rdg"/><xsl:text> (</xsl:text><xsl:value-of select="substring-after(../tei:rdg/@wit,'#')"/><xsl:text>)</xsl:text>
            </xsl:attribute>
            [<xsl:number level="any"/>]
        </a>
    </xsl:template>
    
    
        <xsl:template match="tei:quote | tei:q">
            <i>
                <xsl:apply-templates/>
            </i>
        </xsl:template>
        
    <xsl:template match="tei:hi | tei:emph | tei:del">
           <xsl:choose>
               <xsl:when test="@rend ='italics'">
                   <span style="font-style:italic;"><xsl:apply-templates/></span>
               </xsl:when>
               <xsl:when test="@rend ='bold'">
                   <span style="font-weight:bold;"><xsl:apply-templates/></span>
               </xsl:when>
               <xsl:when test="@rend ='smallCaps'">
                   <span style="font-variant:small-caps;"><xsl:apply-templates/></span>
               </xsl:when>
               <xsl:when test="@rend ='overstrike'">
                   <span style="text-decoration:line-through;"><xsl:apply-templates/></span>
               </xsl:when>
               <xsl:when test="@rend ='super'">
                   <span style="vertical-align:super; font-size: .83em;"><xsl:apply-templates/></span>
               </xsl:when>
                   <xsl:when test="@rend ='underline'">
                       <span style="text-decoration:underline;"><xsl:apply-templates/></span>
               </xsl:when>
               <xsl:otherwise>
                   <xsl:apply-templates/>
               </xsl:otherwise>
           </xsl:choose>
       </xsl:template>
       
       <!-- spezifica -->
       <!-- Bibliographie hier ausschlaten -->
       <xsl:template match="tei:back"/>
    
    <xsl:template match="tei:lg">
        <div>
            <xsl:apply-templates/>
        </div>
    </xsl:template>
    
    <xsl:template match="tei:l">
        <br/>
        <xsl:if test="@n">
            <span style="position:relative;left:-0.5em;font-size:small;">(<xsl:value-of select="@n"/>)</span>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="tei:corr">
        <xsl:text>[</xsl:text>
            <xsl:apply-templates/>
        <xsl:text>]</xsl:text>
    </xsl:template>

    <xsl:template match="tei:unclear">   
    <xsl:choose>
           <xsl:when test="@cert ='high'">
            <xsl:apply-templates/>
            <xsl:text>[?]</xsl:text>
        </xsl:when>
        <xsl:when test="@cert ='medium'">
            <xsl:apply-templates/>
            <xsl:text>[??]</xsl:text>
        </xsl:when>
        <xsl:when test="@cert ='low'">
            <xsl:apply-templates/>
            <xsl:text>[???]</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates/>
        </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
 
  
    <xsl:template match="tei:gap">   
        <xsl:choose>
            <xsl:when test="@extent ='0'">
                <xsl:apply-templates/>
                <xsl:text>[]</xsl:text>
            </xsl:when>
            <xsl:when test="@extent ='3'">
                <xsl:apply-templates/>
                <xsl:text>...</xsl:text>
            </xsl:when>
            <xsl:when test="@extent ='9'">
                <xsl:apply-templates/>
                <xsl:text>.........</xsl:text>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
 
 
    <xsl:template match="tei:add">   
        <span>
            <xsl:if test="@resp ='different'">
                <xsl:attribute name="style">
                    background-color:#EEE;
                </xsl:attribute>
                <xsl:attribute name="title">different hand</xsl:attribute>
            </xsl:if>
        <xsl:choose>
            <xsl:when test="@place ='above'">
                <xsl:text>[ABOVE: </xsl:text>
                <xsl:apply-templates/>
                <xsl:text>]</xsl:text>
            </xsl:when>
            <xsl:when test="@place ='beyond'">
                <xsl:text>[BEYOND: </xsl:text>
                <xsl:apply-templates/>
                <xsl:text>]</xsl:text>
              </xsl:when>
            <xsl:when test="@place ='margin'">
                <xsl:text>[MARGIN: </xsl:text>
                <xsl:apply-templates/>
                <xsl:text>]</xsl:text>
            </xsl:when>
            <xsl:when test="@place ='insert'">
            <xsl:text> [INSERT:] </xsl:text>
            <xsl:apply-templates/>
            </xsl:when>
            <xsl:when test="@place ='super'">
                <span style="vertical-align:super; font-size: .83em;"><xsl:apply-templates/></span>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
        </span>
    </xsl:template>
    
    <xsl:template match="tei:emph">   
        <xsl:apply-templates/>
        <xsl:text> [!] </xsl:text>
    </xsl:template>
    
    <xsl:template match="tei:anchor">
        <span style="position:absolute;left:1em;"><xsl:text>[</xsl:text>
            <a>
                <xsl:attribute name="href">
                    <xsl:text>javascript:show_annotation('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','tei-commentary.xml','show_commentary.xsl','</xsl:text><xsl:value-of select="@xml:id"/><xsl:text>',400,600)</xsl:text>
                </xsl:attribute>
                <xsl:attribute name="title">commentary</xsl:attribute>
                <xsl:text>C</xsl:text>
            </a>
         <xsl:text>]</xsl:text></span>
    </xsl:template>
    
 
</xsl:stylesheet>
