diff software/eXist/webapp/mpdl/presentation/pageHtml.xsl @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children d2a1c14fde31
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/presentation/pageHtml.xsl	Tue Feb 08 15:16:46 2011 +0100
@@ -0,0 +1,1223 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="2.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+  xmlns:xlink="http://www.w3.org/1999/xlink"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  xmlns:functx="http://www.functx.com"
+  xmlns:saxon="http://saxon.sf.net/"
+  xmlns:mpdl="http://www.mpiwg-berlin.mpg.de/ns/mpdl"
+  xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text"
+  xmlns:mpdl-util="http://www.mpiwg-berlin.mpg.de/ns/mpdl/util"
+  xmlns:dc="http://purl.org/dc/elements/1.1/" 
+  xmlns:dcterms="http://purl.org/dc/terms"
+  xmlns:echo="http://www.mpiwg-berlin.mpg.de/ns/echo/1.0/" 
+  xmlns:mml="http://www.w3.org/1998/Math/MathML" 
+  xmlns:xhtml="http://www.w3.org/1999/xhtml">
+
+<xsl:import href="/db/mpdl/presentation/functions-mpdl.xsl" />
+<xsl:import href="/db/mpdl/presentation/functions-text.xsl" />
+<xsl:import href="/db/mpdl/presentation/functions-util.xsl" />
+
+<xsl:output method="xhtml" encoding="utf-8"/>
+
+<xsl:variable name="errorMessage" select="string(/result/query/result/error)"/>
+<xsl:variable name="mode" select="/result/page/mode"/>
+<xsl:variable name="queryType" select="/result/query/type"/>
+<xsl:variable name="query" select="text:trim(string(/result/query/expression))"/>
+<xsl:variable name="queryResultPages" select="number(/result/query/result/pages)"/>
+<xsl:variable name="queryResultPN" select="/result/query/result/pn"/>
+<xsl:variable name="language" select="/result/document-description/language"/>
+<xsl:variable name="sn" select="number(/result/page/sentence-number)"/>
+<xsl:variable name="digilibAvailable" select="/result/page/digilib-available"/>
+<xsl:variable name="options" select="/result/page/options"/>
+<xsl:variable name="topPB" select="subsequence(//pb, 1, 1)"/>
+<xsl:variable name="firstSentence" select="subsequence(//s, 1, 1)"/>
+<xsl:variable name="ftQueryTermsTemp" select="string-join(text:translateLuceneToTerms($query), '')" as="xs:string"/>
+<xsl:variable name="ftQueryMorphForms" select="string(/result/query/result/query-forms)"/>
+<!-- Removes the duplicates between ftQueryMorphForms and ftQueryTerms for highlighting them semantically correct: -->
+<!-- Morphological forms are hightlighted as whole words but query terms are highlighted also as partly strings -->
+<xsl:variable name="ftQueryTerms" select="text:removeDuplicates($ftQueryTermsTemp, $ftQueryMorphForms)"/> 
+<xsl:variable name="ftQueryRegularizations" select="string(/result/query/result/query-regularizations)"/>
+<xsl:variable name="ftQueryHighlightWords">
+  <xsl:choose>
+  <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations = ''"><xsl:value-of select="$ftQueryMorphForms"/></xsl:when>
+  <xsl:when test="$ftQueryMorphForms = '' and $ftQueryRegularizations != ''"><xsl:value-of select="$ftQueryRegularizations"/></xsl:when>
+  <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations != ''"><xsl:value-of select="concat($ftQueryMorphForms, '|', $ftQueryRegularizations)"/></xsl:when>
+  <xsl:otherwise><xsl:value-of select="$ftQueryMorphForms"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+<!-- used in module: functions-text: highlight  -->
+<xsl:variable name="ftQueryEncodeBig5" select="/result/query/result/big5-mappings"/>
+<xsl:variable name="ftQueryMode">
+  <xsl:choose>
+  <xsl:when test="matches($query, concat('&quot;', '.*', '&quot;'))">
+    <xsl:value-of select="'phrase'"/>
+  </xsl:when>
+  <xsl:when test="string-length($query) = 0">
+    <xsl:value-of select="'false'"/>
+  </xsl:when>
+  <!-- Because there are  problems in recognizing words (in mode word) this fake mode is used (same as phrase mode)  -->
+  <xsl:otherwise><xsl:value-of select="'fakeWord'"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+
+<xsl:template match="result">
+  <xsl:variable name="author" select="string-join(/result/document-description/authors/author, ', ')"/>
+  <xsl:variable name="title" select="string-join(/result/document-description/titles/title, ', ')"/>
+  <xsl:variable name="place" select="string-join(/result/document-description/places/place, ', ')"/>
+  <xsl:variable name="date" select="/result/document-description/date"/>
+  <xsl:variable name="bookTitle">
+    <xsl:value-of select="$author"/>.
+    <xsl:value-of select="$title"/>.
+    <xsl:value-of select="$place"/><xsl:if test="$place != ''">, </xsl:if>
+    <xsl:value-of select="$date"/>.
+  </xsl:variable>
+  <html>
+  <head>
+    <title><xsl:value-of select="$bookTitle"/></title>
+    <link rel="stylesheet" type="text/css" href="presentation/pageHtml.css"/>
+  </head>
+  <body>
+    <text style="font-weight:bold;font-size:20px"><xsl:value-of select="$bookTitle"/></text>
+    <p/>
+    <xsl:for-each select="page">
+      <xsl:variable name="documentUri" select="/result/document-description/uri"/>
+      <xsl:variable name="documentName" select="/result/document-description/document-name"/>
+      <xsl:variable name="countPages" select="/result/document-description/count-pages"/>
+      <xsl:variable name="pageHeader" select="header"/>
+      <xsl:variable name="pageNumber" select="number(number)"/>
+      <xsl:variable name="pageNumberOrig" select="number-orig"/>
+      <xsl:variable name="documentValue" select="concat('document=', $documentUri)"/>
+      <xsl:variable name="pnValue" select="concat('pn=', $pageNumber)"/>
+      <xsl:variable name="modeValue" select="concat('mode=', $mode)"/>
+      <table cellspacing="1" cellpadding="1">
+        <colgroup>
+          <col width="5%"/>
+          <col width="5%"/>
+          <col width="5%"/>
+          <col width="5%"/>
+          <col width="33%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="3%"/>
+          <col width="10%"/>          
+          <col width="3%"/>
+          <col width="5%"/>
+          <col width="3%"/>
+          <col width="5%"/>
+        </colgroup>
+        <tr>
+        <form action="page-query-result.xql" method="get">
+        <input type="hidden" name="document" value="{$documentUri}"/>
+        <td>
+          <xsl:choose>
+          <xsl:when test="$mode = 'text'"><button id="buttonModeText" name="mode" value="text" style="background:none;border:none;"><img src="images/text.jpg" height="18"/></button></xsl:when>
+          <xsl:otherwise><button id="buttonModeUText" name="mode" value="text" style="background:none;border:none;"><img src="images/textU.jpg" height="18"/></button></xsl:otherwise>
+          </xsl:choose>
+        </td>
+        <td>
+          <xsl:choose>
+          <xsl:when test="$mode = 'textPollux'"><button id="buttonModeTextPollux" name="mode" value="textPollux" style="background:none;border:none;"><img src="images/textPollux.jpg" height="18"/></button></xsl:when>
+          <xsl:otherwise><button id="buttonModeUTextPollux" name="mode" value="textPollux" style="background:none;border:none;"><img src="images/textPolluxU.jpg" height="18"/></button></xsl:otherwise>
+          </xsl:choose>
+        </td>
+        <td>
+          <xsl:choose>
+          <xsl:when test="$mode = 'image'"><button id="buttonModeImage" name="mode" value="image" style="background:none;border:none;"><img src="images/image.jpg" height="18"/></button></xsl:when>
+          <xsl:otherwise><button id="buttonModeUImage" name="mode" value="image" style="background: none;border:none;"><img src="images/imageU.jpg" height="18"/></button></xsl:otherwise>
+          </xsl:choose>
+        </td>
+        <td>
+          <xsl:choose>
+          <xsl:when test="$mode = 'xml'"><button id="buttonModeXml" name="mode" value="xml" style="background:none;border:none;"><img src="images/xml.jpg" height="18"/></button></xsl:when>
+          <xsl:otherwise><button id="buttonModeUXml" name="mode" value="xml" style="background:none;border:none;"><img src="images/xmlU.jpg" height="18"/></button></xsl:otherwise>
+          </xsl:choose>
+        </td>
+        <input type="hidden" name="pn" value="{$pageNumber}"/>
+        <xsl:if test="/result/page/sentence-number[node()]">
+          <input type="hidden" name="sn" value="{$sn}"/>
+        </xsl:if>
+        <input type="hidden" name="query-type" value="{$queryType}"/>
+        <xsl:if test="/result/query/result[node()]">
+          <input type="hidden" name="query" value="{$query}"/>
+          <input type="hidden" name="query-result-pn" value="{$queryResultPN}"/>
+        </xsl:if>
+        </form>
+        <td/>
+        <!-- toc, fulltext, fulltextMorph, structural, ftIndex and ftIndexMorph buttons      -->
+        <form action="page-query-result.xql" method="get">
+        <input type="hidden" name="document" value="{$documentUri}"/>
+        <input type="hidden" name="mode" value="{$mode}"/>
+        <input type="hidden" name="pn" value="{$pageNumber}"/>
+        <xsl:if test="/result/page/sentence-number[node()]">
+          <input type="hidden" name="sn" value="-1"/>
+        </xsl:if>
+        <td><button id="bToc" name="query-type" value="toc" style="background: none; border: none;"><img src="images/toc.gif" width="24" height="24"/></button></td>
+        <td><button id="bFulltext" name="query-type" value="fulltext" style="background: none; border: none;"><img src="images/search.gif" width="24" height="24"/></button></td>
+        <td><button id="bFulltextMorph" name="query-type" value="fulltextMorph" style="background: none; border: none;"><img src="images/searchMorph.gif" width="24" height="24"/></button></td>
+        <td><button id="bStructural" name="query-type" value="xpath" style="background: none; border: none;"><img src="images/searchStructural.gif" width="24" height="24"/></button></td>
+        <td><button id="bFtIndex" name="query-type" value="ftIndex" style="background: none; border: none;"><img src="images/dictionary.gif" width="24" height="24"/></button></td>
+        <td><button id="bftIndexMorph" name="query-type" value="ftIndexMorph" style="background: none; border: none;"><img src="images/dictionaryMorph.gif" width="24" height="24"/></button></td>
+        <td><button id="bFigures" name="query-type" value="figures" style="background: none; border: none;"><img src="images/figures.png" width="24" height="24"/></button></td>
+        <xsl:choose>
+          <xsl:when test="/result/query/result[node()] and not($queryType = 'toc')">
+            <input type="hidden" name="query" value=""/>
+            <input type="hidden" name="query-result-pn" value="{$queryResultPN}"/>
+          </xsl:when>
+          <xsl:when test="/result/query/result[node()] and $queryType = 'toc'">
+            <input type="hidden" name="query-result-pn" value="1"/>
+          </xsl:when>
+          <xsl:otherwise>
+          </xsl:otherwise>
+        </xsl:choose>
+        </form>
+        <td/>
+        <xsl:variable name="leftNumber">
+          <xsl:choose>
+          <xsl:when test="$pageNumber &gt; 1"><xsl:value-of select="$pageNumber - 1"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="$pageNumber"/></xsl:otherwise>
+          </xsl:choose>
+        </xsl:variable>
+        <xsl:variable name="rightNumber">
+          <xsl:choose>
+          <xsl:when test="$pageNumber &lt; $countPages"><xsl:value-of select="$pageNumber + 1"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="$pageNumber"/></xsl:otherwise>
+          </xsl:choose>
+        </xsl:variable>
+        <form action="page-query-result.xql" method="get">
+        <input type="hidden" name="document" value="{$documentUri}"/>
+        <input type="hidden" name="mode" value="{$mode}"/>
+        <td><button id="buttonLeftNumber" name="pn" value="{$leftNumber}" style="background:none;border:none;"><img src="images/left.gif"/></button></td>
+        <td nowrap="true"><xsl:value-of select="$pageNumber"/> / <xsl:value-of select="$countPages"/></td>
+        <td><button id="buttonRightNumber" name="pn" value="{$rightNumber}" style="background:none;border:none;"><img src="images/right.gif"/></button></td>
+        <input type="hidden" name="query-type" value="{$queryType}"/>
+        <xsl:if test="/result/query/result[node()]">
+          <input type="hidden" name="query" value="{$query}"/>
+          <input type="hidden" name="query-result-pn" value="{$queryResultPN}"/>
+        </xsl:if>
+        </form>
+        <form action="page-query-result.xql" method="get">
+        <input type="hidden" name="document" value="{$documentUri}"/>
+        <input type="hidden" name="mode" value="{$mode}"/>
+        <td nowrap="true">Page: <input type="text" size="2" name="pn" value="{$pageNumber}"/></td> 
+        <input type="hidden" name="query-type" value="{$queryType}"/>
+        <xsl:if test="/result/query/result[node()]">
+          <input type="hidden" name="query" value="{$query}"/>
+          <input type="hidden" name="query-result-pn" value="{$queryResultPN}"/>
+        </xsl:if>
+        </form>
+        </tr>
+      </table>
+      <hr/>
+      <table align="middle" width="100%" rules="cols" frame="void" cellpadding="7">
+        <colgroup>
+          <col width="65%"/>
+          <col width="35%"/>
+        </colgroup>
+        <tr>
+          <xsl:for-each select="content">
+            <xsl:choose>
+            <xsl:when test="$mode = 'text' or $mode = 'textPollux' or $mode = 'gis'">
+              <td align="left" valign="top">
+                <xsl:if test="$pageHeader != '' or $pageNumberOrig != ''">
+                  <table width="100%" cellspacing="1" cellpadding="1">
+                    <colgroup>
+                      <col width="10%"/>
+                      <col width="70%"/>
+                      <col width="20%"/>
+                    </colgroup>
+                    <tr>
+                      <td align="left"><b><xsl:value-of select="$pageNumberOrig"/></b></td>
+                      <td align="center"><b><xsl:value-of select="$pageHeader"/></b></td>
+                    </tr>
+                  </table>
+                </xsl:if>
+                <table>
+                <colgroup>
+                  <col width="90%"/>
+                  <col width="10%"/>
+                </colgroup>
+                <tr>
+                <td>
+                  <xsl:variable name="contentStr" select="normalize-space(string(.))"/>
+                  <xsl:variable name="figures" select=".//figure|.//handwritten"/>
+                  <xsl:if test="$contentStr = '' and empty($figures)">
+                    <div class="emptyPage"><xsl:value-of select="'[Empty page]'"/></div>
+                  </xsl:if>
+                  <xsl:apply-templates mode="text"/>
+                </td>
+                <td align="middle" valign="top"><p><a href="?{$documentValue}&amp;mode={$mode}&amp;pn={$pageNumber}&amp;sn={$sn}&amp;export=pdf&amp;options={$options}"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download PDF</p></td>
+                </tr>
+                </table>
+              </td>
+            </xsl:when>
+            <xsl:when test="$mode = 'xml'">
+              <td align="left" valign="top">
+                <table>
+                <colgroup>
+                  <col width="90%"/>
+                  <col width="10%"/>
+                </colgroup>
+                <tr>
+                <td><xsl:apply-templates mode="xml"/></td>
+                <td align="middle" valign="top"><p><a target="_blank" href="?{$documentValue}&amp;mode=pureXml&amp;pn={$pageNumber}"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download XML</p></td>
+                <td align="middle" valign="top"><p><a href="?{$documentValue}&amp;mode={$mode}&amp;pn={$pageNumber}&amp;sn={$sn}&amp;export=pdf"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download PDF</p></td>
+                </tr>
+                </table>
+              </td>
+            </xsl:when>
+            <xsl:when test="$mode = 'image'">
+              <xsl:variable name="imageAvailable" select="/result/page/image-available"/>
+              <xsl:variable name="imageFileName" select="/result/page/image-file-name"/>
+              <xsl:variable name="linkImageEcho" select="/result/page/image-echo"/>
+              <xsl:variable name="linkImageScaler" select="/result/page/image-scaler"/>
+              <xsl:variable name="imageHeight" select="600"/>
+              <td align="middle" valign="top">
+                <xsl:choose>
+                  <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'true'">
+                    <table>
+                      <colgroup>
+                        <col width="90%"/>
+                        <col width="10%"/>
+                      </colgroup>
+                      <tr>
+                      <td>
+                        <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border: 1px;">
+                          <a href="{$linkImageEcho}"><img alt="Page image: {$linkImageScaler}" src="{$linkImageScaler}&amp;dh={$imageHeight}"/></a>
+                        </div>
+                      </td>
+                      <td align="middle" valign="top"><p><a href="?{$documentValue}&amp;mode={$mode}&amp;pn={$pageNumber}&amp;sn={$sn}&amp;export=pdf"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download PDF</p></td>
+                      </tr>
+                    </table>
+                  </xsl:when>
+                  <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'false'">
+                    <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
+                      <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
+                      Page image: <br/>
+                      <br/>
+                      <xsl:value-of select="$imageFileName"/> , page <xsl:value-of select="$pageNumber"/>
+                      <br/><br/>
+                      not scanned
+                    </div>
+                  </xsl:when>
+                  <xsl:when test="$digilibAvailable = 'false'">
+                    <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
+                      <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
+                      Could not fetch: <br/>
+                      <br/>
+                      <xsl:value-of select="$imageFileName"/> , page <xsl:value-of select="$pageNumber"/>
+                      <br/><br/>
+                      from nausikaa2.rz-berlin.mpg.de: please try again later
+                    </div>
+                  </xsl:when>
+                  <xsl:otherwise></xsl:otherwise>
+                </xsl:choose>
+              </td>
+            </xsl:when>
+            <xsl:otherwise></xsl:otherwise>
+            </xsl:choose>
+          </xsl:for-each>
+          <td align="left" valign="top" style="padding-right: 25px;">
+            <xsl:if test="$queryType = 'toc'">
+              <b>Table of contents</b>
+            </xsl:if>
+            <xsl:if test="$queryType = 'figures'">
+              <b>Figures</b>
+            </xsl:if>
+            <xsl:if test="$queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma'">
+            <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <input type="hidden" name="query-type" value="{$queryType}"/>
+              <xsl:if test="$queryType = 'fulltext'">
+                <xsl:value-of select="'Contains: '"/>
+              </xsl:if>
+              <xsl:if test="$queryType = 'fulltextMorph'">
+                <xsl:value-of select="'Contains morphological: '"/>
+              </xsl:if>
+              <xsl:if test="$queryType = 'fulltextMorphLemma'">
+                <xsl:value-of select="'Contains lemma: '"/>
+              </xsl:if>
+              <input type="text" size="15" name="query" value="{$query}"/>
+              <input type="hidden" name="query-result-pn" value="1"/>
+              <input type="submit" value="Query"/>
+            </form>
+            </xsl:if>
+            <xsl:if test="$queryType = 'xpath' or $queryType = 'xquery'">
+            <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <table cellspacing="1" cellpadding="1">
+              <colgroup>
+                <col width="70%"/>
+                <col width="15%"/>
+                <col width="15%"/>
+              </colgroup>
+              <tr>
+                <td>
+                  <xsl:if test="$queryType = 'xpath'"><b><xsl:value-of select="'XPath query '"/></b></xsl:if>
+                  <xsl:if test="$queryType = 'xquery'"><b><xsl:value-of select="'XQuery '"/></b></xsl:if>
+                  <a href="info.xql?info={$queryType}" onclick="window.open(&quot;info.xql?info={$queryType}&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="images/info.png" width="15" height="15" border="0" alt="Info"/></a>
+                </td>
+                <td><button id="bXPath" name="query-type" value="xpath" style="background:none"><text style="font-weight:bold;font-size:12px">XPath</text></button></td>
+                <td><button id="bXQuery" name="query-type" value="xquery" style="background:none"><text style="font-weight:bold;font-size:12px">XQuery</text></button></td>
+              </tr>
+              </table>
+              <input type="hidden" name="query" value=""/>
+            </form>
+            <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <xsl:if test="$queryType = 'xpath'">
+                <input type="hidden" name="query-type" value="xpath"/>
+                <table>
+                <tr><td><input type="text" size="50" name="query" value="{$query}"/></td></tr>
+                <tr><td><input type="submit" value="Query"/></td></tr>
+                </table>
+              </xsl:if>
+              <xsl:if test="$queryType = 'xquery'">
+                <input type="hidden" name="query-type" value="xquery"/>
+                <table>
+                  <tr>
+                    <td>
+                    <textarea name="query" cols="45" rows="10">
+                      <xsl:choose>
+                      <xsl:when test="$query = ''"><xsl:value-of select="' '" /></xsl:when>
+                      <xsl:otherwise><xsl:value-of select="$query"/></xsl:otherwise>
+                      </xsl:choose>
+                    </textarea>
+                    </td>
+                  </tr>
+                  <tr><td><input type="submit" value="Query"/></td></tr>
+                </table>
+              </xsl:if>
+            </form>
+            </xsl:if>
+            <xsl:if test="$queryType = 'ftIndex' or $queryType = 'ftIndexMorph'">
+            <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <input type="hidden" name="query-type" value="{$queryType}"/>
+              <xsl:if test="$queryType = 'ftIndex'"><xsl:value-of select="'Fulltext index: '"/></xsl:if>
+              <xsl:if test="$queryType = 'ftIndexMorph'"><xsl:value-of select="'Morphological index: '"/></xsl:if>
+              <input type="text" size="10" name="query" value="{$query}"/> 
+              <input type="hidden" name="query-result-pn" value="1"/>
+              <input type="submit" value="Query"/>
+            </form>
+            </xsl:if>
+            <xsl:if test="(($query != '' or $queryType = 'toc' or $queryType = 'figures') and $queryResultPages &gt; 0)">
+              <hr/>
+              <table>
+              <colgroup>
+                <col width="81%"/>
+                <col width="3%"/>
+                <col width="5%"/>
+                <col width="3%"/>
+                <col width="5%"/>
+              </colgroup>
+              <tr>
+              <td>
+                <xsl:variable name="resultSize" select="/result/query/result/size"/>
+                <xsl:if test="$queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma'">
+                  <b><xsl:value-of select="$resultSize"/> sentence hits</b>
+                </xsl:if>
+                <xsl:if test="$queryType = 'ftIndex' or $queryType = 'ftIndexMorph'">
+                  <b><xsl:value-of select="$resultSize"/> entries beginning with: "<xsl:value-of select="$query"/>"<br/></b>
+                </xsl:if>
+                <xsl:if test="$queryType = 'xpath' or $queryType = 'xquery'">
+                  <b><xsl:value-of select="$resultSize"/> element hits</b>
+                </xsl:if>
+              </td>
+              <xsl:variable name="leftNumber">
+                <xsl:choose>
+                <xsl:when test="$queryResultPN &gt; 1"><xsl:value-of select="$queryResultPN - 1"/></xsl:when>
+                <xsl:otherwise><xsl:value-of select="$queryResultPN"/></xsl:otherwise>
+                </xsl:choose>
+              </xsl:variable>
+              <xsl:variable name="rightNumber">
+                <xsl:choose>
+                <xsl:when test="$queryResultPN &lt; $queryResultPages"><xsl:value-of select="$queryResultPN + 1"/></xsl:when>
+                <xsl:otherwise><xsl:value-of select="$queryResultPN"/></xsl:otherwise>
+                </xsl:choose>
+              </xsl:variable>
+              <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <input type="hidden" name="query-type" value="{$queryType}"/>
+              <input type="hidden" name="query" value="{$query}"/>
+              <td><button id="buttonLeftNumber" name="query-result-pn" value="{$leftNumber}" style="background:none;border:none;"><img src="images/left.gif"/></button></td>
+              <td nowrap="true"><xsl:value-of select="$queryResultPN"/> / <xsl:value-of select="$queryResultPages"/></td>
+              <td><button id="buttonRightNumber" name="query-result-pn" value="{$rightNumber}" style="background:none;border:none;"><img src="images/right.gif"/></button></td>
+              </form>
+              <form action="page-query-result.xql" method="get">
+              <input type="hidden" name="document" value="{$documentUri}"/>
+              <input type="hidden" name="pn" value="{$pageNumber}"/>
+              <input type="hidden" name="mode" value="{$mode}"/>
+              <input type="hidden" name="query-type" value="{$queryType}"/>
+              <input type="hidden" name="query" value="{$query}"/>
+              <td nowrap="true">Page: <input type="text" size="2" name="query-result-pn" value="{$queryResultPN}"/></td>
+              </form>
+              </tr>
+              </table>
+              <xsl:if test="$ftQueryMorphForms != ''">
+                <table>
+                  <colgroup>
+                    <col width="40%"/>
+                    <col width="60%"/>
+                  </colgroup>
+                  <td/>
+                  <xsl:if test="$queryType = 'fulltextMorph'">
+                    <td align="right" nowrap="true">Morphological expansion: <a href="lt/lemma.xql?language={$language}&amp;query={$query}">see here</a></td>
+                  </xsl:if>
+                  <xsl:if test="$queryType = 'fulltextMorphLemma'">
+                    <td align="right" nowrap="true">Morphological expansion: <a href="lt/lemma.xql?language={$language}&amp;lemma={$query}">see here</a></td>
+                  </xsl:if>
+                </table>
+              </xsl:if>
+              <hr/>
+              <xsl:if test="$queryType = 'toc' or $queryType = 'figures'">
+                <table class="toc" cellspacing="1" cellpadding="1">
+                  <colgroup>
+                    <col width="70%"/>
+                    <col width="20%"/>
+                  </colgroup>
+                <xsl:for-each select="/result/query/result/hits/toc-entry">
+                  <xsl:variable name="page" select="page"/>
+                  <xsl:variable name="level">
+                    <xsl:choose>
+                      <xsl:when test="real-level = '1'"><xsl:value-of select="'one'"/></xsl:when>
+                      <xsl:when test="real-level = '2'"><xsl:value-of select="'two'"/></xsl:when>
+                      <xsl:when test="real-level = '3'"><xsl:value-of select="'three'"/></xsl:when>
+                      <xsl:when test="real-level = '4'"><xsl:value-of select="'four'"/></xsl:when>
+                      <xsl:when test="real-level = '5'"><xsl:value-of select="'five'"/></xsl:when>
+                      <xsl:when test="real-level = '6'"><xsl:value-of select="'six'"/></xsl:when>
+                      <xsl:when test="real-level = '7'"><xsl:value-of select="'seven'"/></xsl:when>
+                      <xsl:otherwise><xsl:value-of select="'one'"/></xsl:otherwise>
+                    </xsl:choose>
+                  </xsl:variable>
+                  <tr>
+                  <td align="left" valign="top">
+                    <div class="toc {$level}">
+                      <xsl:value-of select="'['"/>
+                      <xsl:value-of select="concat(level-string, ' ')"/>
+                      <xsl:value-of select="content"/>
+                      <xsl:value-of select="']'"/>
+                    </div>
+                  </td>
+                  <td align="center" valign="top">
+                    <div class="toc float right">
+                      <a href="?{$documentValue}&amp;pn={$page}&amp;{$modeValue}&amp;query-type={$queryType}&amp;query-result-pn={$queryResultPN}">
+                        <xsl:value-of select="concat('Page: ', $page)"/>
+                      </a>
+                    </div>
+                  </td>
+                  </tr>
+                </xsl:for-each>
+                </table>
+              </xsl:if>
+              <xsl:if test="$queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma'">
+              <table cellspacing="1" cellpadding="1">
+              <xsl:for-each select="/result/query/result/hits/hit">
+                <tr valign="top">
+                <xsl:variable name="pos" select="pos"/>
+                <xsl:variable name="term" select="term"/>
+                <td><xsl:value-of select="$pos"/>.</td>
+                <td align="left">
+                  <xsl:variable name="hitPN" select="pn"/>
+                  <xsl:variable name="hitPosOfS" select="pos-of-s"/>
+                  <xsl:variable name="sSurroundsPB" select="s-surrounds-pb"/>
+                  <xsl:variable name="queryValue" select="concat('&amp;', 'query=', $query)"/>
+                  <xsl:variable name="queryValueEscaped1" select="replace($queryValue, '\+', '%2B')"/>
+                  <xsl:variable name="queryValueEscaped2" select="replace($queryValueEscaped1, ' ', '+')"/>
+                  <xsl:choose>
+                  <!-- if a found sentence surrounds a page break then a special presentation of the hit is done -->
+                  <xsl:when test="$sSurroundsPB = 'false'">
+                    <a href="?{$documentValue}&amp;pn={$hitPN}&amp;sn={$hitPosOfS}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <a href="?{$documentValue}&amp;pn={$hitPN}&amp;sn={$hitPosOfS}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a> / <a href="?{$documentValue}&amp;pn={$hitPN + 1}&amp;sn=0&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}#sn0">Page <xsl:value-of select="$hitPN + 1"/>, continuation of the sentence</a>
+                  </xsl:otherwise>
+                  </xsl:choose>
+                  :<br/>
+                  <!-- Highlight the query terms in each hit sentence and clip the result -->
+                  <xsl:sequence select="text:highlight(s, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/>
+                </td>
+                </tr>
+              </xsl:for-each>
+              </table>
+              </xsl:if>
+              <xsl:if test="$queryType = 'ftIndex' or $queryType = 'ftIndexMorph'">
+              <table cellspacing="1" cellpadding="1">
+              <xsl:for-each select="/result/query/result/hits/entry">
+                <tr valign="top">
+                <xsl:variable name="pos" select="position"/>
+                <xsl:variable name="term" select="term"/>
+                <xsl:variable name="polluxKeys" select="pollux-keys"/>
+                <xsl:variable name="lemmasWithOR" select="lemmas-with-or"/>
+                <xsl:variable name="dictionaryLink">
+                  <xsl:choose>
+                  <xsl:when test="$language = 'zh'">
+                    <xsl:variable name="termBig5Encoded" select="/result/query/result/big5-hits/entry-big5-encoded/term[$pos]"/>
+                    <a href="http://humanum.arts.cuhk.edu.hk/cgi-bin/agrep-lindict?query={$termBig5Encoded}&amp;category=wholerecord">Lin Yutang</a>
+                    <!-- TODO: replace Java based function by XSL-function like the following, but that does not work yet cause termHexBin is not the same than by Java) also in query.xsl and functions-text.xsl -->
+                    <xsl:variable name="termHexBin"><xsl:value-of select="saxon:string-to-hexBinary($term, 'utf8')"/></xsl:variable>
+                    <xsl:variable name="termHexBinStr" select="string($termHexBin)"/>
+                    <xsl:variable name="termBig5EncodedNew">
+                      <xsl:for-each select="string-to-codepoints($termHexBinStr)">
+                        <xsl:variable name="pos" select="position()"/>
+                        <xsl:variable name="posIDiv" select="$pos idiv 2"/>
+                        <xsl:variable name="posPlus1IDiv" select="($pos + 1) idiv 2"/>
+                        <xsl:if test="$posIDiv != $posPlus1IDiv">
+                          <xsl:variable name="charStr" select="substring($termHexBinStr, $pos, 2)"/>
+                          <xsl:value-of select="encode-for-uri(concat('%', $charStr))"/>
+                        </xsl:if>
+                      </xsl:for-each>
+                    </xsl:variable>
+                  </xsl:when>
+                  <xsl:otherwise><a href="http://archimedes.mpiwg-berlin.mpg.de/cgi-bin/toc/dict?step=table;word={$term};lang={$language};pro=echo">Echo</a></xsl:otherwise>
+                  </xsl:choose>
+                </xsl:variable>
+                <xsl:variable name="polluxLink">
+                  <xsl:choose>
+                  <xsl:when test="$polluxKeys = ''">Pollux</xsl:when>
+                  <xsl:otherwise><a href="lt/lex.xql?language={$language}&amp;query={$polluxKeys}">Pollux</a></xsl:otherwise>
+                  </xsl:choose>
+                </xsl:variable>
+                <xsl:variable name="wikipediaLink">
+                  <xsl:choose>
+                  <xsl:when test="$lemmasWithOR = ''">Wiki</xsl:when>
+                  <xsl:otherwise><a href="http://{$language}.wikipedia.org/wiki/index.php?search={$lemmasWithOR}">Wiki</a></xsl:otherwise>
+                  </xsl:choose>
+                </xsl:variable>
+                <xsl:variable name="ftSearchQueryType">
+                  <xsl:choose>
+                  <xsl:when test="$queryType = 'ftIndex'"><xsl:value-of select="'fulltext'"/></xsl:when>
+                  <xsl:when test="$queryType = 'ftIndexMorph'"><xsl:value-of select="'fulltextMorphLemma'"/></xsl:when>
+                  <xsl:otherwise></xsl:otherwise>
+                  </xsl:choose>
+                </xsl:variable>
+                <td><xsl:value-of select="$pos"/>.</td>
+                <td align="left">
+                  <a href="lt/lemma.xql?language={$language}&amp;lemma={$term}"><xsl:value-of select="$term"/></a>(<a href="?{$documentValue}&amp;{$modeValue}&amp;query-type={$ftSearchQueryType}&amp;query={$term}"><xsl:value-of select="frequency"/></a>) [<xsl:sequence select="$polluxLink"/>][<xsl:sequence select="$wikipediaLink"/>][<xsl:sequence select="$dictionaryLink"/>]
+                </td>
+                </tr>
+              </xsl:for-each>
+              </table>
+              </xsl:if>
+              <xsl:if test="$queryType = 'xpath' or $queryType = 'xquery'">
+                <xsl:for-each select="/result/query/result/hits">
+                  <table>
+                  <colgroup>
+                    <col width="90%"/>
+                    <col width="10%"/>
+                  </colgroup>
+                  <tr>
+                  <td><xsl:apply-templates mode="xml"/></td>
+                  <xsl:variable name="queryWithoutCRLF" select="replace($query, '\r\n', ' ')"/>
+                  <td align="middle" valign="top"><p><a target="_blank" href="?{$documentValue}&amp;mode=pureXml&amp;query-type={$queryType}&amp;query={$queryWithoutCRLF}&amp;query-result-pn={$queryResultPN}"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download</p></td>
+                  </tr>
+                  </table>
+                </xsl:for-each>
+              </xsl:if>
+            </xsl:if>
+            <xsl:choose>
+              <xsl:when test="$errorMessage != ''">
+                <hr/>
+                <b>Your query delivers an error: </b>
+                <xsl:value-of select="$errorMessage"/>
+              </xsl:when>
+              <xsl:when test="$errorMessage = '' and $query != '' and $queryResultPages = 0">
+                <hr/>
+                <b>No results</b>
+              </xsl:when>
+            </xsl:choose>
+          </td>
+        </tr>
+      </table>
+      <hr/>
+      Elapsed time: <xsl:value-of select="/result/performance"/> ms, Back to <a href="query.xql">query page</a>, see the <a href="page-query-result.xql?_source=yes">XQuery source</a> and <a href="/exist/rest/db/mpdl/presentation/pageHtml.xsl?_source=yes">XSL source</a> of this page
+      <br/>
+    </xsl:for-each>
+  </body></html>
+</xsl:template>
+
+<xsl:template match="attribute()|element()|text()|comment()|processing-instruction()" mode="xml">
+  <xsl:copy>
+    <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="element()|comment()|processing-instruction()" mode="xml">
+  <xsl:variable name="elementName" select="name()"/>
+  <xsl:variable name="elementPresentation">
+    <xsl:choose>
+    <xsl:when test="element() = node() or text() != '' or self::comment() or self::processing-instruction()">
+      <xsl:value-of select="'&lt;'"/>
+      <span class="xml elementName"><xsl:value-of select="$elementName"/></span>
+      <xsl:apply-templates select="attribute()" mode="xml"/>
+      <xsl:value-of select="'&gt;'"/>
+      <xsl:apply-templates select="element()|text()|comment()|processing-instruction()" mode="xml"/>
+      <xsl:value-of select="'&lt;/'"/>
+      <span class="xml elementName"><xsl:value-of select="$elementName"/></span>
+      <xsl:value-of select="'&gt;'"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="'&lt;'"/>
+      <span class="xml elementName"><xsl:value-of select="$elementName"/></span>
+      <xsl:apply-templates select="attribute()" mode="xml"/>
+      <xsl:value-of select="'/&gt;'"/>
+    </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="actualSN">
+    <xsl:choose>
+      <xsl:when test=". = $firstSentence and ($topPB >> .)">0</xsl:when>
+      <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:choose>
+    <!-- Show the sentence in color light grey if it is given as sn -->
+    <xsl:when test="$elementName = 's' and $sn >= 0 and $sn = $actualSN">
+      <ul class="xml element highlight">
+        <a name="sn{$actualSN}"></a><xsl:sequence select="$elementPresentation"/>
+      </ul>
+    </xsl:when>
+    <xsl:when test="$elementName = 's' and $sn != $actualSN">
+      <ul class="xml element">
+        <a name="sn{$actualSN}"></a><xsl:sequence select="$elementPresentation"/>
+      </ul>
+    </xsl:when>
+    <xsl:otherwise>
+      <ul class="xml element">
+        <xsl:sequence select="$elementPresentation"/>
+      </ul>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="attribute()" mode="xml">
+  <xsl:variable name="attributeName" select="name()"/>
+  <span class="xml attributeName">
+    <xsl:value-of select="' '"/>
+    <xsl:value-of select="$attributeName"/>
+  </span>
+  <xsl:value-of select="'=&quot;'"/>
+  <span class="xml attributeValue"><xsl:value-of select="."/></span><xsl:value-of select="'&quot;'"/>
+  <xsl:apply-templates select="attribute()" mode="xml"/>
+</xsl:template>
+
+<!-- If ft-query is set then highlight all term occurrences in each little text piece for the fulltext query -->
+<xsl:template match="text()" mode="xml">
+  <xsl:variable name="parentS" select="./ancestor::s"/>
+  <xsl:variable name="actualSN">
+    <xsl:choose>
+      <xsl:when test="$parentS = $firstSentence and ($topPB >> $parentS)">0</xsl:when>
+      <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:choose>
+    <xsl:when test="$ftQueryMode != 'false' and $sn >= 0 and $sn = $actualSN">
+      <xsl:sequence select="text:highlight(string(.), $ftQueryTerms, $ftQueryHighlightWords, 'false')"/>
+    </xsl:when>
+    <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+
+<!-- variables used by templates in mode "text" -->
+<xsl:variable name="collectionName" select="/result/document-description/collection-name"/>
+<xsl:variable name="documentUri" select="/result/document-description/uri"/>
+<xsl:variable name="documentName" select="/result/document-description/document-name"/>
+<xsl:variable name="documentIdentifier" select="/result/document-description/identifier"/>
+<xsl:variable name="pageNumber" select="/result/page/number"/>
+<xsl:variable name="firstFigurePosition" select="/result/page/firstFigurePosition"/>
+<xsl:variable name="figuresImageDirectory" select="/result/page/figures-image-directory"/>
+<xsl:variable name="figures" select="/result/page/figures"/>
+<xsl:variable name="handwritten" select="/result/page/handwritten"/>
+<xsl:variable name="tables" select="/result/page/tables"/>
+<xsl:variable name="notes" select="/result/page/notes"/>
+<xsl:variable name="charNorm" select="/result/page/character-normalization"/>
+
+<xsl:template match="text" mode="text">
+  <xsl:apply-templates mode="text"/>
+  <!--   Notes                      -->
+  <xsl:if test="$collectionName = 'archimedes' and count($notes/*) > 0">
+    <div>
+      <hr class="notesBottom"/>
+      <xsl:for-each select="$notes/note">
+        <xsl:variable name="notePos" select="position()"/>
+        <xsl:variable name="label" select="$notePos"/>
+        <xsl:variable name="uid" select="@uid"/>
+        <xsl:variable name="modificationDate" select="@modificationDate"/>
+        <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace(.)"/>
+        <p>
+          <a>
+            <xsl:attribute name="name"><xsl:value-of select="concat('note-', $pageNumber, '-', $label)"/></xsl:attribute>
+            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', 'note-', $pageNumber, '-', $label, 'ref')"/></xsl:attribute>
+            <xsl:value-of select="concat('[↑ note-', $pageNumber, '-', $label, ']')"/>
+          </a>
+          <xsl:value-of select="': '"/>
+          <xsl:choose>
+            <xsl:when test="$uid = '' or empty($uid)">
+              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+            </xsl:when>
+            <xsl:otherwise>
+              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+              <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
+            </xsl:otherwise>
+          </xsl:choose>
+        </p>
+      </xsl:for-each>
+    </div>
+  </xsl:if>
+  <xsl:if test="$collectionName = 'echo' and count($notes/*) > 0">
+    <div>
+      <hr class="notesBottom"/>
+      <xsl:for-each select="$notes/echo:note">
+        <xsl:variable name="label" select="string(@xlink:label)"/>
+        <xsl:variable name="uid" select="@uid"/>
+        <xsl:variable name="modificationDate" select="@modificationDate"/>
+        <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace(.)"/>
+        <p>
+          <a>
+            <xsl:attribute name="name"><xsl:value-of select="$label"/></xsl:attribute>
+            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $label, 'ref')"/></xsl:attribute>
+            <xsl:value-of select="concat('[↑ ', $label, ']')"/>
+          </a>
+          <xsl:value-of select="': '"/>
+          <xsl:choose>
+            <xsl:when test="$uid = '' or empty($uid)">
+              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+            </xsl:when>
+            <xsl:otherwise>
+              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+              <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
+            </xsl:otherwise>
+          </xsl:choose>
+        </p>
+      </xsl:for-each>
+    </div>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="head" mode="text">
+  <p class="bf center"><xsl:apply-templates mode="text"/></p>
+</xsl:template>
+
+<xsl:template match="div" mode="text">
+  <xsl:variable name="type" select="@type"/>
+  <xsl:variable name="level" select="@level"/>
+  <xsl:variable name="style" select="@style"/>
+  <xsl:variable name="border" select="@border"/>
+  <xsl:variable name="width" select="@width"/>
+  <xsl:variable name="note" select="note"/>
+  <xsl:variable name="figure" select="figure"/>
+  <xsl:variable name="floatClassValue">
+    <xsl:choose>
+      <xsl:when test="not(empty($note))"><xsl:value-of select="''"/></xsl:when>
+      <xsl:when test="not(empty($figure))"><xsl:value-of select="''"/></xsl:when>
+      <xsl:when test="$type = 'float'"><xsl:value-of select="'float left'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'float left'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="levelClassValue">
+    <xsl:choose>
+      <xsl:when test="not(empty($note))"><xsl:value-of select="''"/></xsl:when>
+      <xsl:when test="$level = '1'"><xsl:value-of select="'level one'"/></xsl:when>
+      <xsl:when test="$level = '2'"><xsl:value-of select="'level two'"/></xsl:when>
+      <xsl:when test="$level = '3'"><xsl:value-of select="'level three'"/></xsl:when>
+      <xsl:when test="$level = '4'"><xsl:value-of select="'level four'"/></xsl:when>
+      <xsl:when test="$level = '5'"><xsl:value-of select="'level five'"/></xsl:when>
+      <xsl:when test="$level = '6'"><xsl:value-of select="'level six'"/></xsl:when>
+      <xsl:when test="$level = '7'"><xsl:value-of select="'level seven'"/></xsl:when>
+      <xsl:when test="$level = '8'"><xsl:value-of select="'level eight'"/></xsl:when>
+      <xsl:when test="$level = '9'"><xsl:value-of select="'level nine'"/></xsl:when>
+      <xsl:when test="empty($level)"><xsl:value-of select="''"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'level n'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <div>
+    <xsl:if test="not(empty($style))"><xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute></xsl:if>
+    <xsl:attribute name="class"><xsl:value-of select="concat($floatClassValue, ' ', $levelClassValue)"/></xsl:attribute>
+    <xsl:apply-templates mode="text"/>
+  </div>
+</xsl:template>
+
+<xsl:template match="p" mode="text">
+  <xsl:variable name="style" select="@style"/>
+  <p>
+    <xsl:if test="not(empty($style))">
+      <xsl:attribute name="class"><xsl:value-of select="$style"/></xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates mode="text"/>
+  </p>
+</xsl:template>
+
+<xsl:template match="lb" mode="text">
+  <xsl:variable name="withoutLBs">
+    <xsl:choose>
+      <xsl:when test="contains($options, 'withoutLBs')"><xsl:value-of select="'true'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'false'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>  
+  <xsl:if test="$withoutLBs = 'false'"><br/></xsl:if>
+  <xsl:apply-templates mode="text"/>
+</xsl:template>
+
+<xsl:template match="cb" mode="text">
+  <br/><xsl:apply-templates mode="text"/>
+</xsl:template>
+
+<xsl:template match="expan" mode="text">
+  <xsl:apply-templates mode="text"/><xsl:text> </xsl:text>
+</xsl:template>
+
+<xsl:template match="note" mode="text">
+  <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
+  <xsl:variable name="notePos" select="count(preceding::note[. >> $topPB]) + 1"/>
+  <xsl:variable name="href" select="concat('note-', $pageNumber, '-', $notePos)"/>
+  <xsl:choose>
+    <xsl:when test="$collectionName = 'archimedes'">
+      <a>
+        <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
+        <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="'super'"/></xsl:attribute>
+        <xsl:value-of select="concat(' ↓ (', $href, ') ')"/>
+      </a>
+    </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and not($hasLabel)">
+      <p>
+        <xsl:value-of select="'[Note]: '"/>
+        <span class="note"><xsl:apply-templates mode="text"/></span>
+      </p>
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="emph" mode="text">
+  <xsl:variable name="class" select="@class"/>
+  <xsl:variable name="style" select="@style"/>
+  <xsl:variable name="text" select="string-join(., '')"/>
+  <xsl:variable name="length" select="string-length($text)"/>
+  <xsl:variable name="firstChar" select="substring($text, 1, 1)"/>
+  <xsl:variable name="first2Chars" select="substring($text, 1, 2)"/>
+  <xsl:variable name="restChars" select="substring($text, 2, $length)"/>
+  <xsl:variable name="first2CharsAreUppercase" select="upper-case($first2Chars) = $first2Chars"/>
+  <xsl:variable name="rest">
+    <xsl:choose>
+      <xsl:when test="$length &lt; 2 or empty($length)"><xsl:value-of select="''"/></xsl:when>
+      <xsl:otherwise>
+        <xsl:choose>
+          <xsl:when test="not(empty(w))">
+            <a class="textPollux" href="interface/lt/wordInfo.xql?language={w/@lang}&amp;word={w/@form}&amp;output=html"><xsl:value-of select="$restChars"/></a>
+          </xsl:when>
+          <xsl:otherwise><xsl:value-of select="$restChars"/></xsl:otherwise>
+        </xsl:choose>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:if test="$collectionName = 'echo' and not(contains($class, 'sc'))"><span class="{$class} {$style}"><xsl:apply-templates mode="text"/></span></xsl:if>
+  <xsl:if test="$collectionName = 'echo' and contains($class, 'sc') and $first2CharsAreUppercase"><span class="dc {$style}"><xsl:value-of select="$firstChar"/></span><span class="{$class} {$style}"><xsl:sequence select="$rest"/></span></xsl:if>
+  <xsl:if test="$collectionName = 'echo' and contains($class, 'sc') and not($first2CharsAreUppercase)"><span class="{$class} {$style}"><xsl:apply-templates mode="text"/></span></xsl:if>
+  <xsl:if test="$collectionName = 'archimedes'"><xsl:apply-templates mode="text"/></xsl:if>
+</xsl:template>
+
+<xsl:template match="ref" mode="text">
+  <span class="ref"><xsl:apply-templates mode="text"/></span>
+</xsl:template>
+
+<xsl:template match="foreign" mode="text">
+  <xsl:variable name="lang" select="@lang"/>
+  <xsl:variable name="xmllang" select="@xml:lang"/>
+  <xsl:variable name="language">
+    <xsl:choose>
+      <xsl:when test="not(empty($xmllang))"><xsl:value-of select="$xmllang"/></xsl:when>
+      <xsl:when test="not(empty($lang))"><xsl:value-of select="$lang"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>  
+  <span>
+    <xsl:attribute name="class"><xsl:value-of select="concat('foreign ', $language)"/></xsl:attribute>
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="q" mode="text">
+  <div class="q"><xsl:apply-templates mode="text"/></div>
+</xsl:template>
+
+<xsl:template match="quote" mode="text">
+  <div class="quote"><xsl:apply-templates mode="text"/></div>
+</xsl:template>
+
+<xsl:template match="blockquote" mode="text">
+  <div class="blockquote"><xsl:apply-templates mode="text"/></div>
+</xsl:template>
+
+<xsl:template match="set-off" mode="text">
+  <div class="set-off"><xsl:apply-templates mode="text"/></div>
+</xsl:template>
+
+<xsl:template match="reg" mode="text">
+  <span class="reg">   
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="var" mode="text">
+  <xsl:variable name="type" select="@type"/>
+  <span class="var">
+    <xsl:attribute name="class"><xsl:value-of select="concat('var ', $type)"/></xsl:attribute>
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="num" mode="text">
+  <span class="num"><xsl:apply-templates mode="text"/></span>
+</xsl:template>
+
+<xsl:template match="gap" mode="text">
+  <xsl:variable name="extent" select="@extent"/>
+  <xsl:variable name="count">
+    <xsl:choose>
+      <xsl:when test="empty($extent)"><xsl:value-of select="number(3)"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="number($extent)"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="gapChars" select="text:nchars($count, '.')"/>
+  <xsl:value-of select="concat('[', $gapChars, ']')"/><xsl:apply-templates mode="text"/>
+</xsl:template>
+
+<xsl:template match="anchor" mode="text">
+  <xsl:variable name="type" select="@type"/>
+  <xsl:variable name="href" select="@xlink:href"/>
+  <xsl:choose>
+    <xsl:when test="$type = 'figure'">
+      <xsl:variable name="figure" select="$figures/echo:figure[@xlink:label = $href]"/>
+      <xsl:variable name="figureFileName">
+        <xsl:choose>
+          <xsl:when test="$collectionName = 'archimedes'"><xsl:value-of select="replace($figure/@xlink:href, '/', '.')"/></xsl:when>
+          <xsl:when test="$collectionName = 'echo'"><xsl:value-of select="$figure/echo:image/@file"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="$figure/echo:image/@file"/></xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:variable name="figureNumber">
+        <xsl:choose>
+          <xsl:when test="$collectionName = 'archimedes'"><xsl:value-of select="$firstFigurePosition + count($figure/preceding::figure)"/></xsl:when>
+          <xsl:when test="$collectionName = 'echo'"><xsl:value-of select="$firstFigurePosition + count(./preceding::figure[empty(@xlink:label)]) + count(./preceding::anchor[@type = 'figure'])"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="$firstFigurePosition + count(./preceding::echo:figure[empty(@xlink:label)]) + count(./preceding::echo:anchor[@type = 'figure'])"/></xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:variable name="figureCaption" select="string-join($figure/echo:caption/text(), ' ')"/>
+      <xsl:variable name="figureDescription" select="string-join($figure/echo:description/text(), ' ')"/>
+      <xsl:variable name="figureVariables" select="string-join($figure/echo:variables/text(), ' ')"/>
+      <xsl:sequence select="mpdl:showFigure($digilibAvailable, $figureFileName, $figureNumber, $figureCaption, $figureDescription, $figureVariables, 'float right')"/>
+    </xsl:when>
+    <xsl:when test="$type = 'handwritten'">
+      <xsl:variable name="hw" select="$handwritten/echo:handwritten[@xlink:label = $href]"/>
+      <xsl:variable name="hwFileName" select="$hw/@file"/>
+      <xsl:variable name="hwHref" select="$hw/@xlink:href"/>
+      <xsl:sequence select="mpdl:showHandwritten($hwFileName, $hwHref)"/>
+    </xsl:when>
+    <xsl:when test="$type = 'table'">
+      <xsl:variable name="table" select="$tables/xhtml:table[@xlink:label = $href]"/>
+      <xsl:sequence select="mpdl-util:copyWithoutNamespace($table)"/>
+    </xsl:when>
+    <xsl:when test="$type = 'note'">
+      <a>
+        <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
+        <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="'super'"/></xsl:attribute>
+        <xsl:value-of select="concat('↓ (', $href, ')')"/>
+      </a>
+    </xsl:when>
+    <xsl:otherwise><a><xsl:attribute name="href"><xsl:value-of select="$href"/></xsl:attribute>Anchor of type: <xsl:value-of select="$type"/>, href: <xsl:value-of select="$href"/></a></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- GIS Elements   -->
+<xsl:template match="place" mode="text">
+  <xsl:variable name="actualSN">
+    <xsl:choose>
+      <xsl:when test=". = $firstSentence and ($topPB >> .)">0</xsl:when>
+      <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="id" select="@id"/>
+  <xsl:variable name="echoDocDir" select="replace($figuresImageDirectory, '(.*)/.*$', '$1')"/>
+  <xsl:variable name="echoDocDirTokenized" select="tokenize($echoDocDir, '/')"/>
+  <xsl:variable name="echoDocDirNameSize" select="count($echoDocDirTokenized)"/>
+  <xsl:variable name="echoDoc" select="string(subsequence($echoDocDirTokenized, $echoDocDirNameSize))"/>
+  <xsl:variable name="docStrOld" select="concat('http://echo.mpiwg-berlin.mpg.de/ECHOdocuView?url=', $echoDocDir, '&amp;pn=', $pageNumber, '&amp;sn=', $actualSN, '&amp;viewMode=gis')"/>
+  <xsl:variable name="docStr" select="concat('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/page-query-result.xql?document=', $documentUri, '&amp;mode=gis', '&amp;pn=', $pageNumber, '&amp;sn=', $actualSN)"/>
+  <xsl:variable name="docBase64Coded" select="saxon:string-to-base64Binary($docStr, 'utf8')"/>
+  <xsl:variable name="href" select="concat('http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/', $echoDoc, '?id=', $id, '&amp;doc=', $docBase64Coded, '&amp;format=gis')"/>
+  <xsl:choose>
+    <xsl:when test="$mode = 'textPollux'">
+      <xsl:variable name="wordLanguage" select="string-join(w[1]/@lang, '')"/>
+      <xsl:variable name="form" select="string-join(w/@form, '')"/>
+      <xsl:variable name="wordStr" select="string-join(w, '')"/>
+      <xsl:variable name="lexHref">
+        <xsl:if test="not(empty(w))">
+          <xsl:value-of select="concat('interface/lt/wordInfo.xql?language=', $wordLanguage, '&amp;word=', $form, '&amp;output=html', '&amp;placeHref=', encode-for-uri($href))"/>
+        </xsl:if>
+        <xsl:if test="empty(w)">
+          <xsl:value-of select="concat('interface/lt/wordInfo.xql?type=place', '&amp;output=html', '&amp;placeHref=', encode-for-uri($href))"/>
+        </xsl:if>
+      </xsl:variable>
+      <span class="place">
+        <a class="textPollux"><xsl:attribute name="href"><xsl:value-of select="$lexHref"/></xsl:attribute><xsl:value-of select="$wordStr"/></a>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="place">
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="time" mode="text">
+  <span class="time">
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="person" mode="text">
+  <span class="person">
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="event" mode="text">
+  <span class="event">
+    <xsl:apply-templates mode="text"/>
+  </span>
+</xsl:template>
+
+<!-- MML   -->
+<xsl:template match="mml:*" mode="text">
+  <xsl:copy-of select="."/>
+</xsl:template>
+    
+<!-- XHTML: remove the xhtml namespace   -->
+<xsl:template match="xhtml:*" mode="text">
+  <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
+  <xsl:variable name="isTable" select="name() = 'table'"/>
+  <xsl:choose>
+    <xsl:when test="(not($hasLabel)) or ($isTable and $hasLabel)">
+      <xsl:element name="{name()}" namespace="">
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates mode="text"/>
+      </xsl:element>
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="figure" mode="text">
+  <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
+  <xsl:choose>
+    <xsl:when test="not($hasLabel)">
+      <xsl:variable name="figureFileName">
+        <xsl:choose>
+          <xsl:when test="$collectionName = 'archimedes'"><xsl:value-of select="replace(./@xlink:href, '/', '.')"/></xsl:when>
+          <xsl:when test="$collectionName = 'echo'"><xsl:value-of select="./image/@file"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="./image/@file"/></xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:variable name="figureNumber">
+        <xsl:choose>
+          <xsl:when test="$collectionName = 'archimedes'"><xsl:value-of select="$firstFigurePosition + count(./preceding::figure)"/></xsl:when>
+          <xsl:when test="$collectionName = 'echo'"><xsl:value-of select="$firstFigurePosition + count(./preceding::figure[empty(@xlink:label)]) + count(./preceding::anchor[@type = 'figure'])"/></xsl:when>
+          <xsl:otherwise><xsl:value-of select="$firstFigurePosition + count(./preceding::figure[empty(@xlink:label)]) + count(./preceding::anchor[@type = 'figure'])"/></xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:variable name="figureCaption" select="./caption/text()"/>
+      <xsl:variable name="figureDescription" select="./description/text()"/>
+      <xsl:variable name="figureVariables" select="./variables/text()"/>
+      <xsl:sequence select="mpdl:showFigure($digilibAvailable, $figureFileName, $figureNumber, $figureCaption, $figureDescription, $figureVariables, 'float none')"/>
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="handwritten" mode="text">
+  <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
+  <xsl:choose>
+    <xsl:when test="not($hasLabel)">
+      <xsl:variable name="fileName" select="@file"/>
+      <xsl:variable name="href" select="@xlink:href"/>
+      <xsl:sequence select="mpdl:showHandwritten($fileName, $href)"/>
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+
+
+<!-- textPollux links                           -->
+<xsl:template match="w" mode="text">
+  <xsl:variable name="wordLanguage" select="@lang"/>
+  <xsl:variable name="form" select="@form"/>
+  <a class="textPollux">
+    <xsl:attribute name="href"><xsl:value-of select="concat('interface/lt/wordInfo.xql?language=', $wordLanguage, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
+    <xsl:apply-templates mode="text"/>
+  </a>
+</xsl:template>
+
+<xsl:template match="s" mode="text">
+  <xsl:variable name="actualSN">
+    <xsl:choose>
+      <xsl:when test=". = $firstSentence and ($topPB >> .)">0</xsl:when>
+      <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <a name="sn{$actualSN}"></a>
+  <xsl:choose>
+    <!-- Show the sentence in color light grey if it is given as sn -->
+    <xsl:when test="$sn >= 0 and $sn = $actualSN">
+      <span class="s highlight">
+        <xsl:if test="contains($options, 'withXmlNodeId')"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="s">
+        <xsl:if test="contains($options, 'withXmlNodeId')"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- If ft-query is set then highlight all term occurrences in each little text piece for the fulltext query -->
+<xsl:template match="text()" mode="text">
+  <xsl:variable name="parentS" select="./ancestor::s"/>
+  <xsl:variable name="actualSN">
+    <xsl:choose>
+      <xsl:when test="$parentS = $firstSentence and ($topPB >> $parentS)">0</xsl:when>
+      <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:choose>
+  <xsl:when test="$ftQueryMode != 'false' and $sn >= 0 and $sn = $actualSN">
+    <xsl:sequence select="text:highlight(string(.), $ftQueryTerms, $ftQueryHighlightWords, 'false')"/>
+  </xsl:when>
+  <xsl:otherwise>
+    <xsl:value-of select="."/>
+  </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>