<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:s="http://www.w3.org/2001/sw/DataAccess/rf1/result" xmlns:oai="http://www.openarchives.org/OAI/2.0/" xmlns:str="http://exslt.org/strings" xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:functx="http://www.functx.com" xmlns:schema="http://schema.org/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="#all" version="2.0">
      
    <xsl:include href="corema-static.xsl"/>
    <xsl:include href="corema-meta.xsl"/>
    <xsl:strip-space elements="*"/>   
    
    <xsl:function name="functx:capitalize-first" as="xs:string?"
        xmlns:functx="http://www.functx.com">
        <xsl:param name="arg" as="xs:string?"/>
        
        <xsl:sequence select="
            concat(upper-case(substring($arg,1,1)),
            substring($arg,2))
            "/>
        
    </xsl:function>
    <xsl:variable name="context">context:corema.<xsl:value-of select="tokenize($teipid,'\.')[2]"/></xsl:variable>
    <xsl:variable name="ms">
        <xsl:choose>
            <xsl:when test="contains($teipid,'n2') or contains($teipid,'a1') or contains($teipid,'ha1') or contains($teipid,'ka1') or contains($teipid,'m2') or contains($teipid,'m3') or contains($teipid,'m5') or contains($teipid,'m8') or contains($teipid,'h2') or contains($teipid,'ha1') or contains($teipid,'m5') or contains($teipid,'m13') or contains($teipid,'pa1') or contains($teipid,'sb2') or contains($teipid,'st1') or contains($teipid,'wo1') or contains($teipid,'wo3') or contains($teipid,'wo7') or contains($teipid,'wo9') or contains($teipid,'wo10') or contains($teipid,'wo11')">
                <xsl:text>o:corema.</xsl:text><xsl:value-of select="replace(tokenize($teipid,'\.')[2],'a\b|b\b|c\b','','!')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>o:corema.</xsl:text><xsl:value-of select="tokenize($teipid,'\.')[2]"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="recipeID" select="//t:body/t:div/@xml:id"/>
    <xsl:variable name="recipe_dollar1">
        <xsl:value-of select="concat('%24',1,'%7C','%3C','https://gams.uni-graz.at/o:corema.',$recipeID,'%3E')"/>
    </xsl:variable>
    <xsl:variable name="collection_dollar2">
        <xsl:value-of select="concat('%24',2,'%7C','%3C','https://gams.uni-graz.at/',$ms,'%3E')"/>
    </xsl:variable>
    <xsl:variable name="ingredientSequencesQuery">
        <xsl:value-of select="document(concat('/archive/objects/query:corema.ingredientsequences/methods/sdef:Query/getXML?params=',$recipe_dollar1,'%3B',$collection_dollar2))//s:rec2C"/>
    </xsl:variable>
    <xsl:variable name="toolSequencesQuery">
        <xsl:value-of select="document(concat('/archive/objects/query:corema.toolsequences/methods/sdef:Query/getXML?params=',$recipe_dollar1,'%3B',$collection_dollar2))//s:rec2C"/>
    </xsl:variable>
    <xsl:variable name="dishCategoriesQuery">
        <xsl:value-of select="concat('/archive/objects/query:corema.dishcategories/methods/sdef:Query/getXML?params=',$recipe_dollar1)"/>
    </xsl:variable>
    
    <xsl:variable name="neighbour-next">
        
            <xsl:value-of
                select="document(concat('/archive/objects/', $context, '/methods/sdef:Context/getNeighbours?identifier=', $teipid))//neighbours/next/identifier"
            />
        
    </xsl:variable>
    
    <xsl:variable name="neighbour-prev">
        
            <xsl:value-of
                select="document(concat('/archive/objects/', $context, '/methods/sdef:Context/getNeighbours?identifier=', $teipid))//neighbours/previous/identifier"
            />
        
    </xsl:variable>
    
    <xsl:template name="content">
        
        <nav class="navbar navbar-expand-md navbar-dark fixed-bottom" id="bottom_nav">
            <div class="container">
                <a class="navbar-brand d-md-none" href="#">Bottom Nav</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse"
                    data-target="#bottomnavbarCollapse" aria-controls="navbarCollapse"
                    aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"> </span>
                </button>
                <div id="bottomnavbarCollapse" class="collapse navbar-collapse">
                    <ul class="navbar-nav mr-auto">
                        <li class="nav-item" title="Manuscript Description">
                            <a class="nav-link py-1 text-white" href="/{$ms}/sdef:TEI/get?mode=view:msdesc"><span class="oi oi-book"><xsl:text> </xsl:text></span> Description</a>
                        </li>
                        <li class="nav-item" title="Annotated Recipes of the Manuscript">
                            <a class="nav-link py-1 text-white" href="{concat('/',$ms,'.recipes','#',substring-after($teipid,'corema.'))}"><span class="oi oi-layers"><xsl:text> </xsl:text></span> Recipes</a>
                        </li>
                        <li class="nav-item" title="Hyperdiplomatic Transcription of the Manuscript">
                            <a class="nav-link py-1 text-white" href="{substring-after(//t:bibl[@type='manuscript_page']/t:ref/@target,'.at')}"><span class="oi oi-image"><xsl:text> </xsl:text></span> Transcription</a>
                        </li>
                        <li class="nav-item" title="Metadata and Downloads (Use your Browsers Back-Button to Come Back Here">
                            <a class="nav-link py-1 text-white" href="/{$teipid}/sdef:Object/getDC"><span class="icon-TEIlogo"><xsl:text> </xsl:text></span> Metadata</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <div id="BRnavCntlBtm" class="BRnavCntl BRdn" title="Show/Hide Functionalities" style="overflow: hidden; height: 30px; opacity: 0.25; z-index:1"><xsl:text> </xsl:text></div>
        
                 
        <section class="row">                                                     
                   <article class="col-md-8">
                        <div class="card">
                            <div class="card-body">
                                <div class="row align-items-center">
                                    <div class="col-md-1">
                                        <xsl:choose>
                                            <xsl:when test="string-length($neighbour-prev) > 1">
                                            <a title="Previous Recipe">
                                                <xsl:attribute name="href">
                                                    <xsl:text>/</xsl:text>
                                                    <xsl:value-of select="$neighbour-prev"/>
                                                </xsl:attribute>
                                                <i class="fas fa-backward fa-2x">
                                                <xsl:text> </xsl:text>
                                                </i>                                                   
                                            </a>                                             
                                            </xsl:when>
                                            <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
                                        </xsl:choose>
                                    </div>
                                    <div class="col-md-10 text-center">
                                        <h1>
                                            <xsl:value-of select="//t:titleStmt/t:title[@xml:lang = 'en']"/>
                                        </h1>
                                        <xsl:choose>
                                            <xsl:when test="//t:titleStmt/t:title[not(@xml:lang = 'en')]">
                                                <h5 title="Original Title">
                                                    <xsl:value-of
                                                        select="//t:titleStmt/t:title[not(@xml:lang = 'en')]"
                                                    />
                                                </h5>
                                            </xsl:when>
                                        </xsl:choose>
                                    </div>
                                    <div class="col-md-1">
                                        <xsl:choose>
                                            <xsl:when test="string-length($neighbour-next) > 1">
                                                <a title="Next Recipe">
                                                    <xsl:attribute name="href">
                                                        <xsl:text>/</xsl:text>
                                                        <xsl:value-of select="$neighbour-next"/>
                                                    </xsl:attribute>
                                                    <i class="fas fa-forward fa-2x">
                                                        <xsl:text> </xsl:text>
                                                    </i>                                                   
                                                </a>                                             
                                            </xsl:when>
                                            <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
                                        </xsl:choose>    
                                    </div>
                                </div>
                            </div>
                        </div>
                       <section class="row">
                           <article class="col-md-6">
                            <div class="card">
                                <div class="card-body">
                                    <h2 class="card-title">Ingredients:</h2>
                                    <ul>
                                        <xsl:choose>
                                            <xsl:when test="//t:ingredient[@commodity != 'Q0'][not(@ana)]">
                                                <xsl:for-each-group select="//t:ingredient[@commodity != 'Q0'][not(@ana)]" group-by="@en">
                                                    <xsl:sort select="current-grouping-key()"/>
                                                    <li><xsl:value-of select="."/><xsl:text> (</xsl:text><a href="/archive/objects/query:corema.label/methods/sdef:Query/get?params=%241%7C%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F{@commodity}%3E"><xsl:value-of select="@en"/></a><xsl:text>)</xsl:text></li>
                                                </xsl:for-each-group>
                                            </xsl:when>
                                            <xsl:otherwise><li>No ingredients mentioned</li></xsl:otherwise>
                                        </xsl:choose>
                                    </ul>
                                    <h2 class="card-title">Tools:</h2>
                                    <ul>       
                                        <xsl:choose>
                                            <xsl:when test="//t:tool">
                                                <xsl:for-each-group select="//t:tool" group-by="@en">
                                                    <xsl:sort select="current-grouping-key()"/>
                                                    <li><xsl:value-of select="."/><xsl:text> (</xsl:text><a href="/archive/objects/query:corema.label/methods/sdef:Query/get?params=%241%7C%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F{@commodity}%3E"><xsl:value-of select="@en"/></a><xsl:text>)</xsl:text></li>
                                                </xsl:for-each-group>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <li>No tools mentioned</li>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </ul>
                                </div>
                            </div>
                           </article>
                           <article class="col-md-6">
                               <div class="card">
                                   <div class="card-body">
                                       <h2 class="card-title">Metadata:</h2>
                                       <span class="d-block tt">
                                           <span class="tttext"><xsl:apply-templates select="//t:msIdentifier/t:settlement"/><xsl:text>, </xsl:text><xsl:value-of select="//t:msIdentifier/t:institution"/><xsl:if test="//t:msIdentifier/t:repository"><xsl:text>, </xsl:text><xsl:value-of select="//t:msIdentifier/t:repository"/></xsl:if><xsl:text>, </xsl:text><xsl:value-of select="//t:msIdentifier/t:idno"/></span>
                                           <xsl:text>Source Collection: </xsl:text>
                                           <a href="/{$ms}/sdef:TEI/get?mode=view:msdesc" target="_blank">
                                               <xsl:value-of select="//t:bibl[@type='corresponding_manuscript']//t:altIdentifier[@type='abbr']/t:idno"/></a><xsl:text>, fol. </xsl:text><a title="Go to hyperdiplomatic transcription" href="{substring-after(//t:bibl[@type='manuscript_page']/t:ref/@target,'.at')}"><xsl:value-of select="substring-after(//t:bibl[@type='manuscript_page']/t:ref/@target,'_')"/></a>
                                         
                                       </span>
                                       <span class="d-block"><xsl:text>Recipe Nr. </xsl:text><span><xsl:value-of select="//t:body/t:div/@n"/></span><xsl:text> </xsl:text><a title="Go to hyperdiplomatic transcription" href="{substring-after(//t:bibl[@type='manuscript_page']/t:ref/@target,'.at')}"><span class="oi oi-image"><xsl:text> </xsl:text></span></a><xsl:text> </xsl:text><a title="View recipe in context" href="{concat('/',$ms,'.recipes','#',substring-after($teipid,'corema.'))}"><span class="oi oi-layers"><xsl:text> </xsl:text></span></a></span>
                                       <span class="d-block"><xsl:text>Dating: </xsl:text><span><xsl:value-of select="//t:creation/t:origDate/t:date[@xml:lang='en']"/></span></span>
                                       <span class="d-block"><xsl:text>Origin: </xsl:text><span><xsl:value-of select="//t:creation/t:origPlace/t:placeName[@xml:lang='en']"/></span></span>
                                       <span class="d-block"><xsl:text>Lang: </xsl:text><xsl:for-each select="//t:langUsage/t:language"><span><xsl:value-of select="."/></span><xsl:choose>
                                           <xsl:when test="position() = last()"/>
                                           <xsl:otherwise>, </xsl:otherwise>
                                       </xsl:choose></xsl:for-each></span>                                        
                                   </div>
                               </div>
                               
                               <div class="card">
                                   <div class="card-body">
                                       <h2 class="card-title">Similar recipes:</h2>                            
                                       <span class="d-block"><xsl:text>Same title: </xsl:text><span>
                                           <xsl:choose>
                                               <xsl:when test="//t:titleStmt/t:title[@xml:lang = 'en'] and normalize-space(//t:titleStmt/t:title[@xml:lang = 'en']) != ''">
                                                   <xsl:for-each select="document(concat('/archive/objects/query:corema.samerecipetitle/methods/sdef:Query/getXML?params=%241%7C',//t:titleStmt/t:title[@xml:lang = 'en']))//s:recipes/@uri"><a href="{.}"><xsl:value-of select="substring-after(.,'o:corema.')"/></a><xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if></xsl:for-each>
                                               </xsl:when>
                                               <xsl:otherwise>No English title provided</xsl:otherwise>
                                           </xsl:choose>
                                       </span></span>
                                        <xsl:variable name="ing">
                                            <xsl:value-of select="concat('%24', 1, '%7C')"/>
                                            <xsl:choose>
                                                <xsl:when
                                                    test="//t:ingredient[@commodity != 'Q0'][not(@ana)]">
                                                    <xsl:for-each-group
                                                        select="//t:ingredient[@commodity != 'Q0'][not(@ana)]"
                                                        group-by="@commodity">
                                                        <xsl:text>%3Chttp://www.wikidata.org/entity/</xsl:text>
                                                        <xsl:value-of select="current-grouping-key()"/>
                                                        <xsl:text>%3E</xsl:text>
                                                        <xsl:if test="position() != last()">
                                                          <xsl:text>%2C</xsl:text>
                                                        </xsl:if>
                                                    </xsl:for-each-group>
                                                </xsl:when>
                                                <xsl:otherwise><xsl:text>%3Chttp://www.wikidata.org/entity/Q0%3E</xsl:text></xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:variable>
                                      
                                       <xsl:variable name="heatMapColor">
                                           <xsl:choose>
                                               <xsl:when test="$ingredientSequencesQuery='1'">#ffffcc</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='2'">#ffeda0</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='3'">#fed976</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='4'">#feb24c</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='5'">#fd8d3c</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='6'">#fc4e2a</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='7'">#e31a1c</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='8'">#bd0026</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery='9'">#800026</xsl:when>
                                               <xsl:when test="$ingredientSequencesQuery>'9'">#800026</xsl:when>
                                           </xsl:choose>
                                       </xsl:variable>
                                       <span class="d-block"><xsl:text>Shared ingredients: </xsl:text><span><xsl:for-each select="document(concat('/archive/objects/query:corema.samerecipeingredients/methods/sdef:Query/getXML?params=',$ing))//s:recipes/@uri"><a href="{.}"><xsl:value-of select="substring-after(.,'o:corema.')"/></a><xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if></xsl:for-each></span></span>
                                       <!--WIEDER EINSCHALTEN WENN BLAZEGRAPH AUF GAMS UPGEDATED WURDE-->
                                       <span class="d-block"><xsl:text>Same ingredients in following recipe: </xsl:text>
                                            <xsl:choose>                                     
                                                <xsl:when test="$ingredientSequencesQuery != ''">
                                                    <b style="background:{$heatMapColor};"><xsl:value-of select="$ingredientSequencesQuery"/></b>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <b><xsl:text>0</xsl:text></b>
                                                </xsl:otherwise>                                  
                                            </xsl:choose>
                                       </span>
                                       <span class="d-block"><xsl:text>Same tools in following recipe: </xsl:text>
                                           <xsl:choose>                                     
                                               <xsl:when test="$toolSequencesQuery != ''">
                                                   <b style="background:{$heatMapColor};"><xsl:value-of select="$toolSequencesQuery"/></b>
                                               </xsl:when>
                                               <xsl:otherwise>
                                                   <b><xsl:text>0</xsl:text></b>
                                               </xsl:otherwise>                                  
                                           </xsl:choose>
                                       </span>
                                   </div>
                               </div>
                               <div class="card">
                                   <div class="card-body">
                                       <h2 class="card-title">Categories:</h2> 
                                       <span class="d-block"><xsl:text>Main ingredient: </xsl:text>
                                           <xsl:choose>
                                               <xsl:when test="document($dishCategoriesQuery)//s:dcingL!=''">
                                                   <xsl:value-of select="document($dishCategoriesQuery)//s:dcingL"/>
                                               </xsl:when>
                                               <xsl:otherwise>-</xsl:otherwise>
                                           </xsl:choose>
                                       </span>
                                       <span class="d-block"><xsl:text>Preparation: </xsl:text><xsl:choose>
                                           <xsl:when test="document($dishCategoriesQuery)//s:dcprepL!=''">
                                               <xsl:value-of select="document($dishCategoriesQuery)//s:dcprepL"/>
                                           </xsl:when>
                                           <xsl:otherwise>-</xsl:otherwise>
                                       </xsl:choose>
                                       </span>
                                       <span class="d-block"><xsl:text>Type: </xsl:text><xsl:choose>
                                           <xsl:when test="document($dishCategoriesQuery)//s:dcintL!=''">
                                               <xsl:value-of select="document($dishCategoriesQuery)//s:dcintL"/>
                                           </xsl:when>
                                           <xsl:otherwise>-</xsl:otherwise>
                                       </xsl:choose>
                                       </span>                                        
                                   </div>
                               </div>
                           </article>
                       </section>
                       <div class="card">
                           <div class="card-body">
                              <xsl:apply-templates select="//t:body" />
                           </div>
                       </div> 
                   </article>
                   
                   <article class="col-md-4" style="margin-top:30px;">
                       <div style="top:67px; z-index:100;" class="sticky-top">
                           <xsl:choose>
                               <xsl:when test="contains($teipid,'o:corema.wo1a') or contains($teipid,'o:corema.wo1b') or contains($teipid,'o:corema.wo1c') or contains($teipid,'o:corema.wo3') or contains($teipid,'o:corema.wo7') or contains($teipid,'o:corema.wo8') or contains($teipid,'o:corema.wo9') or contains($teipid,'o:corema.wo10') or contains($teipid,'o:corema.m11') or contains($teipid,'o:corema.b2') or contains($teipid,'o:corema.b3') or contains($teipid,'o:corema.b4') or contains($teipid,'o:corema.b6') or contains($teipid,'o:corema.br1') or contains($teipid,'o:corema.bs1') or contains($teipid,'o:corema.gr1') or contains($teipid,'o:corema.h2') or contains($teipid,'o:corema.w1') or contains($teipid,'o:corema.w4')">
                           
                               <div class="btn-group" role="group" aria-label="Food and Tools">
                                   <button type="button" class="btn btn-secondary buting">Ingredient</button>
                                   <button type="button" class="btn btn-secondary butdish">Dish</button>
                                   <button type="button" class="btn btn-secondary buttool">Tool</button>
                                   <button type="button" class="btn btn-secondary butname">Name</button>
                               </div>
                               <hr class="my-1"/>
                               <div class="btn-group" role="group" aria-label="Instructions">
                                   <button type="button" class="btn btn-secondary butins">Instruction</button>                                   
                                   <button type="button" class="btn btn-secondary butopener">Opener</button>
                                   <button type="button" class="btn btn-secondary butcloser">Closer</button>
                                   <button type="button" class="btn btn-secondary butref" title="Reference">Ref.</button>
                               </div>
                               <hr class="my-1"/>
                               <div class="btn-group" role="group" aria-label="Tips">
                                    <button type="button" class="btn btn-secondary butkt">Kitchen Tip</button>
                                    <button type="button" class="btn btn-secondary buthht">Household Tip</button>
                                    <button type="button" class="btn btn-secondary butst">Serving Tip</button>
                               </div>
                               <hr class="my-1"/>
                               <div class="btn-group" role="group" aria-label="Alternatives and Others">
                                    <button type="button" class="btn btn-secondary butalt" title="Alternative">Alt.</button>                               
                                    <button type="button" class="btn btn-secondary butdiet">Dietetics</button>
                                    <button type="button" class="btn btn-secondary buttime">Time</button>
                                    <button type="button" class="btn btn-secondary butdate">Date</button>
                                    <button type="button" class="btn btn-secondary butnote">Note</button>
                               </div>
                               <hr class="my-1"/>
                               <div class="btn-group" role="group" aria-label="Alternatives and Others">
                                   <button type="button" class="btn btn-secondary butspeech" title="Speech"><i class="fas fa-comment-dots"><xsl:text> </xsl:text></i></button>
                                   <button type="button" class="btn btn-secondary butexcl" title="Excluded ingredient"><i class="fas fa-times"><xsl:text> </xsl:text></i></button>                               
                                   <button type="button" class="btn btn-secondary butcomp" title="Compared to ..."><i class="fas fa-equals"><xsl:text> </xsl:text></i></button>
                                   <button type="button" class="btn btn-secondary butanal" title="Analogy"><i class="fas fa-compress-arrows-alt"><xsl:text> </xsl:text></i></button>              
                               </div>
                               <hr class="my-1"/>
                     
                           </xsl:when>
                           <xsl:otherwise>
                              
                                   <div class="btn-group" role="group" aria-label="Food and Tools">
                                       <button type="button" class="btn btn-secondary buting">Ingredient</button>
                                       <button type="button" class="btn btn-secondary butdish">Dish</button>
                                       <button type="button" class="btn btn-secondary buttool">Tool</button>
                                   </div>
                                   <hr class="my-1"/>
                                   <div class="btn-group" role="group" aria-label="Instructions">
                                       <button type="button" class="btn btn-secondary butname">Name</button>
                                       <button type="button" class="btn btn-secondary butref" title="Reference">Ref.</button>
                                   </div> 
                                   <hr class="my-1"/>
                                     <div class="btn-group" role="group" aria-label="Alternatives and Others">             
                                         <button type="button" class="btn btn-secondary butexcl" title="Excluded ingredient"><i class="fas fa-times"><xsl:text> </xsl:text></i></button>                               
                                         <button type="button" class="btn btn-secondary butcomp" title="Compared to ..."><i class="fas fa-equals"><xsl:text> </xsl:text></i></button>
                                         <button type="button" class="btn btn-secondary butanal" title="Analogy"><i class="fas fa-compress-arrows-alt"><xsl:text> </xsl:text></i></button>              
                                     </div>
                                     <hr class="my-1"/>
                            
                           </xsl:otherwise>
                       </xsl:choose>
                       <div id="vwr-content" class="toc mt-2"
                           style="background-color: #E8E8E8; height:311px;" >
                           <xsl:text> </xsl:text>    
                       </div>
                       <xsl:call-template name="msinfo"/>
                       </div>
                       <!--Modal for licence-->
                       <div class="modal fade" id="licenceModal">
                           <div class="modal-dialog modal-dialog-centered">
                               <div class="modal-content">
                                   
                                   <!-- Modal Header -->
                                   <div class="modal-header">
                                       <b class="modal-title">Licence for this digital image:</b>
                                       <button type="button" class="close" data-dismiss="modal"><xsl:text disable-output-escaping="yes">&amp;times;</xsl:text></button>
                                   </div>
                                   
                                   <!-- Modal body -->
                                   <div class="modal-body">
                                       <xsl:choose>
                                           <xsl:when test="//t:availability/t:licence[2]/@target"><a href="{//t:availability/t:licence[2]/@target}"><xsl:value-of select="//t:availability/t:licence[2]/normalize-space()"/></a></xsl:when>
                                           <xsl:otherwise><xsl:value-of select="//t:availability/t:licence[2]/normalize-space()"/></xsl:otherwise>
                                       </xsl:choose>
                                   </div>
                                   
                                   <!-- Modal footer -->
                                   <div class="modal-footer">
                                       <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                   </div>
                                   
                               </div>
                           </div>
                       </div>
                       <!-- Modal for How to cite -->  
                       <div class="modal fade" id="citeModal">
                           <div class="modal-dialog modal-dialog-centered">
                               <div class="modal-content">
                                   
                                   <!-- Modal Header -->
                                   <div class="modal-header">
                                       <b class="modal-title">How to cite this page:</b>
                                       <button type="button" class="close" data-dismiss="modal"><xsl:text disable-output-escaping="yes">&amp;times;</xsl:text></button>
                                   </div>
                                   
                                   <!-- Modal body -->
                                   <div class="modal-body">
                                       
                                       <xsl:variable name="handle">
                                           <xsl:value-of select="document(concat('/',$teipid,'/RELS-EXT'))//substring-after(oai:itemID,'hdl:')"/>
                                       </xsl:variable>
                                       <xsl:choose>
                                           <xsl:when test="//t:respStmt/t:resp[text()='edition']/following-sibling::t:persName='Barbara Denicolò'">Denicolò, B.</xsl:when>
                                           <xsl:otherwise><xsl:text>Böhm, A., &amp; Klug, H. W.</xsl:text></xsl:otherwise>
                                       </xsl:choose>
                                       <xsl:text> (2021): Cooking Recipe for "</xsl:text><xsl:value-of select="//t:titleStmt/t:title[@xml:lang='en']"/><xsl:text> (</xsl:text><xsl:value-of select="substring-after($teipid, 'o:corema.')"/><xsl:text>)". In H. W. Klug (Ed.), </xsl:text><i>CoReMA - Cooking Recipes of the Middle Ages. Corpus - Analysis - Visualisation.</i><xsl:text> With the help of A. Böhm, J. Eibinger, and C. Steiner. </xsl:text><a href="http://hdl.handle.net/{$handle/normalize-space()}"><xsl:text>http://hdl.handle.net/</xsl:text><xsl:value-of select="$handle/normalize-space()"/></a><xsl:text> (GAMS. </xsl:text><xsl:value-of select="substring-after($handle/normalize-space(),'11471/')"/><xsl:text>) (Accessed </xsl:text><xsl:value-of select="format-date(current-date(),'[Y0001]-[M01]-[D01]')"/><xsl:text>)</xsl:text>   
                                   </div>
                                   
                                   <!-- Modal footer -->
                                   <div class="modal-footer">
                                       <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                   </div>
                                   
                               </div>
                           </div>
                       </div>
                       
                       <script type="text/javascript" src="/editionviewer/openseadragon.js"><xsl:text> </xsl:text></script>
                       <script type="text/javascript" src="/osdviewer/gamsOsd.js"><xsl:text> </xsl:text></script>
                       <script type="text/javascript">
                           gamsOsd({
                           id: "vwr-content",
                           prefixUrl: "/osdviewer/images/",
                           showNavigator: true,
                           sequenceMode: true,
                           showReferenceStrip: true,
                           showRotationControl: true,
                           showIiifLabels: false,
                           referenceStripScroll: "horizontal",
                           tileSources: ["/iiif/<xsl:value-of select="$ms"/>/IMG.<xsl:value-of select="substring-after(//t:bibl[@type='manuscript_page']/t:ref/@target,'_')"/>/info.json"]
                           });
                       </script>
                       <script type="text/javascript" src="{$gamsdev}/corema/js/recipeButtons.js"><xsl:text> </xsl:text></script>
                   </article>              
               </section>
    </xsl:template>
    
 
    
    <!-- Seitenumbruch kennzeichnen, Seitenzahl auslesen, Folio auslesen -->
    <xsl:template match="t:pb">
        <!--Hier wird div zuerst zugemacht weil von leerem pb zu nächstem leerem pb navigiert werden muss und dort mit div geklamert damit die full width ansicht funktioniert-->
        <xsl:if test="$mode='view:facs-horizontal'"><xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text></xsl:if>
        <a href="/{$ms}#{@xml:id}">
        <span class="page" level="{@xml:id}" id="{@xml:id}">
            <span class="pageNumber">
                <xsl:call-template name="pageNumber">
                    <xsl:with-param name="number" select="@n"/>
                </xsl:call-template>
            </span>
        </span>
        </a>
        <xsl:if test="$mode='view:facs-horizontal'"><xsl:text disable-output-escaping="yes">&lt;div class=&quot;pagediv&quot;&gt;</xsl:text></xsl:if>
        <!--<a class="offset" href="#{@xml:id}" xml:space="preserve"><xsl:text> </xsl:text></a>-->      
    </xsl:template>
    
    
    <xsl:template name="pageNumber">
        <xsl:param name="number"/>
        <xsl:choose>
            <xsl:when test="starts-with($number, '0')">
                <xsl:variable name="saveNumber" select="substring-after($number, '0')"/>
                <xsl:call-template name="pageNumber">
                    <xsl:with-param name="number" select="$saveNumber"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <b>
                    <xsl:text>[</xsl:text>
                    <xsl:value-of select="$number"/>
                    <xsl:text>]</xsl:text>
                </b>
            </xsl:otherwise>
            
        </xsl:choose>
    </xsl:template>
    
    <!--<xsl:template match="text()">
        <xsl:value-of select="replace(.,'&#10;','&lt;br/&gt;')"/>
    </xsl:template>-->
        
    <xsl:template match="t:ab">
            <xsl:apply-templates/>
    </xsl:template>    
    
    <xsl:template match="t:lb[@n]">  
        <!-- Zeilennummern schreiben  -->   
        <xsl:if test="not(@n='N001')"><br/></xsl:if><span class="bold"><xsl:value-of select="substring-after(@n,'N0')"/><xsl:text>: </xsl:text></span>
        <xsl:apply-templates/>
    </xsl:template> 
    <xsl:template match="t:lb[not(@n)]">  
         
       <br/>
        
    </xsl:template> 
   
        
    <xsl:template match="t:foreign">
        <!--<span class="cursor foreign">-->
            <i><xsl:apply-templates/></i><!--<span class="tt"><span class="tttext"><xsl:choose><xsl:when test="@xml:lang"><xsl:value-of select="@xml:lang"/></xsl:when><xsl:otherwise><xsl:text>Latin</xsl:text></xsl:otherwise></xsl:choose></span><xsl:text> </xsl:text><i class="fas fa-language"><xsl:text> </xsl:text></i></span>-->
        <!--</span>-->
    </xsl:template>
                              
    <xsl:template match="t:body//t:note[@xml:lang='en']">
        <span class="cursor note tt">
            <sup><span class="fas fa-hand-point-up" data-fa-transform="rotate-30"><xsl:text> </xsl:text></span></sup>
            <span class="tttext"><xsl:value-of select="."/></span>
        </span>  
    </xsl:template>
    <xsl:template match="t:body//t:note[@xml:lang='de']"/>
    
    <xsl:template match="t:unclear">
        <i class="cursor note tt" style="color:LightGrey;" >
            <span class="tttext"><xsl:text>unclear</xsl:text></span>
            <xsl:apply-templates/>
        </i>  
    </xsl:template>
    
    <xsl:template match="t:ab[@type][@subtype]">
        <xsl:variable name="ti">
            <xsl:choose>
                <xsl:when test="@type='recipe'"><xsl:text>cooking recipe</xsl:text></xsl:when>
                <xsl:when test="@type='medicinal'"><xsl:text>medicinal recipe</xsl:text></xsl:when>
                <xsl:when test="@type='kitchenTip'"><xsl:text>kitchen tip</xsl:text></xsl:when>
                <xsl:when test="@type='household'"><xsl:text>houshold recipe</xsl:text></xsl:when>
                <xsl:when test="@type='dietetics'"><xsl:text>dietetic recipe</xsl:text></xsl:when>
                <xsl:when test="@type='artTechnology'"><xsl:text>art technology</xsl:text></xsl:when>
            </xsl:choose>
        </xsl:variable>
     
        <p class="block subrecipe cursor" title="subrecipe" id="{@xml:id}">
            <b>
                <xsl:attribute name="style">
                    <xsl:choose>
                        <xsl:when test="@type='recipe'"><xsl:text>background-color:lightgreen</xsl:text></xsl:when>
                        <xsl:when test="@type='medicinal'"><xsl:text>background-color:lightblue</xsl:text></xsl:when>
                        <xsl:when test="@type='kitchenTip'"><xsl:text>background-color:lightcoral</xsl:text></xsl:when>
                        <xsl:when test="@type='household'"><xsl:text>background-color:lightgrey</xsl:text></xsl:when>
                        <xsl:when test="@type='dietetics'"><xsl:text>background-color:lightseagreen</xsl:text></xsl:when>
                        <xsl:when test="@type='artTechnology'"><xsl:text>background-color:lightsalmon</xsl:text></xsl:when>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:text>*</xsl:text>
                <xsl:value-of select="descendant::t:title/@key"/><xsl:text>* (Subrecipe Nr. </xsl:text><xsl:value-of select="@n"/><xsl:text>)</xsl:text></b><i><xsl:text> [</xsl:text><xsl:value-of select="$ti"/><xsl:text>] </xsl:text></i><xsl:apply-templates/></p>
    </xsl:template>
    <xsl:template match="t:div[@type][not(@subtype)]">
     <p class="block"><xsl:apply-templates/></p>
    </xsl:template>
    
    <xsl:template match="t:title">
        <b><xsl:apply-templates/></b>
    </xsl:template>
    
    <xsl:template match="t:title[not(descendant::text())]"/>
    
    <xsl:template match="t:ingredient">
        <xsl:text> </xsl:text><span>
            <xsl:choose>
                <xsl:when test="@ana='exclusion'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> excl</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='comparison'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> comp</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='analogy'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> anal</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/>
                    </xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/><span style="display:none" class="en" title="Go to single entity overview"><xsl:text> (</xsl:text><a href="/archive/objects/query:corema.label/methods/sdef:Query/get?params=%241%7C%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F{@commodity}%3E"><xsl:value-of select="@en"/></a><xsl:text>)</xsl:text></span></span>
    </xsl:template>  
    <xsl:template match="t:dish">
        <xsl:text> </xsl:text><span>
            <xsl:choose>
                <xsl:when test="@ana='exclusion'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> excl</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='comparison'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> comp</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='analogy'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> anal</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/>
                    </xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/><span style="display:none" class="enD" title="Go to single entity overview"><xsl:text> (</xsl:text><a href="/archive/objects/query:corema.label/methods/sdef:Query/get?params=%241%7C%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F{@commodity}%3E"><xsl:value-of select="@en"/></a><xsl:text>)</xsl:text></span></span>    </xsl:template>
    <xsl:template match="t:tool">
        <xsl:text> </xsl:text><span>
            <xsl:choose>
                <xsl:when test="@ana='exclusion'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> excl</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='comparison'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> comp</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:when test="@ana='analogy'">
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/><xsl:text> anal</xsl:text>
                    </xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="class">
                        <xsl:value-of select="name()"/>
                    </xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/><span style="display:none" class="enT" title="Go to single entity overview"><xsl:text> (</xsl:text><a href="/archive/objects/query:corema.label/methods/sdef:Query/get?params=%241%7C%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F{@commodity}%3E"><xsl:value-of select="@en"/></a><xsl:text>)</xsl:text></span></span>
    </xsl:template>
    
    <xsl:template match="t:name">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    
    <xsl:template match="t:instruction">
        <xsl:text> </xsl:text> <span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:kitchenTip">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:servingTip">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:householdTip">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:opener">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:closer">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    
    <xsl:template match="t:alternative">
        <xsl:text> </xsl:text><span class="{name()}">
            <xsl:attribute name="title">
                <xsl:text>reason: </xsl:text><xsl:value-of select="@reason"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </span>
    </xsl:template> 
    <xsl:template match="t:dietetics">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:time">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:date">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:ref">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:note">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>
    <xsl:template match="t:sp">
        <xsl:text> </xsl:text><span class="{name()}"><xsl:apply-templates/></span>
    </xsl:template>

    
   
    <!--<xsl:template match="ingredient">
        
        
        <xsl:variable name="rdfabout" select="string(concat('http://www.wikidata.org/entity/',@commodity))"/>
        <xsl:variable name="wiki_ingredient" select="document(concat('https://www.wikidata.org/wiki/Special:EntityData/',@commodity,'.rdf'))//rdf:Description[@rdf:about=$rdfabout]"/>
       
        <xsl:choose>
            <xsl:when test="starts-with(@commodity,'Q')">
                <u title="{$wiki_ingredient/schema:name[@xml:lang='en']}: {$wiki_ingredient/schema:description[@xml:lang='en']}"><xsl:apply-templates/></u>
           <!-\- <u title="{$rdfabout}"><xsl:apply-templates/></u>-\->
 
            </xsl:when>
            
            <xsl:otherwise>
                <u title="unknown"><xsl:apply-templates/></u>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>-->
    
    
    
</xsl:stylesheet>
