<?xml version="1.0" encoding="UTF-8"?>

<!--XSL zur Ausgabe von TEI-konformen Editionen in der WDB (hier:Theatra) / staecker; 2012-05-22 -->

<xsl:stylesheet
    xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:tei="http://www.tei-c.org/ns/1.0"
    xmlns:mets="http://www.loc.gov/METS/"
    xmlns:mods="http://www.loc.gov/mods/v3"
    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="html tei" 
    version="1.0">
    
    
    <!-- Einbindung der Standard-Templates -->
    <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: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;">
                        Inhalt
                    </div>
                    <hr style="margin:0;padding:0;height:1px;"/>
                    <!-- weitere Funktionen rechtsbuendig -->
                </div>
                <!-- Titel -->
                <div id="caption">
                    <div>
                        <xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/>
                    </div>
                    <div style="font-size:0.8em;font-weight:300;margin:0.3em 0 1em 0;">
                        <xsl:for-each select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:author">
                            <xsl:if test="position() > 1"><xsl:text>, </xsl:text></xsl:if>
                            <xsl:value-of select="tei:forename"/><xsl:text> </xsl:text><xsl:value-of select="tei:surname"/>
                        </xsl:for-each>
                        <xsl:if test="//tei:encodingDesc/tei:projectDesc/tei:p[not(@xml:id)]">
                            <div style="margin-top:0.5em;font-style:italic;"><xsl:value-of select="//tei:encodingDesc/tei:projectDesc/tei:p[not(@xml:id)]"/></div>
                        </xsl:if>
                    </div>
                 </div>
                <!-- Inhaltsuebersicht -->
                <div id="headings">
                    <ul>
                        <xsl:for-each select="/tei:TEI/tei:text/tei:body//tei:div/tei:head">
                            <li>
                                <xsl:number level="multiple" count="tei:div" format="1.1. "/>
                                <a>
                                    <xsl:attribute name="href"><xsl:text>#hd</xsl:text><xsl:number level="any"/></xsl:attribute>
                                    <xsl:choose>
                                        <xsl:when test="tei:ref">
                                            <xsl:value-of select="tei:ref/text()"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="text()"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                    <!--<xsl:apply-templates>
                                        <xsl:with-param name="caption">true</xsl:with-param>
                                    </xsl:apply-templates>-->
                                </a>
                                <xsl:apply-templates select="../tei:argument/tei:p">
                                    <xsl:with-param name="caption">true</xsl:with-param>
                                </xsl:apply-templates>
                            </li>
                        </xsl:for-each>
                    </ul>
                </div>
                <!-- Haupttext -->
                <div class="content" style="text-align:justify;font-size:0.9em;">
                   <xsl:apply-templates select="tei:TEI/tei:text/tei:body"/>
                </div>
                
                <div class="footnotes">
                    <!-- Fussnotenbereich  -->
                    
                    <xsl:choose>
                        <xsl:when test="tei:TEI/tei:text/tei:body/tei:div[@type='footnotes']">
                            <a name="footnotes">
                                <hr style="width:50%;height:1px;margin:1em 0 1em 0;"/>
                            </a>
                            <!--  Wenn es einen Fussnotenbereich gibt -->
                            <xsl:apply-templates select="tei:TEI/tei:text/tei:body/tei:div[@type='footnotes']"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:if test="tei:TEI/tei:text/tei:body//tei:note[@type='footnote']">
                                <a name="footnotes">
                                    <hr style="width:50%;height:1px;margin:1em 0 1em 0;"/>
                                </a>
                            </xsl:if>
                            <!--  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:0.7em;vertical-align:super;color:blue;margin-right:0.3em;"><xsl:number level="any" count="tei:note[@type ='footnote']"/></span>
                                        </a>
                                        <xsl:apply-templates/>
                                    </xsl:element>
                                </div>
                            </xsl:for-each>
                        </xsl:otherwise>
                    </xsl:choose>
                </div>
                    <!-- footer -->
                    <div id="doc_footer">
                        <hr/>
                                <b>
                                    <xsl:text>© </xsl:text>
                                    <xsl:for-each select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:author">
                                        <xsl:if test="position() > 1"><xsl:text>; </xsl:text></xsl:if>
                                        <xsl:value-of select="tei:forename"/><xsl:text> </xsl:text><xsl:value-of select="tei:surname"/>
                                    </xsl:for-each>
                                  </b>
                                <a>
                                    <img src="http://diglib.hab.de/images/cc-by-sa.png" alt="image CC BY-SA licence" width="50px" align="right" hspace="10px"/>
                                </a>
                        </div>
                    <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>
                
            </body>
        </html>
    </xsl:template>
    
    <!--  bibliography -->
    <xsl:template match="tei:listBibl">
        <p class="content">
            <xsl:choose>
                <xsl:when test="tei:bibl">
                    <ul>
                        <xsl:apply-templates/>
                            <!--<xsl:sort/>
                        </xsl:apply-templates>-->
                    </ul>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates/>
                </xsl:otherwise>
            </xsl:choose>
        </p>
    </xsl:template>
    
    
    
    <xsl:template match="tei:bibl">
        <xsl:choose>
            <xsl:when test="ancestor::tei:div[1][@type = 'digital_editions']">
                <div>
                <xsl:choose>
                    <xsl:when test="//tei:list">
                        <xsl:apply-templates/>
                    </xsl:when>
                    <xsl:otherwise>
                        <ul>
                            <li>
                                <xsl:apply-templates/>
                            </li>
                        </ul>
                    </xsl:otherwise>
                </xsl:choose>
                </div>
            </xsl:when>
            <xsl:when test="parent::tei:listBibl">
                <li>
                    <a>
                        <xsl:attribute name="name">
                            <xsl:value-of select="@xml:id"/>
                        </xsl:attribute>
                    </a>
                    <xsl:apply-templates/>
                </li>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
     </xsl:template>
    
    <!-- lists  -->
    <!--  copies liste -->
    <xsl:template match="tei:list" mode="copies">
      <xsl:for-each select="tei:item">
            <div style="margin-top:1em;font-style:italic;"><xsl:value-of select="tei:label"/></div>
              <div style="margin-left:2em;">
                  <xsl:apply-templates select="tei:list/tei:item"/>
              </div>
        </xsl:for-each>
    </xsl:template>
    
    
    
    <xsl:template match="tei:list">
        <xsl:apply-templates select="tei:head"/>
        <xsl:choose>
            <xsl:when test="@type='ordered'">
                <ol>
                    <xsl:apply-templates select="tei:item"/>
                </ol>
            </xsl:when>
            <xsl:otherwise>
                <ul>
                    <xsl:choose>
                        <!-- sortieren nach label, wenn vorhanden -->
                        <xsl:when test="tei:label">
                            <xsl:apply-templates select="tei:label">
                                <!--<xsl:sort data-type="text" xml:lang="de" case-order="upper-first"/>-->
                            </xsl:apply-templates>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="tei:item"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </ul>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="tei:item">
        <li>
            <xsl:if test="preceding-sibling::tei:label[1]">
                <xsl:value-of select="preceding-sibling::tei:label[1]"/>
                <xsl:choose>
                    <xsl:when test="ancestor::tei:biblStruct[@type='source']">
                        <xsl:text>, </xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text> </xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
            <xsl:apply-templates/>
        </li>
    </xsl:template>
    
    <xsl:template match="tei:label">
        <!--  <xsl:value-of select="."/><xsl:text>: </xsl:text>-->
        
        <xsl:if test="following-sibling::tei:item[1]">
            <xsl:apply-templates select="following-sibling::tei:item[1]"/> 
        </xsl:if>
    </xsl:template>
    
    
    
    <!-- text -->
    <xsl:template match="tei:div">
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="tei:head">
       <xsl:choose>
           <xsl:when test="parent::tei:list"> 
               <hr style="margin-top:2em;"/><h2><xsl:apply-templates/></h2>
           </xsl:when>
           <xsl:otherwise>
               <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><xsl:number level="multiple" count="tei:div" format="1.1. "/><xsl:apply-templates/></div>
                   <div style="position:absolute;left:95%;top:0.5em;"><a href="#" title="up"><img src="http://diglib.hab.de/images/arrowup.png" alt="[arrow up]" border="0"/></a></div>
               </h2>
           </xsl:otherwise>
       </xsl:choose>
    </xsl:template>
    
    <xsl:template match="tei:note">
        <xsl:param name="caption"/>
        <!--  zwei Typen: entweder Fussnoten am Text- oder Seitenende in einem besonderen Abschnitt oder in den Text integriert -->
        <xsl:choose>
            <xsl:when test="parent::tei:div[@type='footnotes' ]">
                <!--   Fussnoten am Text- oder Seitenende -->
                <div id="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:0.7em;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='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>
                </xsl:element>
                <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:0.6em;vertical-align:super;color:blue;"><xsl:number level="any" count="tei:note[@type ='footnote']"/></span>
                </a>
            </xsl:when>
            <xsl:when test="@type = 'history_of_the_work'">
                <div style="font-size:small; font-sytle:italic;">
                    <xsl:apply-templates/>
                </div>
            </xsl:when>
            <xsl:when test="@type='copies'">
               <div style="margin-top:1em;">
                   <div style="margin:1em;">
                       <xsl:value-of select="tei:head"/>
                   </div>
                    <div>
                        <xsl:value-of select="tei:label"/>
                    </div>
                        <xsl:apply-templates select="tei:list" mode="copies"/>
                </div>    
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>(</xsl:text><xsl:apply-templates/><xsl:text>)</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="tei:ptr">
        <xsl:apply-templates/>
        <xsl:choose>
            <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="starts-with(@target,'#')">
                [<a>
                    <xsl:attribute name="href"><xsl:value-of select="@target"/></xsl:attribute>
                    <xsl:text>Link</xsl:text>
                </a>]
            </xsl:when>
            <xsl:when test="@cRef">
                <xsl:call-template name="referencesPTR">
                    <xsl:with-param name="refType">
                        <xsl:value-of select="@type"/>
                    </xsl:with-param>
                    <xsl:with-param name="refValue">
                        <xsl:value-of select="@cRef"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="tei:ref ">
        <a>
             <xsl:attribute name="href">
                <xsl:choose>
                    <xsl:when test="contains(@target,'@')">
                        <xsl:text>mailto://</xsl:text><xsl:value-of select="@target"/>
                    </xsl:when>
                    <xsl:when test="@target">
                        <xsl:choose>
                            <xsl:when test="@type ='bibliography'">
                                <!--<xsl:text>javascript:show_annotation('</xsl:text><xsl:value-of select="$dir"/><xsl:text>','tei-inhalt.xml','http://diglib.hab.de/rules/styles/projekte/theatra/tei-bibliography.xsl','</xsl:text><xsl:value-of select="substring(@target,2)"/><xsl:text>',400,500)</xsl:text>-->
                                <xsl:value-of select="@target"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@target"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test="@cRef">
                        <xsl:choose>
                            <xsl:when test="@type = 'opac'"><xsl:value-of select="$opac"/></xsl:when>

                            <xsl:when test="@type = 'gbv'"><xsl:value-of select="$gbv"/></xsl:when>
                            <xsl:when test="@type = 'urn'"><xsl:value-of select="$urn"/></xsl:when>
                            <xsl:when test="@type = 'vd16'"><xsl:value-of select="$vd16"/></xsl:when>
                            <xsl:when test="@type = 'vd17'"><xsl:value-of select="$vd17"/></xsl:when>
                            <xsl:otherwise>javascript:alert('Code not supported please check wdb dokumentation at  http://www.hab.de/bibliothek/wdb/doku/links.htm');</xsl:otherwise>
                        </xsl:choose>
                        <xsl:value-of select="@cRef"/>
                    </xsl:when>
                </xsl:choose>
             </xsl:attribute>
             <xsl:attribute name="title">
                 <xsl:choose>
                     <xsl:when test="starts-with(@target,'#')">
                         <xsl:choose>
                             <xsl:when test="id(substring(@target,2))//tei:title[@type='short']">
                                 <xsl:value-of select="normalize-space(id(substring(@target,2))//tei:title[@type='short'])"/>
                                 <xsl:text>. </xsl:text>
                                 <xsl:value-of select="normalize-space(id(substring(@target,2))//tei:pubPlace[1])"/>
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="normalize-space(id(substring(@target,2))//tei:date)"/>
                             </xsl:when>
                             <xsl:otherwise>
                                 <xsl:value-of select="normalize-space(id(substring(@target,2)))"/>
                             </xsl:otherwise>
                         </xsl:choose>
                      </xsl:when>
                     <xsl:when test="@n">
                         <xsl:value-of select="@n"/>
                     </xsl:when>
                     <xsl:otherwise>
                         <xsl:text>Link</xsl:text>
                     </xsl:otherwise>
                 </xsl:choose>
             </xsl:attribute>
            <xsl:if test="starts-with(@target,'http://') or starts-with(@target,'https://') or @cRef">
                <!-- neue Seite, wenn nach aussen -->
                <xsl:attribute name="target">
                    _blank
                </xsl:attribute>
            </xsl:if>
            <xsl:apply-templates/> 
        </a>
    </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>
    
    <xsl:template match="tei:biblStruct">
        <div style="border:1px solid gray;margin:1em;padding:1em;margin-top:1em;">
             <xsl:apply-templates select="tei:monogr"/>
        </div>
    </xsl:template>
    
    <xsl:template match="tei:monogr">
        <div style="position:relative;">
               <div style="float:right;">
                   <xsl:for-each select="tei:title/tei:ref/tei:graphic">
                        <img border="0" style="height:300px;margin-left:2em;">
                         <xsl:attribute name="src">
                             <!--<xsl:value-of select="tei:title/tei:ref/tei:graphic/@url[not(contains(.,'(2)'))]"/>-->
                             <xsl:value-of select="@url"/>
                         </xsl:attribute>
                        </img>
                   </xsl:for-each>
               </div>
               <div>
                   <xsl:apply-templates select="tei:title"/>
                   <xsl:apply-templates select="tei:imprint"/>
                   <xsl:apply-templates select="tei:extent"/>
                   <xsl:apply-templates select="../tei:idno"/>
                   <xsl:apply-templates select="../tei:note[@type='copies']"/> 
                   <xsl:apply-templates select="../tei:note[@type ='history_of_the_work']"/> 
                </div>   
                <div style="clear:both;"/>
            </div>
    </xsl:template>
    <!--  bibliographische Angaben  -->
    
    <xsl:template match="tei:idno">
        <xsl:text> [</xsl:text>
        <xsl:choose>
            <xsl:when test="@type='siglum'">
               <xsl:text>Sigle: </xsl:text><xsl:value-of select="."/>  
            </xsl:when>
            <xsl:otherwise>
                        <xsl:value-of select="@type"/><xsl:text> ↗</xsl:text>
                    <a>
                        <xsl:attribute name="target">_blank</xsl:attribute>
                        <xsl:attribute name="href">
                    <xsl:choose>
                        <xsl:when test="@type = 'opac'">
                            <xsl:value-of select="concat($opac,.)"/>
                        </xsl:when>
                       
                        <xsl:when test="@type = 'gbv'">
                            <xsl:value-of select="$gbv"/><xsl:value-of select="."/>
                        </xsl:when>
                        <xsl:when test="@type = 'urn'">
                            <xsl:value-of select="$urn"/><xsl:value-of select="."/>
                        </xsl:when>
                        <xsl:when test="@type = 'vd16'">
                            <xsl:value-of select="concat($vd16,.)"/>
                        </xsl:when>
                        <xsl:when test="@type = 'vd17'">
                            <xsl:value-of select="concat($vd17,.)"/>
                        </xsl:when>
                        <xsl:when test="@type = 'vd18'">
                            <xsl:value-of select="concat($vd18,.)"/>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:text> javascript:alert('Code not supported please check wdb dokumentation at  http://www.hab.de/bibliothek/wdb/doku/links.htm');</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                        </xsl:attribute>
                        <xsl:value-of select="."/>
                    </a>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text>]</xsl:text>
     </xsl:template>
    
    <xsl:template match="tei:title">
        <xsl:choose>
            <xsl:when test="@type='sub' or @type='short' ">
                <!-- erst mal ausblenden ### -->
            </xsl:when>
            <xsl:otherwise>
                <i><xsl:apply-templates/></i>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
    
    <xsl:template match="tei:imprint">
        <xsl:apply-templates select="tei:pubPlace"/>
        <xsl:apply-templates select="tei:publisher"/>
        <xsl:apply-templates select="tei:date"/>
    </xsl:template>
    
    <xsl:template match="tei:pubPlace">
        <xsl:if test="position() &gt; 1"><xsl:text>;</xsl:text></xsl:if>
        <xsl:text> </xsl:text>
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="tei:publisher">
        <xsl:if test="position()= 1"><xsl:text>: </xsl:text></xsl:if>
        <xsl:if test="position() &gt; 1"><xsl:text>, </xsl:text></xsl:if>
        <xsl:apply-templates/>
        <xsl:if test="position() = last() and ../tei:date">
            <xsl:text>, </xsl:text>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="tei:date">
        <xsl:if test="not(preceding-sibling::tei:publisher)">
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="tei:extent">
        <xsl:text>. - </xsl:text>
        <xsl:apply-templates/>
    </xsl:template>
    
    
        <xsl:template match="tei:quote">
            <xsl:text>„</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>“</xsl:text>
        </xsl:template>
    
    <xsl:template match="tei:pb">
        <a>
            <xsl:attribute name="name">
                <xsl:value-of select="substring(@facs,2)"/>
            </xsl:attribute>
            <xsl:text> </xsl:text>
        </a> 
            <xsl:text>(</xsl:text>
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>http://diglib.hab.de/</xsl:text>
                    <xsl:value-of select="substring-before(substring(@facs,2),'_')"/>
                    <xsl:text>/</xsl:text>
                    <xsl:value-of
                        select="substring-before(substring-after(substring(@facs,2),'_'),'_')"/>
                    <!-- select Image-No , e.g. 00006  -->
                    <xsl:text>/start.htm?image=</xsl:text>
                    <xsl:value-of
                        select="substring-after(substring-after(substring(@facs,2),'_'),'_')"
                    />
                </xsl:attribute>
                <!-- editionsspezifisch -->
                <xsl:choose>
                    <xsl:when test="$pvID = 'edoc_ed000145_transfacs_pnr' or $pvID = 'edoc_ed000145_transfacs_nul'">
                        <xsl:attribute name="target">display2</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="target">_blank</xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="@n"/>
            </xsl:element>
            <xsl:text>)</xsl:text>
       </xsl:template>
    
    <!-- lokal -->
    <xsl:template match="tei:rs">
        <xsl:apply-templates/>
        <xsl:if test="@key">
            <xsl:text> [</xsl:text><a>
                <xsl:attribute name="href">
                    <xsl:value-of select="$gnd"/><xsl:value-of select="substring-after(@key,'_')"/>
                </xsl:attribute>
                <xsl:attribute name="target">_blank</xsl:attribute>
                <xsl:text>↗GND</xsl:text>
            </a><xsl:text>]</xsl:text>
         </xsl:if>
    </xsl:template>
    
    <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>
    
   
     <xsl:template match="tei:abbr">
         <span>
             <xsl:attribute name="title">
                 <xsl:apply-templates select="../tei:expan/text()"></xsl:apply-templates>
             </xsl:attribute>
             <xsl:apply-templates/>
         </span>
     </xsl:template>
    
    
    <!-- ausschalten -->
    <xsl:template match="tei:graphic"/>
    <xsl:template match="tei:expan"/>
    
    
    
</xsl:stylesheet>