changeset 15:e99964f390e4

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Mon, 29 Aug 2011 17:40:19 +0200
parents 5df60f24e997
children 257f67be5c00
files software/eXist/webapp/mpdl/_stuff/.DS_Store software/eXist/webapp/mpdl/_stuff/futureDev/getFragment.xsl software/eXist/webapp/mpdl/_stuff/futureDev/getFragmentSaxonFast.xsl software/eXist/webapp/mpdl/_stuff/testDev/.DS_Store software/eXist/webapp/mpdl/_stuff/tmp/mpdl-extension-modules.jar software/eXist/webapp/mpdl/_stuff/tmp/saxon9-dom.jar software/eXist/webapp/mpdl/_stuff/tmp/saxon9-xpath.jar software/eXist/webapp/mpdl/_stuff/tmp/saxon9.jar software/eXist/webapp/mpdl/attribute-query-result.xql software/eXist/webapp/mpdl/doc/.DS_Store software/eXist/webapp/mpdl/doc/doc-op.xql software/eXist/webapp/mpdl/doc/doc-operation-exist.xql software/eXist/webapp/mpdl/doc/get-jobs.xql software/eXist/webapp/mpdl/escidoc/.DS_Store software/eXist/webapp/mpdl/images/.DS_Store software/eXist/webapp/mpdl/interface/.DS_Store software/eXist/webapp/mpdl/interface/echo/echoDocuView.xql software/eXist/webapp/mpdl/interface/external/.DS_Store software/eXist/webapp/mpdl/interface/lt/wordInfo.xql software/eXist/webapp/mpdl/interface/page-fragment.xql software/eXist/webapp/mpdl/lt/.DS_Store software/eXist/webapp/mpdl/lucene/.DS_Store software/eXist/webapp/mpdl/lucene/search.xql software/eXist/webapp/mpdl/page-query-result.xql software/eXist/webapp/mpdl/presentation/.DS_Store software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl software/eXist/webapp/mpdl/presentation/pageFragmentHtml.xsl software/eXist/webapp/mpdl/presentation/pageHtml.css software/eXist/webapp/mpdl/presentation/pageHtml.xsl software/eXist/webapp/mpdl/presentation/queryHtml.xsl software/eXist/webapp/mpdl/query.xql software/eXist/webapp/mpdl/text/.DS_Store
diffstat 32 files changed, 940 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
Binary file software/eXist/webapp/mpdl/_stuff/.DS_Store has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/_stuff/futureDev/getFragment.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:local="local">
+
+<xsl:function name="local:contains">
+  <xsl:param name="sequence" as="node()*"/> 
+  <xsl:param name="node" as="node()?"/> 
+  <xsl:sequence select="some $nodeInSequence in $sequence satisfies $nodeInSequence is $node"/>
+</xsl:function>
+
+<xsl:output method="xml" encoding="utf-8"/>
+
+<xsl:param name="msName"></xsl:param>
+<xsl:param name="ms1Position"></xsl:param>
+<xsl:param name="ms2Position"></xsl:param>
+
+<xsl:variable name="ms1" select="saxon:evaluate(concat('subsequence(//*:', $msName, ', ', $ms1Position, ', 1)'))" xmlns:saxon="http://saxon.sf.net/"/>
+<xsl:variable name="ms2" select="saxon:evaluate(concat('subsequence(//*:', $msName, ', ', $ms2Position, ', 1)'))" xmlns:saxon="http://saxon.sf.net/"/>
+<xsl:variable name="ms1Ancestors" select="$ms1/ancestor::*"/>
+<xsl:variable name="ms2Ancestors" select="$ms2/ancestor::*"/>
+
+<xsl:template match="element()[name() != $msName]">
+  <xsl:choose>
+    <xsl:when test="(. >> $ms1 or local:contains($ms1Ancestors, .)) and ($ms2 >> . or local:contains($ms2Ancestors, .))">
+      <!-- without namespace   -->
+      <xsl:element name="{local-name(.)}"><xsl:apply-templates/></xsl:element>
+    </xsl:when>
+    <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="attribute()|text()|comment()|processing-instruction()">
+  <xsl:choose>
+    <xsl:when test=". >> $ms1 and $ms2 >> .">
+      <xsl:copy><xsl:apply-templates/></xsl:copy>
+    </xsl:when>
+    <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="element()[name() = $msName]">
+  <xsl:choose>
+    <xsl:when test=". is $ms1">
+      <!-- without namespace   -->
+      <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
+    </xsl:when>
+    <xsl:when test=". is $ms2">
+      <!-- without namespace   -->
+      <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/_stuff/futureDev/getFragmentSaxonFast.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<!-- Delivers the fragment between two milestones. Takes no care about namespaces. -->
+
+<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="local-function">
+
+<xsl:function name="fn:contains">
+  <xsl:param name="sequence" as="node()*"/> 
+  <xsl:param name="node" as="node()?"/> 
+  <xsl:sequence select="some $nodeInSequence in $sequence satisfies $nodeInSequence is $node"/>
+</xsl:function>
+
+<xsl:output method="xml" encoding="utf-8"/>
+
+<!-- ms1Name and ms2Name have to be given without namespace: e.g. "pb" -->
+<xsl:param name="xmlFileName"></xsl:param>
+<xsl:param name="ms1Name"></xsl:param>
+<xsl:param name="ms1Position"></xsl:param>
+<xsl:param name="ms2Name"></xsl:param>
+<xsl:param name="ms2Position"></xsl:param>
+
+<!-- the doc method is ca. 25% faster than over the source document  -->
+<xsl:variable name="xmlDocExpr" select="saxon:expression('doc($p1)')" xmlns:saxon="http://saxon.sf.net/"/>
+<xsl:variable name ="xmlDoc" select="saxon:eval($xmlDocExpr, $xmlFileName)" xmlns:saxon="http://saxon.sf.net/"/> 
+
+<xsl:variable name="ms1AllExpr" select="saxon:expression('$p1//*[name() = $p2]')" xmlns:saxon="http://saxon.sf.net/"/>
+<xsl:variable name ="ms1All" select="saxon:eval($ms1AllExpr, $xmlDoc, $ms1Name)" xmlns:saxon="http://saxon.sf.net/"/> 
+<xsl:variable name="ms1" select="subsequence($ms1All, $ms1Position, 1)"/>
+<xsl:variable name="ms2AllExpr" select="saxon:expression('$p1//*[name() = $p2]')" xmlns:saxon="http://saxon.sf.net/"/>
+<xsl:variable name ="ms2All" select="saxon:eval($ms2AllExpr, $xmlDoc, $ms2Name)" xmlns:saxon="http://saxon.sf.net/"/> 
+<xsl:variable name="ms2" select="subsequence($ms2All, $ms2Position, 1)"/>
+
+<xsl:variable name="ms1Ancestors" select="$ms1/ancestor::*"/>
+<xsl:variable name="ms2Ancestors" select="$ms2/ancestor::*"/>
+
+<xsl:template match="/">
+  <xsl:apply-templates select="$xmlDoc" mode="doc"/>
+</xsl:template>
+
+<xsl:template match="element()[local-name() != $ms1Name and local-name() != $ms2Name]" mode="doc">
+  <xsl:choose>
+    <xsl:when test="(. >> $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 >> . or fn:contains($ms2Ancestors, .))">
+      <xsl:element name="{local-name(.)}"><xsl:apply-templates mode="doc"/></xsl:element>
+    </xsl:when>
+    <xsl:otherwise><xsl:apply-templates mode="doc"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="attribute()|text()|comment()|processing-instruction()" mode="doc">
+  <xsl:choose>
+    <xsl:when test=". >> $ms1 and $ms2 >> .">
+      <xsl:copy><xsl:apply-templates mode="doc"/></xsl:copy>
+    </xsl:when>
+    <xsl:otherwise><xsl:apply-templates mode="doc"/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="element()[local-name() = $ms1Name or local-name() = $ms2Name]"  mode="doc">
+  <xsl:choose>
+    <xsl:when test=". is $ms1">
+      <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
+    </xsl:when>
+    <xsl:when test=". is $ms2">
+      <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
+      <!-- <xsl:message terminate="yes">Terminate</xsl:message>  -->
+    </xsl:when>
+    <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
Binary file software/eXist/webapp/mpdl/_stuff/testDev/.DS_Store has changed
Binary file software/eXist/webapp/mpdl/_stuff/tmp/mpdl-extension-modules.jar has changed
Binary file software/eXist/webapp/mpdl/_stuff/tmp/saxon9-dom.jar has changed
Binary file software/eXist/webapp/mpdl/_stuff/tmp/saxon9-xpath.jar has changed
Binary file software/eXist/webapp/mpdl/_stuff/tmp/saxon9.jar has changed
--- a/software/eXist/webapp/mpdl/attribute-query-result.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/attribute-query-result.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -171,8 +171,12 @@
 let $pageResult := 
   for $elem at $pos in $orderedAttrQueryResult
     let $doc := $elem/fn:root()
    let $documentUriOrig := document-uri($doc)
+    let $documentName := util:document-name($doc)
+    let $documentCollection := replace(string($documentUriOrig), "(.+)/.+xml", "$1")
     let $documentUri := substring-after($documentUriOrig, $docPath)
     let $documentUriWithoutExtension := substring-before($documentUri, ".")
+    (: let $lastModified := replace(substring-before(string(xmldb:last-modified($documentCollection, $documentName)), "."), "T", " ")  :)
+    let $lastModified := substring-before(string(xmldb:last-modified($documentCollection, $documentName)), ".")
     let $docBase := substring-before(substring-after($documentUri, "/"), "/")
     let $metadata := mpdl-lucene:getMetadata($docBase, $doc)
     (: Performance: following is slow: why  (would be better structured code) ?
@@ -183,10 +187,12 @@
     let $titleElems := mpdl-lucene:getElementsByAttr($metadata, $docBase, "title")
     let $placeElems := mpdl-lucene:getElementsByAttr($metadata, $docBase, "place")
     let $dateElems := mpdl-lucene:getElementsByAttr($metadata, $docBase, "date")
+    let $langElems := mpdl-lucene:getElementsByAttr($metadata, $docBase, "language")
     let $authors := string-join($authorElems, ', ')
     let $titles := string-join($titleElems, ', ')
     let $places := string-join($placeElems, ', ')
     let $dates := string-join($dateElems, ', ')
+    let $langs := string-join($langElems, ', ')
     let $resultElem := 
       <tr>
         <td valign="top" style="padding-left:5px;">{$pos}.</td>
@@ -199,6 +205,9 @@
         <td valign="top" style="padding-left:5px;">{$titles}</td>
         <td valign="top" style="padding-left:5px;">{$places}</td>
         <td valign="top" style="padding-left:5px;">{$dates}</td>
+        <td valign="top" style="padding-left:5px;">{$langs}</td>
+        <td valign="top" style="padding-left:5px;">{$docBase}</td>
+        <td valign="top" style="padding-left:5px;">{$lastModified}</td>
       </tr>
   where $pos >= $positionFrom and $pos <= $positionTo
   return $resultElem
@@ -301,9 +310,12 @@
       <col width="3%"/>
       <col width="3%"/>
       <col width="15%"/>
-      <col width="42%"/>
-      <col width="15%"/>
+      <col width="35%"/>
+      <col width="5%"/>
       <col width="6%"/>
+      <col width="3%"/>
+      <col width="3%"/>
+      <col width="3%"/>
     </colgroup>
     <thead>
     <tr>
@@ -312,9 +324,9 @@
       </th>
       <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Full view</button></th>
       <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Lite view</button></th>
-      <th align="left" valign="top"><button id="dummy" name="order-by" value="author" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Xml</button></th>
-      <th align="left" valign="top"><button id="dummy" name="order-by" value="author" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Pdf</button></th>
-      <th align="left" valign="top"><button id="dummy" name="order-by" value="author" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Html</button></th>
+      <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Xml</button></th>
+      <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Pdf</button></th>
+      <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Html</button></th>
       <th align="left" valign="top">
         <button name="order-by" value="author" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Author</button>
       </th>
@@ -327,6 +339,11 @@
       <th align="left" valign="top">
         <button name="order-by" value="date" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Year</button>
       </th>
+      <th align="left" valign="top">
+        <button name="order-by" value="language" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Language</button>
+      </th>
+      <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Schema</button></th>
+      <th align="left" valign="top"><button id="dummy" name="order-by" value="{$orderBy}" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Last modified</button></th>
     </tr>
     </thead>
     <tbody>
Binary file software/eXist/webapp/mpdl/doc/.DS_Store has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/doc/doc-op.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -0,0 +1,15 @@
+xquery version "1.0";
+
+import module namespace request="http://exist-db.org/xquery/request";
+
+let $operation := request:get-parameter("operation", "")
+let $srcUrl := request:get-parameter("srcUrl", "")
+(: let $uploadFileName := request:get-parameter("uploadFileName", "");  :)
+let $docBase := request:get-parameter("docBase", "")
+let $language := request:get-parameter("language", "")
+let $fileName := request:get-parameter("fileName", "")
+let $eSciDocCookieId := request:get-parameter("eSciDocCookieId", "")
+
+let $jobId := mpdldoc:do(string($operation), string($srcUrl), 'empty', string($docBase), string($language), string($fileName), string($eSciDocCookieId))
+
+return $jobId
\ No newline at end of file
--- a/software/eXist/webapp/mpdl/doc/doc-operation-exist.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/doc/doc-operation-exist.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -36,7 +36,7 @@
     <!--
     function DocumentSelection() {
       var existIdentifier = document.docBaseList.doc[document.docBaseList.doc.selectedIndex].value;
-      var existLink = "http://" + window.location.host + "/mpdl/page-query-result.xql?document=" + existIdentifier;
+      var existLink = "http://mpdl-test.mpiwg-berlin.mpg.de:30030/mpdl/page-query-result.xql?document=".concat(existIdentifier);
       var existIdentifierSplit = existIdentifier.split("/");
       var docBase = existIdentifierSplit[1];
       var language = existIdentifierSplit[2];
@@ -256,4 +256,4 @@
   <br/>
   See the <a href="doc-operation-exist.xql?_source=yes">XQuery source</a> of this page, if you find a bug <a href="https://itgroup.mpiwg-berlin.mpg.de:8080/tracs/mpdl-project-software/newticket">let us know</a>
 </body>
-</html>
\ No newline at end of file
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/eXist/webapp/mpdl/doc/get-jobs.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -0,0 +1,259 @@
+xquery version "1.0";
+
+declare namespace request="http://exist-db.org/xquery/request";
+declare namespace util = "http://exist-db.org/xquery/util";
+
+declare namespace escidocItem="http://www.escidoc.de/schemas/item/0.9";
+declare namespace container="http://www.escidoc.de/schemas/container/0.8";
+declare namespace escidocMetadataRecords="http://www.escidoc.de/schemas/metadatarecords/0.5";
+declare namespace dc="http://purl.org/dc/elements/1.1/";
+declare namespace xlink="http://www.w3.org/1999/xlink";
+declare namespace mpiwg="http://www.mpiwg-berlin.mpg.de/ns/mpiwg";
+
+let $docBaseReq := request:get-parameter("docBase", "")
+let $docBase :=
+  if ($docBaseReq = '')
+  then 'echo'
+  else $docBaseReq
+let $languageReq := request:get-parameter("language", "")
+let $language :=
+  if ($languageReq = '')
+  then 'la'
+  else string($languageReq)
+
+let $docPathStandard := "/db/mpdl/documents/standard"
+let $docPath := concat($docPathStandard, "/", $docBase, "/", $language)
+let $docCollectionStr := concat("collection('", $docPath, "')")
+let $docCollection := util:eval($docCollectionStr)
+let $docFileNames := 
+  for $elem at $pos in $docCollection
+    let $doc := $elem/fn:root()
    let $documentUriOrig := document-uri($doc)
+    let $documentFileName := substring-after(substring-after($documentUriOrig, $docPath), "/")
+  return $documentFileName
+
+let $javascriptHtml :=
+  <script type="text/javascript">
+    <!--
+    function DocumentSelection() {
+      var existIdentifier = document.docBaseList.doc[document.docBaseList.doc.selectedIndex].value;
+      var existLink = "http://" + window.location.host + "/mpdl/page-query-result.xql?document=" + existIdentifier;
+      var existIdentifierSplit = existIdentifier.split("/");
+      var docBase = existIdentifierSplit[1];
+      var language = existIdentifierSplit[2];
+      var fileName = existIdentifierSplit[3];
+      document.formDocOperation.docBase.value = docBase;
+      document.formDocOperation.language.value = language;
+      document.formDocOperation.fileName.value = fileName;
+      document.getElementById("existLink").href = existLink;
+      document.getElementById("existLink").firstChild.nodeValue = existIdentifier;
+      document.formDocOperation.srcLocalFileName.value = "";
+      document.formDocOperation.srcUrl.value = "";
+    }
+    function OperationSelection() {
+      if (document.formDocOperation.operation.selectedIndex == 1) {
+        document.formDocOperation.srcLocalFileName.value = "";
+        document.formDocOperation.srcUrl.value = "";
+      }
+    }
+    function LocalFileNameSelection() {
+      var srcLocalFileName = document.formDocOperation.srcLocalFileName.value;
+      document.formDocOperation.fileName.value = srcLocalFileName;
+      document.formDocOperation.srcUrl.value = "";
+      document.getElementById("existLink").href = "";
+      document.getElementById("existLink").firstChild.nodeValue = "";
+    }
+    function UrlSelection() {
+      var srcUrl = document.formDocOperation.srcUrl.value;
+      var startPos = srcUrl.lastIndexOf("/");
+      var endPos = srcUrl.length;
+      var fileName = srcUrl.substring(startPos + 1, endPos);
+      document.formDocOperation.fileName.value = fileName;
+      document.formDocOperation.srcLocalFileName.value = "";
+      document.getElementById("existLink").href = "";
+      document.getElementById("existLink").firstChild.nodeValue = "";
+    }
+    function ResetSrcLocalFileName() {
+      document.formDocOperation.srcLocalFileName.value = "";
+      document.formDocOperation.srcUrl.value = "";
+      document.formDocOperation.fileName.value = "";
+    }
+    function DocBaseRefreshDest() {
+      var docBase = document.formDocOperation.docBase[document.formDocOperation.docBase.selectedIndex].value;
+      DocBaseRefresh(docBase);
+    }
+    function DocBaseRefreshList() {
+      var docBase = document.docBaseList.docBase[document.docBaseList.docBase.selectedIndex].value;
+      DocBaseRefresh(docBase);
+    }
+    function DocBaseRefresh(docBase) {
+      document.docBaseList.docBase.value = docBase;
+      for (i = 0; i < document.docBaseList.doc.length; i++)
+        document.docBaseList.doc[i].selected = false;
+      document.docBaseList.submit();
+    }
+    function LanguageRefreshDest() {
+      var lang = document.formDocOperation.language[document.formDocOperation.language.selectedIndex].value;
+      LanguageRefresh(lang);
+    }
+    function LanguageRefreshList() {
+      var lang = document.docBaseList.language[document.docBaseList.language.selectedIndex].value;
+      LanguageRefresh(lang);
+    }
+    function LanguageRefresh(language) {
+      document.docBaseList.language.value = language;
+      for (i = 0; i < document.docBaseList.doc.length; i++)
+        document.docBaseList.doc[i].selected = false;
+      document.docBaseList.submit();
+    }
+    -->
+  </script>
+
+let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")
+
+let $docBaseOptions :=
+          <select>
+            <option value ="archimedes">Archimedes</option>
+            <option value ="echo">Echo</option>
+            <option value ="tei">TEI</option>
+          </select>
+let $docBaseOptionsSelected :=
+  for $option in $docBaseOptions/option
+    return element { node-name($option)}
+                   { if ($option/@value = $docBase)
+                     then attribute {'selected'}
+                                    {'true'}
+                     else (),
+                     $option/@*,
+                     $option/node() }
+let $docBaseSelectBoxDest :=  
+  <select name="docBase" onchange="DocBaseRefreshDest()">{$docBaseOptionsSelected}</select>
+let $docBaseSelectBoxList :=
+  <select name="docBase" onchange="DocBaseRefreshList()">{$docBaseOptionsSelected}</select>
+
+let $languageOptions :=
+          <select>
+            <option value = "ar">Arabic</option>
+            <option value = "zh">Chinese</option>
+            <option value = "nl">Dutch</option>
+            <option value = "en">English</option>
+            <option value = "fr">French</option>
+            <option value = "de">German</option>
+            <option value = "el">Greek</option>
+            <option value = "it">Italian</option>
+            <option value = "la">Latin</option>
+          </select>
+let $languageOptionsSelected :=
+  for $option in $languageOptions/option
+    return element { node-name($option)}
+                   { if ($option/@value = $language)
+                     then attribute {'selected'}
+                                    {'true'}
+                     else (),
+                     $option/@*,
+                     $option/node() }
+let $languageSelectBoxDest :=  
+  <select name="language" onchange="LanguageRefreshDest()">{$languageOptionsSelected}</select>
+let $languageSelectBoxList :=
+  <select name="language" onchange="LanguageRefreshList()">{$languageOptionsSelected}</select>
+
+let $docsSelectBoxOptions := 
+  for $docFileName at $pos in $docFileNames
+    let $existIdentifier := concat("/", $docBase, "/", $language, "/", $docFileName)
+    let $option := <option value ="{$existIdentifier}">{$docFileName}</option>
+  order by $docFileName
+  return $option
+let $docsSelectBox := 
+  <select name="doc" style="width: 100%;" size="20" onclick="DocumentSelection()">
+    {$docsSelectBoxOptions}
+  </select>
+
+let $error :=
+  if ($eSciDocCookieId = '' or empty($eSciDocCookieId))
+  then <bla>No login context available. Please <a href="login-exist.xql">login</a> before you do an operation</bla>
+  else "no"
+
+let $resultHtml := 
+  if ($error = 'no')
+  then 
+    <div>
+    <table align="middle" width="100%" rules="all" border="1" cellpadding="15">
+      <colgroup>
+        <col width="50%"/>
+        <col width="50%"/>
+      </colgroup>
+      <tr>
+      <td valign="top">
+        <form name="formDocOperation" action="{session:encode-url(xs:anyURI('doc-operation-result-exist.xql'))}" method="post" enctype="multipart/form-data">
+        <table>
+          <tr><td><b>Destination</b></td></tr>
+          <tr>
+            <td>
+              Document base: 
+              {$docBaseSelectBoxDest}
+              Language: 
+              {$languageSelectBoxDest}
+            </td>
+          </tr>
+          <tr><td><br/></td></tr>
+          <tr><td>Document name: <input type="text" size="40" name="fileName" value=""/> <a href="../info.xql?info=docInterfaceDestDocName" onclick="window.open(&quot;../info.xql?info=docInterfaceDestDocName&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface source"/></a></td></tr>
+          <tr><td>Document link: <a id="existLink" href=""></a></td></tr>
+          <tr><td><br/></td></tr>
+          <tr><td><b>Source <a href="../info.xql?info=docInterfaceSource" onclick="window.open(&quot;../info.xql?info=docInterfaceSource&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface source"/></a></b></td></tr>
+          <tr><td>Local file: <input type="file" size="40" name="srcLocalFileName" onchange="LocalFileNameSelection()" maxlength="10000000" accept="text/xml" value="srcLocalFileName"/>
+                              <input type="button" name="resetSrcLocalFileName" value="Reset" onclick="ResetSrcLocalFileName()"/></td></tr>
+          <tr><td><text style="margin-left:10px;"></text>or</td></tr>
+          <tr><td>Url: <input type="text" size="40" name="srcUrl" onchange="UrlSelection()" value=""/></td></tr>
+          <tr><td><br/></td></tr>
+          <tr>
+            <td>
+              <b>Operation</b><br/>
+              <select name="operation" onchange="OperationSelection()">
+                <option value ="updateExist" selected="true">Create/Update</option>
+                <option value ="deleteExist">Delete</option>
+              </select>
+              <input type="submit" name="performOperation" value="Execute"/>
+              <a href="../info.xql?info=docInterfaceOperation" onclick="window.open(&quot;../info.xql?info=docInterfaceOperation&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface operation"/></a>
+            </td>
+          </tr>
+        </table>
+        </form>
+      </td>
+      <td valign="top">
+        <form name="docBaseList" action="doc-operation-exist.xql" method="get">
+        <table>
+          <tr>
+            <td>
+              <b>Documents</b><br/>
+              <br/>
+              Document base: 
+              {$docBaseSelectBoxList}
+              Language:
+              {$languageSelectBoxList}
+            </td>
+          </tr>
+          <tr><td>{$docsSelectBox}</td></tr>
+        </table>
+        </form>
+      </td>
+      </tr>
+    </table>
+    </div>
+  else 
+    <div><b>Error in operation:</b> {$error}</div> 
+
+
+
+let $title := "MPDL: eXist document interface"
+return
+<html>
+<head>
+<title>{$title}</title>
+{$javascriptHtml}
+</head>
+<body>
+  <h1>{$title}</h1>
+  {$resultHtml}
+  <br/>
+  See the <a href="doc-operation-exist.xql?_source=yes">XQuery source</a> of this page, if you find a bug <a href="https://itgroup.mpiwg-berlin.mpg.de:8080/tracs/mpdl-project-software/newticket">let us know</a>
+</body>
+</html>
\ No newline at end of file
Binary file software/eXist/webapp/mpdl/escidoc/.DS_Store has changed
Binary file software/eXist/webapp/mpdl/images/.DS_Store has changed
Binary file software/eXist/webapp/mpdl/interface/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/interface/echo/echoDocuView.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/interface/echo/echoDocuView.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -6,7 +6,7 @@
 
 let $mpdlDocUri := request:get-parameter("document", ())
 let $echoArchivePath := mpdl-text:getEchoArchivePath($mpdlDocUri)
-let $echoURLDocuView := concat("http://mpdl-dev.mpiwg-berlin.mpg.de/ECHOdocuView?url=", $echoArchivePath, "&amp;optionToggle=1")
+let $echoURLDocuView := concat("http://mpdl-dev.mpiwg-berlin.mpg.de/ECHOdocuView?url=", $echoArchivePath)
 let $urlDocuViewer := <a href="{$echoURLDocuView}">redirect to Echo</a>
 let $diglibAvailable := 
   if ($echoArchivePath = "XXXXDigilibNotAvailableXXXX")
Binary file software/eXist/webapp/mpdl/interface/external/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/interface/lt/wordInfo.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/interface/lt/wordInfo.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -9,6 +9,7 @@
 
 let $type :=  request:get-parameter("type", "compact")
 let $language := request:get-parameter("language", "")
+let $display := request:get-parameter("display", "")
 let $word := request:get-parameter("word", "")
 let $placeHref := request:get-parameter("placeHref", "")
 let $output := request:get-parameter("output", "xml")
@@ -61,11 +62,22 @@
       for $form in $lemma/forms/form
       order by $form/form-name
       return $form
+    let $remotePerseusLink :=
+      if ($language = "ar" or $language = "la")
+      then concat("http://www.perseus.tufts.edu/hopper/morph?l=", $lemma/lemma-name, "&amp;la=", $language)
+      else if ($language = "el")
+      then concat("http://www.perseus.tufts.edu/hopper/morph?l=", $lemma/lemma-name, "&amp;la=greek")
+      else ""
+    let $lemmaExternalLink :=
+      if ($language = "ar" or $language = "el" or $language = "la")
+      then <directLink xlink:type="simple" xlink:href="{$remotePerseusLink}"/>
+      else ()
     let $retLemma := 
       <lemma>
         {$lemma/provider}
         {$lemma/language}
         {$lemma/lemma-name}
+        {$lemmaExternalLink}
         <forms size="{$lemma/forms-size}">{$orderedForms}</forms>
       </lemma>
   order by $lemma/lemma-name
@@ -173,7 +185,7 @@
           else $l
         let $repairedEntryContentLink :=
           if ($lexName = "dwds")
-          then concat("http://beta.dwds.de/?qu=", $l)
+          then concat("http://www.dwds.de/search/?qu=", $l)
           else if ($lexName = "slater")
           then concat("http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:1999.04.0072:entry=", $lLink)
           else if ($lexName = "artfl-fr-en")
@@ -245,6 +257,7 @@
           let $dictEntryContentParsedTmp := 
             if ($dictEntryXmlValid = "true" and empty($dictEntryRepairedContentLink))
             then util:parse($dictEntryRepairedContent)
+            (: then <bla>bla</bla>  :)
             else if ($dictEntryXmlValid = "true" and not(empty($dictEntryRepairedContentLink)) and $output = "html")
             then <div>External link: <a href="{$dictEntryRepairedContentLink/@xlink:href}">{$dictEntryRepairedContentLink}</a></div>
             else if ($dictEntryXmlValid = "true" and not(empty($dictEntryRepairedContentLink)) and $output = "xml")
@@ -390,7 +403,10 @@
   then util:declare-option("exist:serialize", "method=html media-type=text/html omit-xml-declaration=no indent=yes encoding=utf-8")
   else util:declare-option("exist:serialize", "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8")
 
-let $queryResultHeaderStr := <h2>Word information for: {$word}</h2>
+let $queryResultHeaderStr := 
+  if ($display = "")
+  then <h2>Word information for: {$word}</h2>
+  else <h2>Word information for: {$display}</h2>
 let $commentExternalLinks := 
    "[* external links may not function]"
 
--- a/software/eXist/webapp/mpdl/interface/page-fragment.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/interface/page-fragment.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -22,6 +22,8 @@
 let $reqPF := request:get-parameter("pf", "")
 let $reqSN := number(request:get-parameter("sn", "-1"))
 let $xPointer := request:get-parameter("xpointer", "")
+let $highlightElement := request:get-parameter("highlightElement", "")
+let $highlightElementPos := number(request:get-parameter("highlightElementPos", "-1"))
 let $highlightQuery := request:get-parameter("highlightQuery", "")
 let $regCharNorm := request:get-parameter("characterNormalization", "")
 let $tmpCharNorm := string-join($regCharNorm, ',')
@@ -232,7 +234,7 @@
   else ()
 let $returnPageFragmentTmp := util:parse($retPageFragment)  (: returns a valid xml document for that string   :)  
 
-let $externalElementsTmpTmp := mpdltext:externalObject("read", "element", concat("<object uid=&quot;joe&quot; documentId=&quot;", $mpdlDocUri, "&quot; xpointer=&quot;", "#xpointer(id(", "'page", $pn, "'", "))&quot;></object>"))
+let $externalElementsTmpTmp := mpdltext:externalObject("read", "element", concat("<object documentId=&quot;", $mpdlDocUri, "&quot; xpointer=&quot;", "id(", "'page", $pn, "'", ")&quot;></object>"))
 let $externalElementsTmp := 
   if(not($externalElementsTmpTmp = ""))
   then util:parse($externalElementsTmpTmp)
@@ -355,6 +357,8 @@
         <number-orig>{$pageNumberOrig}</number-orig>
         <number-orig-norm>{$pageNumberOrigNorm}</number-orig-norm>
         <sentence-number>{$sn}</sentence-number>
+        <highlightElement>{$highlightElement}</highlightElement>
+        <highlightElementPos>{$highlightElementPos}</highlightElementPos>
         <digilib-available>{$digilibAvailable}</digilib-available>
         <image-available>{$imageIsAvailable}</image-available>
         <image-file-name>{$imageFileName}</image-file-name>
Binary file software/eXist/webapp/mpdl/lt/.DS_Store has changed
Binary file software/eXist/webapp/mpdl/lucene/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/lucene/search.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/lucene/search.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -37,25 +37,19 @@
     else if ($queryType = 'fulltextMorphLemma')
     then concat('lemmalemma', $queryStr)
     else ()
-  let $pageBreaks := 
-    if ($mpdlCollectionName = 'archimedes')
-    then $document//pb
-    else if ($mpdlCollectionName = 'echo') 
-    then $document//echo:pb
-    else if ($mpdlCollectionName = 'tei') 
-    then $document//TEI:pb
-    else $document//pb
+  let $pageBreaks := $document//*[name() = 'pb']
   let $luceneParseResult := mpdltext:lucene-parse-query($queryStr)
   let $t := 
     if ($luceneParseResult != '')
     then ()
     else if ($mpdlCollectionName = 'archimedes')
-    then $document//s[ft:query(., $query)]
+    then $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'echo')
-    then $document//echo:s[ft:query(., $query)]
+    then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'tei')
-    then $document//TEI:s[ft:query(., $query)]
-    else $document//s[ft:query(., $query)]
+    then $document//TEI:s[ft:query(., $query)]|$document//TEI:head[ft:query(., $query)]
+    else $document//s[ft:query(., $query)]|$document//head[ft:query(., $query)]
+    (: else $document//*[name() = 's' or name() = 'head'][ft:query(., $query)]  this would be much slower and would consume too much memory   :)
   let $from := ($pn * $pageSize) - $pageSize + 1
   let $to := $pn * $pageSize
   (: performance improvements: result set of 500 needs 3 sec., result set of 10 needs 0,7 sec.:)
@@ -64,31 +58,39 @@
     where $poss >= $from and $poss <= $to
     return $ss
   let $queryResult :=
-    for $s at $pos in $tempQueryResult
-      let $pnOfS := count($pageBreaks[. << $s])        (: faster: comparison only in pb elements of this document :)
-      let $pb := subsequence($pageBreaks, $pnOfS, 1)
+    for $hit at $pos in $tempQueryResult
+      let $hitType := local-name($hit)
+      let $pnOfHit := count($pageBreaks[. << $hit])        (: faster: comparison only in pb elements of this document :)
+      let $pb := subsequence($pageBreaks, $pnOfHit, 1)
       (: test if sentence surrounds page break; costs 0,1 sec performance :)
-      let $pbPlus1 := subsequence($pageBreaks, $pnOfS + 1, 1)
-      let $sSurroundsPB := 
-        if ($pbPlus1/parent::node() = $s and $pbPlus1 intersect $s/descendant::node())
+      let $pbPlus1 := subsequence($pageBreaks, $pnOfHit + 1, 1)
+      let $hitSurroundsPB := 
+        if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
         then true()
         else false()
-      let $posOfS :=                           (: faster: comparison only in s elements of this document :)
-        if ($mpdlCollectionName = 'archimedes')
-        then count($pb/following::s[. << $s]) + 1
-        else if ($mpdlCollectionName = 'echo')
-        then count($pb/following::echo:s[. << $s]) + 1
-        else if ($mpdlCollectionName = 'tei')
-        then count($pb/following::TEI:s[. << $s]) + 1
-        else count($pb/following::s[. << $s]) + 1
+      let $posOfHit :=           (: faster: comparison only in s or head elements of this document and only in a specific namespace :)
+        if ($mpdlCollectionName = 'archimedes' and $hitType = 's')
+        then count($pb/following::s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'archimedes' and $hitType = 'head')
+        then count($pb/following::head[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'echo' and $hitType = 's')
+        then count($pb/following::echo:s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'echo' and $hitType = 'head')
+        then count($pb/following::echo:head[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'tei' and $hitType = 's')
+        then count($pb/following::TEI:s[. << $hit]) + 1
+        else if ($mpdlCollectionName = 'tei' and $hitType = 'head')
+        then count($pb/following::TEI:head[. << $hit]) + 1
+        else count($pb/following::s[. << $hit]) + 1
       let $position := $from - 1 + $pos
       let $resultElem := 
         <hit>
+          <hitType>{$hitType}</hitType>
           <pos>{$position}</pos>
-          <pn>{$pnOfS}</pn>
-          <pos-of-s>{$posOfS}</pos-of-s>
-          <s>{string($s)}</s>
-          <s-surrounds-pb>{$sSurroundsPB}</s-surrounds-pb>
+          <pn>{$pnOfHit}</pn>
+          <hitPos>{$posOfHit}</hitPos>
+          <hitString>{string($hit)}</hitString>
+          <hitSurroundsPB>{$hitSurroundsPB}</hitSurroundsPB>
         </hit>
     return $resultElem
   let $resultSize := count($t)
--- a/software/eXist/webapp/mpdl/page-query-result.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/page-query-result.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -23,6 +23,8 @@
 let $reqSN := number(request:get-parameter("sn", "-1"))
 let $xPointer := request:get-parameter("xpointer", "")
 let $query := request:get-parameter("query", "")
+let $highlightElement := request:get-parameter("highlightElement", "")
+let $highlightElementPos := number(request:get-parameter("highlightElementPos", "-1"))
 let $reqQueryResultPN := request:get-parameter("query-result-pn", "")
 let $queryResultPN := 
   if ($reqQueryResultPN = '' or $reqQueryResultPN = '0')
@@ -130,7 +132,7 @@
   else $reqPN
 let $sn := 
   if (($queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma') and $countHits > 0 and $reqPN <= 0 and $reqSN < 0)
-  then number($firstHit/pos-of-s)
+  then number($firstHit/posOfHit)
   else $reqSN
 
 (: 10 or more is an error :)
@@ -274,7 +276,7 @@
   else ()
 let $returnPageFragmentTmp := util:parse($retPageFragment)  (: returns a valid xml document for that string   :)  
 
-let $externalElementsTmpTmp := mpdltext:externalObject("read", "element", concat("<object uid=&quot;joe&quot; documentId=&quot;", $mpdlDocUri, "&quot; xpointer=&quot;", "#xpointer(id(", "'page", $pn, "'", "))&quot;></object>"))
+let $externalElementsTmpTmp := mpdltext:externalObject("read", "element", concat("<object documentId=&quot;", $mpdlDocUri, "&quot; xpointer=&quot;", "id(", "'page", $pn, "'", ")&quot;></object>"))
 let $externalElementsTmp := 
   if(not($externalElementsTmpTmp = ""))
   then util:parse($externalElementsTmpTmp)
@@ -374,6 +376,8 @@
         <mode>{$mode}</mode>
         <number>{$pn}</number>
         <sentence-number>{$sn}</sentence-number>
+        <highlightElement>{$highlightElement}</highlightElement>
+        <highlightElementPos>{$highlightElementPos}</highlightElementPos>
         <header>{$pageHeader}</header>
         <number-orig>{$pageNumberOrig}</number-orig>
         <digilib-available>{$digilibAvailable}</digilib-available>
Binary file software/eXist/webapp/mpdl/presentation/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -84,9 +84,10 @@
   <xsl:variable name="elemXmlNodeIdTmp" select="saxon:path(.)"/>
   <xsl:variable name="elemXmlNodeId" select="concat('/', substring-after(substring-after(substring-after($elemXmlNodeIdTmp, '/'), '/'), '/'))"/>
   <xsl:variable name="extElemXmlNodeIds" select="$externalElements//@xmlNodeId"/>
+  <!-- Bug: if there are more than one external node at the same position, index-of delivers an error: ToDo: handle more than one external nodes at one position  -->
   <xsl:variable name="extElemIndex" select="index-of($extElemXmlNodeIds, $elemXmlNodeId)"/>
   <xsl:variable name="extElem" select="$externalElements/*[$extElemIndex]"/>
-  <xsl:variable name="extElemContent" select="$extElem/content/*[1]"/>
+  <xsl:variable name="extElemContent" select="$extElem/*[1]"/>
   <xsl:variable name="extElemXPointer" select="$extElem/@xpointer"/>
   <xsl:variable name="extElemXPointerPoint" select="substring-before(substring-after($extElemXPointer, '/point('), ')')"/>
   <xsl:variable name="extElemXPointerPointInt">
@@ -140,7 +141,7 @@
     <xsl:sequence select="$extElemContent"/>
   </xsl:if>
   <xsl:if test="$extElemXPointerPointInt &gt;= 0">
-    <xsl:variable name="extElemContent" select="$extElem/content/*[1]"/>
+    <xsl:variable name="extElemContent" select="$extElem/*[1]"/>
     <xsl:variable name="extElemContentSerialized" select="saxon:serialize($extElemContent, 'myXml')"/>
     <xsl:variable name="elemSerialized" select="saxon:serialize(., 'myXml')"/>
     <xsl:variable name="insertedElemSerialized" select="mpdlxmlutil:insertAtCharPos(mpdlxmlutil:new(), $elemSerialized, string($extElemXPointerPointInt), $extElemContentSerialized)"/>
--- a/software/eXist/webapp/mpdl/presentation/pageFragmentHtml.xsl	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageFragmentHtml.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -19,11 +19,15 @@
 <xsl:import href="/db/mpdl/presentation/functions-text.xsl" />
 <xsl:import href="/db/mpdl/presentation/functions-util.xsl" />
 
+<xsl:strip-space elements="*"/> 
+
 <xsl:output method="xhtml" encoding="utf-8"/>
 
 <xsl:variable name="mode" select="/result/page/mode"/>
 <xsl:variable name="language" select="/result/document-description/language"/>
 <xsl:variable name="sn" select="number(/result/page/sentence-number)"/>
+<xsl:variable name="highlightElement" select="/result/page/highlightElement"/>
+<xsl:variable name="highlightElementPos" select="number(/result/page/highlightElementPos)"/>
 <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)"/>
@@ -133,6 +137,7 @@
 
 <xsl:template match="element()|comment()|processing-instruction()" mode="xml">
   <xsl:variable name="elementName" select="name()"/>
+  <xsl:variable name="countPrecedingElemsStr" select="concat('count(preceding::', $elementName, '[. >> $p1]) + 1')"/>
   <xsl:variable name="elementPresentation">
     <xsl:choose>
     <xsl:when test="element() = node() or text() != '' or self::comment() or self::processing-instruction()">
@@ -153,30 +158,24 @@
     </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="currentHighlightElementPos">
     <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:when test="($highlightElement = 's' or $highlightElement = '') and . = $firstSentence and ($topPB >> .)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></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:variable name="class">
+    <xsl:choose>
+      <xsl:when test="($sn >= 0 and $sn = $currentHighlightElementPos) or ($elementName = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos)"><xsl:value-of select="'xml element highlight'"/></xsl:when>
+      <xsl:when test="$elementName = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos != $currentHighlightElementPos"><xsl:value-of select="'xml element'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'xml element'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <!-- Show the sentence in color light grey if it is given as highlightElementPos -->
+  <ul class="{$class}" id="{$elementName}{$currentHighlightElementPos}">
+    <xsl:sequence select="$elementPresentation"/>
+  </ul>
 </xsl:template>
 
 <xsl:template match="attribute()" mode="xml">
@@ -191,15 +190,24 @@
 </xsl:template>
 
 <xsl:template match="text()" mode="xml">
-  <xsl:variable name="parentS" select="./ancestor::s"/>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="highlightElementAncestor">
     <xsl:choose>
-      <xsl:when test="$parentS = $firstSentence and ($topPB >> $parentS)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:sequence select="./ancestor::s"/></xsl:when>
+      <xsl:when test="$highlightElement = 'head'"><xsl:sequence select="./ancestor::head"/></xsl:when>
+      <xsl:otherwise><xsl:sequence select="./ancestor::s"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="highlightElementAncestorType" select="name($highlightElementAncestor/*[1])"/>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="($highlightElement = 's' or $highlightElement = '') and $highlightElementAncestor = $firstSentence and ($topPB >> $highlightElementAncestor)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:when test="$highlightElement = 'head'"><xsl:value-of select="count(preceding::head[. >> $topPB]) + 1"/></xsl:when>
       <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:choose>
-    <xsl:when test="$highlightQuery != '' and $sn >= 0 and $sn = $actualSN">
+    <xsl:when test="$highlightQuery != '' and $highlightElementAncestorType = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos">
       <xsl:sequence select="text:highlight(string(.), $highlightQueryTerms, $highlightQueryWords, 'false')"/>
     </xsl:when>
     <xsl:otherwise>
@@ -340,7 +348,26 @@
 </xsl:template>
 
 <xsl:template match="head" mode="text">
-  <p class="bf center"><xsl:apply-templates mode="text"/></p>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="$highlightElement = 'head'"><xsl:value-of select="count(preceding::head[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="class">
+    <xsl:choose>
+      <xsl:when test="not(empty(@style)) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="concat('head highlight bf ', @style)"/></xsl:when>
+      <xsl:when test="empty(@style) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="'head highlight bf'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'head bf'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <p>
+    <span>
+      <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+      <xsl:attribute name="id"><xsl:value-of select="concat('head', $currentHighlightElementPos)"/></xsl:attribute>
+      <xsl:apply-templates mode="text"/>
+    </span>
+  </p>
 </xsl:template>
 
 <!-- TEI: segmentation   -->
@@ -602,20 +629,35 @@
 </xsl:template>
 
 <xsl:template match="p" mode="text">
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="$highlightElement = 'p'"><xsl:value-of select="count(preceding::p[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:variable name="style" select="@style"/>
+  <xsl:variable name="class">
+    <xsl:choose>
+      <xsl:when test="not(empty(@style)) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="concat('p highlight ', @style)"/></xsl:when>
+      <xsl:when test="empty(@style) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="'p highlight'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'p'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:choose>
     <xsl:when test="not(empty($style))">
       <div>
-        <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
         <span>
-          <xsl:attribute name="class"><xsl:value-of select="$style"/></xsl:attribute>
+          <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+          <xsl:attribute name="id"><xsl:value-of select="concat('p', $currentHighlightElementPos)"/></xsl:attribute>
           <xsl:apply-templates mode="text"/>
         </span>
       </div>
     </xsl:when>
     <xsl:otherwise>
       <div>
-        <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+        <xsl:attribute name="id"><xsl:value-of select="concat('p', $currentHighlightElementPos)"/></xsl:attribute>
         <xsl:apply-templates mode="text"/>
       </div>
     </xsl:otherwise>
@@ -638,7 +680,17 @@
 </xsl:template>
 
 <xsl:template match="expan" mode="text">
-  <xsl:apply-templates mode="text"/>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('expan ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="expan"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="note" mode="text">
@@ -700,7 +752,7 @@
       <xsl:otherwise>
         <xsl:choose>
           <xsl:when test="not(empty(w))">
-            <a class="textPollux" href="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql?language={w/@lang}&amp;word={w/@form}&amp;output=html"><xsl:value-of select="$restChars"/></a>
+            <a class="textPollux" href="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql?language={w/@lang}&amp;display={$text}&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>
@@ -711,6 +763,9 @@
     <xsl:when test="$collectionName = 'echo' and not(contains($style, 'sc'))">
       <span class="{$style}"><xsl:apply-templates mode="text"/></span>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and $style = 'sc' and $length = 1">
+      <span class="sc"><xsl:value-of select="$firstChar"/></span>
+    </xsl:when>
     <xsl:when test="$collectionName = 'echo' and $style = 'sc' and $first2CharsAreUppercase">
       <span class="dc"><xsl:value-of select="$firstChar"/></span><span class="sc"><xsl:sequence select="$rest"/></span>
     </xsl:when>
@@ -718,7 +773,7 @@
       <span class="dc"><span class="{$styleWithoutSC}"><xsl:value-of select="$firstChar"/></span></span><span class="sc"><span class="{$styleWithoutSC}"><xsl:sequence select="$rest"/></span></span>
     </xsl:when>
     <xsl:when test="$collectionName = 'echo' and $style = 'sc' and not($first2CharsAreUppercase)">
-      <xsl:apply-templates mode="text"/>
+      <span class="sc"><xsl:apply-templates mode="text"/></span>
     </xsl:when>
     <xsl:when test="$collectionName = 'echo' and contains($style, 'sc') and not($first2CharsAreUppercase)">
       <span class="sc"><span class="{$styleWithoutSC}"><xsl:apply-templates mode="text"/></span></span>
@@ -747,37 +802,107 @@
 </xsl:template>
 
 <xsl:template match="q" mode="text">
-  <span class="q"><xsl:apply-templates mode="text"/></span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('q ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="q"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="quote" mode="text">
-  <div class="quote"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('quote ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="quote"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="blockquote" mode="text">
-  <div class="blockquote"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('blockquote ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="blockquote"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="set-off" mode="text">
-  <div class="set-off"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('set-off ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="set-off"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="reg" mode="text">
-  <span class="reg">   
-    <xsl:apply-templates mode="text"/>
-  </span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('reg ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="reg"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </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:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('reg ', @type, ' ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="var">
+        <xsl:attribute name="class"><xsl:value-of select="concat('var ', @type)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="num" mode="text">
-  <span class="num"><xsl:apply-templates mode="text"/></span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="'num'"/></xsl:attribute>
+        <span>
+          <xsl:attribute name="class"><xsl:value-of select="@style"/></xsl:attribute>
+          <xsl:apply-templates mode="text"/>
+        </span>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="num"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="gap" mode="text">
@@ -1003,27 +1128,31 @@
 <xsl:template match="w" mode="text">
   <xsl:variable name="baseUrlLex" select="'http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/'"/>
   <xsl:variable name="wordLanguage" select="@lang"/>
-  <xsl:variable name="form" select="@form"/>
+  <xsl:variable name="form" select="encode-for-uri(@form)"/>
+  <xsl:variable name="displayWord"><xsl:apply-templates mode="text"/></xsl:variable>
+  <xsl:variable name="displayWordUrlEncoded" select="encode-for-uri($displayWord)"/>
   <xsl:choose>
     <xsl:when test="not(empty(anchor))">
       <xsl:for-each select="node()">
+        <xsl:variable name="dispWord"><xsl:apply-templates mode="text" select="."/></xsl:variable>
+        <xsl:variable name="dispWordUrlEncoded" select="encode-for-uri($dispWord)"/>
         <xsl:choose>
           <xsl:when test=". instance of text()">
             <a class="textPollux">
-              <xsl:attribute name="href"><xsl:value-of select="concat($baseUrlLex, 'lt/wordInfo.xql?language=', $wordLanguage, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
-              <xsl:apply-templates mode="text" select="."/>
+              <xsl:attribute name="href"><xsl:value-of select="concat($baseUrlLex, 'lt/wordInfo.xql?language=', $wordLanguage, '&amp;display=', $dispWordUrlEncoded, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
+              <xsl:sequence select="$dispWord"/>
             </a>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:apply-templates mode="text" select="."/>
+              <xsl:sequence select="$dispWord"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:for-each>
     </xsl:when>
     <xsl:otherwise>
       <a class="textPollux">
-        <xsl:attribute name="href"><xsl:value-of select="concat($baseUrlLex, 'lt/wordInfo.xql?language=', $wordLanguage, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
-        <xsl:apply-templates mode="text"/>
+        <xsl:attribute name="href"><xsl:value-of select="concat($baseUrlLex, 'lt/wordInfo.xql?language=', $wordLanguage, '&amp;display=', $displayWordUrlEncoded, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
+        <xsl:sequence select="$displayWord"/>
       </a>
     </xsl:otherwise>
   </xsl:choose>
@@ -1031,17 +1160,16 @@
 
 <xsl:template match="s" mode="text">
   <xsl:variable name="style" select="@style"/>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="currentSN">
     <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">
+    <!-- Show the sentence in color light grey if it is given as sn or highlightElementPos -->
+    <xsl:when test="($sn >= 0 and $sn = $currentSN) or ($highlightElement = 's' and $highlightElementPos >= 0 and $highlightElementPos = $currentSN)">
+      <span class="s highlight" id="s{$currentSN}">
         <xsl:if test="not(empty(@xmlNodeId))"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
@@ -1054,7 +1182,7 @@
       </span>
     </xsl:when>
     <xsl:otherwise>
-      <span class="s">
+      <span class="s" id="s{$currentSN}">
         <xsl:if test="not(empty(@xmlNodeId))"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
@@ -1071,20 +1199,29 @@
 
 
 <xsl:template match="text()" mode="text">
-  <xsl:variable name="parentS" select="./ancestor::s"/>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="highlightElementAncestor">
     <xsl:choose>
-      <xsl:when test="$parentS = $firstSentence and ($topPB >> $parentS)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:sequence select="./ancestor::s"/></xsl:when>
+      <xsl:when test="$highlightElement = 'head'"><xsl:sequence select="./ancestor::head"/></xsl:when>
+      <xsl:otherwise><xsl:sequence select="./ancestor::s"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="highlightElementAncestorType" select="name($highlightElementAncestor/*[1])"/>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="($highlightElement = 's' or $highlightElement = '') and $highlightElementAncestor = $firstSentence and ($topPB >> $highlightElementAncestor)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:when test="$highlightElement = 'head'"><xsl:value-of select="count(preceding::head[. >> $topPB]) + 1"/></xsl:when>
       <xsl:otherwise><xsl:value-of select="count(preceding::s[. >> $topPB]) + 1"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:choose>
-  <xsl:when test="$highlightQuery != '' and $sn >= 0 and $sn = $actualSN">
-    <xsl:sequence select="text:highlight(string(.), $highlightQueryTerms, $highlightQueryWords, 'false')"/>
-  </xsl:when>
-  <xsl:otherwise>
-    <xsl:value-of select="."/>
-  </xsl:otherwise>
+    <xsl:when test="$highlightQuery != '' and $highlightElementAncestorType = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos">
+      <xsl:sequence select="text:highlight(string(.), $highlightQueryTerms, $highlightQueryWords, 'false')"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="."/>
+    </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
--- a/software/eXist/webapp/mpdl/presentation/pageHtml.css	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageHtml.css	Mon Aug 29 17:40:19 2011 +0200
@@ -16,6 +16,9 @@
 /* unused */
 .setoff    { margin-left:2cm; margin-right:2cm }
 
+/* highlighting    */
+.highlight { background-color:#D3D3D3; }  /* LightGrey    */
+
 /* xml presentation    */
 span.xml.elementName { font-weight:bold;color:purple; }
 span.xml.attributeName { font-weight:bold; }
@@ -83,7 +86,9 @@
 span.sc.it {font-weight:bold; font-style:italic; }
 
 /* ref               */
-span.ref { font-style:italic; } 
+span.ref a:link {text-decoration: underline; color: blue;}
+span.ref a:visited {text-decoration: none; color: #800080;}
+span.ref a:hover {text-decoration: underline; color: blue;}
 
 /* quotes */
 span.q     { font-style:italic; }
--- a/software/eXist/webapp/mpdl/presentation/pageHtml.xsl	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageHtml.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -6,8 +6,8 @@
   xmlns:functx="http://www.functx.com"
   xmlns:saxon="http://saxon.sf.net/"
   xmlns:mpdl="http://www.mpiwg-berlin.mpg.de/ns/mpdl"
+  xmlns:mpdl-util="http://www.mpiwg-berlin.mpg.de/ns/mpdl/util"
   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/" 
@@ -19,6 +19,8 @@
 <xsl:import href="/db/mpdl/presentation/functions-text.xsl" />
 <xsl:import href="/db/mpdl/presentation/functions-util.xsl" />
 
+<xsl:strip-space elements="*"/> 
+
 <xsl:output method="xhtml" encoding="utf-8"/>
 
 <xsl:variable name="errorMessage" select="string(/result/query/result/error)"/>
@@ -29,6 +31,8 @@
 <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="highlightElement" select="/result/page/highlightElement"/>
+<xsl:variable name="highlightElementPos" select="number(/result/page/highlightElementPos)"/>
 <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)"/>
@@ -139,8 +143,11 @@
           </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 test="/result/page/highlightElement[node()]">
+          <input type="hidden" name="highlightElement" value="{$highlightElement}"/>
+        </xsl:if>
+        <xsl:if test="/result/page/highlightElementPos[node()]">
+          <input type="hidden" name="highlightElementPos" value="{$highlightElementPos}"/>
         </xsl:if>
         <input type="hidden" name="query-type" value="{$queryType}"/>
         <xsl:if test="/result/query/result[node()]">
@@ -154,9 +161,6 @@
         <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>
@@ -428,7 +432,7 @@
               <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>
+                  <b><xsl:value-of select="$resultSize"/> 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>
@@ -533,24 +537,29 @@
                 <xsl:variable name="term" select="term"/>
                 <td><xsl:value-of select="$pos"/>.</td>
                 <td align="left">
+                  <xsl:variable name="hitType" select="hitType"/>
                   <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="hitString" select="hitString"/>
+                  <xsl:variable name="hitPos" select="hitPos"/>
+                  <xsl:variable name="hitSurroundsPB" select="hitSurroundsPB"/>
                   <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 test="$hitType = 's' and $hitSurroundsPB = 'false'">
+                    <a href="?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a>
+                  </xsl:when>
+                  <xsl:when test="$hitType = 'head'">
+                    <a href="?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#head{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Head <xsl:value-of select="$hitPos"/></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>
+                    <a href="?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a> / <a href="?{$documentValue}&amp;pn={$hitPN + 1}&amp;{$modeValue}&amp;query-type={$queryType}{$queryValueEscaped2}&amp;query-result-pn={$queryResultPN}#s0">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')"/>
+                  <xsl:sequence select="text:highlight($hitString, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/>
                 </td>
                 </tr>
               </xsl:for-each>
@@ -659,6 +668,7 @@
 
 <xsl:template match="element()|comment()|processing-instruction()" mode="xml">
   <xsl:variable name="elementName" select="name()"/>
+  <xsl:variable name="countPrecedingElemsStr" select="concat('count(preceding::', $elementName, '[. >> $p1]) + 1')"/>
   <xsl:variable name="elementPresentation">
     <xsl:choose>
     <xsl:when test="element() = node() or text() != '' or self::comment() or self::processing-instruction()">
@@ -679,30 +689,24 @@
     </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="currentHighlightElementPos">
     <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:when test="($highlightElement = 's' or $highlightElement = '') and . = $firstSentence and ($topPB >> .)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></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:variable name="class">
+    <xsl:choose>
+      <xsl:when test="($sn >= 0 and $sn = $currentHighlightElementPos) or ($elementName = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos)"><xsl:value-of select="'xml element highlight'"/></xsl:when>
+      <xsl:when test="$elementName = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos != $currentHighlightElementPos"><xsl:value-of select="'xml element'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'xml element'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <!-- Show the sentence in color light grey if it is given as highlightElementPos -->
+  <ul class="{$class}" id="{$elementName}{$currentHighlightElementPos}">
+    <xsl:sequence select="$elementPresentation"/>
+  </ul>
 </xsl:template>
 
 <xsl:template match="attribute()" mode="xml">
@@ -718,18 +722,29 @@
 
 <!-- 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:variable name="ancestorStr" select="concat('./ancestor::', $highlightElement)"/>
+  <xsl:variable name="highlightElementAncestor">
     <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:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:sequence select="./ancestor::s"/></xsl:when>
+      <xsl:otherwise><xsl:sequence select="saxon:evaluate($ancestorStr)"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="highlightElementAncestorType" select="name($highlightElementAncestor/*[1])"/>
+  <xsl:variable name="countPrecedingElemsStr" select="concat('count(preceding::', $highlightElement, '[. >> $p1]) + 1')"/>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="($highlightElement = 's' or $highlightElement = '') and $highlightElementAncestor = $firstSentence and ($topPB >> $highlightElementAncestor)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:choose>
-    <xsl:when test="$ftQueryMode != 'false' and $sn >= 0 and $sn = $actualSN">
+    <xsl:when test="$ftQueryMode != 'false' and $highlightElementAncestorType = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos">
       <xsl:sequence select="text:highlight(string(.), $ftQueryTerms, $ftQueryHighlightWords, 'false')"/>
     </xsl:when>
-    <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
+    <xsl:otherwise>
+      <xsl:value-of select="."/>
+    </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
@@ -866,7 +881,26 @@
 </xsl:template>
 
 <xsl:template match="head" mode="text">
-  <p class="bf center"><xsl:apply-templates mode="text"/></p>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="$highlightElement = 'head'"><xsl:value-of select="count(preceding::head[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="class">
+    <xsl:choose>
+      <xsl:when test="not(empty(@style)) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="concat('head highlight bf ', @style)"/></xsl:when>
+      <xsl:when test="empty(@style) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="'head highlight bf'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'head bf'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <p>
+    <span>
+      <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+      <xsl:attribute name="id"><xsl:value-of select="concat('head', $currentHighlightElementPos)"/></xsl:attribute>
+      <xsl:apply-templates mode="text"/>
+    </span>
+  </p>
 </xsl:template>
 
 <!-- TEI: segmentation   -->
@@ -1128,20 +1162,35 @@
 </xsl:template>
 
 <xsl:template match="p" mode="text">
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="$highlightElement = 'p'"><xsl:value-of select="count(preceding::p[. >> $topPB]) + 1"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:variable name="style" select="@style"/>
+  <xsl:variable name="class">
+    <xsl:choose>
+      <xsl:when test="not(empty(@style)) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="concat('p highlight ', @style)"/></xsl:when>
+      <xsl:when test="empty(@style) and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos"><xsl:value-of select="'p highlight'"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="'p'"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:choose>
     <xsl:when test="not(empty($style))">
       <div>
-        <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
         <span>
-          <xsl:attribute name="class"><xsl:value-of select="$style"/></xsl:attribute>
+          <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+          <xsl:attribute name="id"><xsl:value-of select="concat('p', $currentHighlightElementPos)"/></xsl:attribute>
           <xsl:apply-templates mode="text"/>
         </span>
       </div>
     </xsl:when>
     <xsl:otherwise>
       <div>
-        <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
+        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
+        <xsl:attribute name="id"><xsl:value-of select="concat('p', $currentHighlightElementPos)"/></xsl:attribute>
         <xsl:apply-templates mode="text"/>
       </div>
     </xsl:otherwise>
@@ -1164,7 +1213,17 @@
 </xsl:template>
 
 <xsl:template match="expan" mode="text">
-  <xsl:apply-templates mode="text"/>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('expan ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="expan"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="note" mode="text">
@@ -1226,7 +1285,7 @@
       <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>
+            <a class="textPollux" href="interface/lt/wordInfo.xql?language={w/@lang}&amp;display={$text}&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>
@@ -1237,6 +1296,9 @@
     <xsl:when test="$collectionName = 'echo' and not(contains($style, 'sc'))">
       <span class="{$style}"><xsl:apply-templates mode="text"/></span>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and $style = 'sc' and $length = 1">
+      <span class="sc"><xsl:value-of select="$firstChar"/></span>
+    </xsl:when>
     <xsl:when test="$collectionName = 'echo' and $style = 'sc' and $first2CharsAreUppercase">
       <span class="dc"><xsl:value-of select="$firstChar"/></span><span class="sc"><xsl:sequence select="$rest"/></span>
     </xsl:when>
@@ -1244,7 +1306,7 @@
       <span class="dc"><span class="{$styleWithoutSC}"><xsl:value-of select="$firstChar"/></span></span><span class="sc"><span class="{$styleWithoutSC}"><xsl:sequence select="$rest"/></span></span>
     </xsl:when>
     <xsl:when test="$collectionName = 'echo' and $style = 'sc' and not($first2CharsAreUppercase)">
-      <xsl:apply-templates mode="text"/>
+      <span class="sc"><xsl:apply-templates mode="text"/></span>
     </xsl:when>
     <xsl:when test="$collectionName = 'echo' and contains($style, 'sc') and not($first2CharsAreUppercase)">
       <span class="sc"><span class="{$styleWithoutSC}"><xsl:apply-templates mode="text"/></span></span>
@@ -1273,37 +1335,107 @@
 </xsl:template>
 
 <xsl:template match="q" mode="text">
-  <span class="q"><xsl:apply-templates mode="text"/></span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('q ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="q"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="quote" mode="text">
-  <div class="quote"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('quote ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="quote"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="blockquote" mode="text">
-  <div class="blockquote"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('blockquote ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="blockquote"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="set-off" mode="text">
-  <div class="set-off"><xsl:apply-templates mode="text"/></div>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <div>
+        <xsl:attribute name="class"><xsl:value-of select="concat('set-off ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <div class="set-off"><xsl:apply-templates mode="text"/></div>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="reg" mode="text">
-  <span class="reg">   
-    <xsl:apply-templates mode="text"/>
-  </span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('reg ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="reg"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </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:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="concat('reg ', @type, ' ', @style)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="var">
+        <xsl:attribute name="class"><xsl:value-of select="concat('var ', @type)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="num" mode="text">
-  <span class="num"><xsl:apply-templates mode="text"/></span>
+  <xsl:choose>
+    <xsl:when test="not(empty(@style))">
+      <span>
+        <xsl:attribute name="class"><xsl:value-of select="'num'"/></xsl:attribute>
+        <span>
+          <xsl:attribute name="class"><xsl:value-of select="@style"/></xsl:attribute>
+          <xsl:apply-templates mode="text"/>
+        </span>
+      </span>
+    </xsl:when>
+    <xsl:otherwise>
+      <span class="num"><xsl:apply-templates mode="text"/></span>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="gap" mode="text">
@@ -1527,27 +1659,31 @@
 <!-- textPollux links                           -->
 <xsl:template match="w" mode="text">
   <xsl:variable name="wordLanguage" select="@lang"/>
-  <xsl:variable name="form" select="@form"/>
+  <xsl:variable name="form" select="encode-for-uri(@form)"/>
+  <xsl:variable name="displayWord"><xsl:apply-templates mode="text"/></xsl:variable>
+  <xsl:variable name="displayWordUrlEncoded" select="encode-for-uri($displayWord)"/>
   <xsl:choose>
     <xsl:when test="not(empty(anchor))">
       <xsl:for-each select="node()">
+        <xsl:variable name="dispWord"><xsl:apply-templates mode="text" select="."/></xsl:variable>
+        <xsl:variable name="dispWordUrlEncoded" select="encode-for-uri($dispWord)"/>
         <xsl:choose>
           <xsl:when test=". instance of text()">
             <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" select="."/>
+              <xsl:attribute name="href"><xsl:value-of select="concat('interface/lt/wordInfo.xql?language=', $wordLanguage, '&amp;display=', $dispWordUrlEncoded, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
+              <xsl:sequence select="$dispWord"/>
             </a>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:apply-templates mode="text" select="."/>
+            <xsl:sequence select="$dispWord"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:for-each>
     </xsl:when>
     <xsl:otherwise>
       <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"/>
+        <xsl:attribute name="href"><xsl:value-of select="concat('interface/lt/wordInfo.xql?language=', $wordLanguage, '&amp;display=', $displayWordUrlEncoded, '&amp;word=', $form, '&amp;output=html')"/></xsl:attribute>
+        <xsl:sequence select="$displayWord"/>
       </a>
     </xsl:otherwise>
   </xsl:choose>
@@ -1555,17 +1691,16 @@
 
 <xsl:template match="s" mode="text">
   <xsl:variable name="style" select="@style"/>
-  <xsl:variable name="actualSN">
+  <xsl:variable name="currentSN">
     <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">
+    <!-- Show the sentence in color light grey if it is given as sn or highlightElem -->
+    <xsl:when test="($sn >= 0 and $sn = $currentSN) or ($highlightElement = 's' and $highlightElementPos >= 0 and $highlightElementPos = $currentSN)">
+      <span class="s highlight" id="s{$currentSN}">
         <xsl:if test="not(empty(@xmlNodeId))"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
@@ -1578,7 +1713,7 @@
       </span>
     </xsl:when>
     <xsl:otherwise>
-      <span class="s">
+      <span class="s" id="s{$currentSN}">
         <xsl:if test="not(empty(@xmlNodeId))"><xsl:attribute name="xmlNodeId"><xsl:value-of select="@xmlNodeId"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
@@ -1595,20 +1730,29 @@
 
 <!-- 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:variable name="ancestorStr" select="concat('./ancestor::', $highlightElement)"/>
+  <xsl:variable name="highlightElementAncestor">
     <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:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:sequence select="./ancestor::s"/></xsl:when>
+      <xsl:otherwise><xsl:sequence select="saxon:evaluate($ancestorStr)"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="highlightElementAncestorType" select="name($highlightElementAncestor/*[1])"/>
+  <xsl:variable name="countPrecedingElemsStr" select="concat('count(preceding::', $highlightElement, '[. >> $p1]) + 1')"/>
+  <xsl:variable name="currentHighlightElementPos">
+    <xsl:choose>
+      <xsl:when test="($highlightElement = 's' or $highlightElement = '') and $highlightElementAncestor = $firstSentence and ($topPB >> $highlightElementAncestor)">0</xsl:when>
+      <xsl:when test="$highlightElement = 's' or $highlightElement = ''"><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="saxon:evaluate($countPrecedingElemsStr, $topPB)"/></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:when test="$ftQueryMode != 'false' and $highlightElementAncestorType = $highlightElement and $highlightElementPos >= 0 and $highlightElementPos = $currentHighlightElementPos">
+      <xsl:sequence select="text:highlight(string(.), $ftQueryTerms, $ftQueryHighlightWords, 'false')"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="."/>
+    </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
--- a/software/eXist/webapp/mpdl/presentation/queryHtml.xsl	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/queryHtml.xsl	Mon Aug 29 17:40:19 2011 +0200
@@ -94,29 +94,34 @@
 	  <xsl:for-each select="/result/query/result/hits/hit">
 	    <xsl:variable name="pos" select="pos"/>
 	    <xsl:variable name="term" select="term"/>
+        <xsl:variable name="hitString" select="hitString"/>
 	    <div class="queryResultPageHit">
           <div class="queryResultPageHitLink">
 	        <xsl:value-of select="concat($pos, '.')"/>
+            <xsl:variable name="hitType" select="hitType"/>
 	        <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="hitPos" select="hitPos"/>
+	        <xsl:variable name="hitSurroundsPB" select="hitSurroundsPB"/>
 	        <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="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;sn={$hitPosOfS}&amp;{$modeValue}&amp;highlightQuery={$query}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a>
+              <xsl:when test="$hitType = 's' and $hitSurroundsPB = 'false'">
+	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a>
+	          </xsl:when>
+              <xsl:when test="$hitType = 'head'">
+	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#head{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Head <xsl:value-of select="$hitPos"/></a>
 	          </xsl:when>
 	          <xsl:otherwise>
-	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;sn={$hitPosOfS}&amp;{$modeValue}&amp;highlightQuery={$query}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a> / <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN + 1}&amp;sn=0&amp;{$modeValue}&amp;highlightQuery={$query}#sn0">Page <xsl:value-of select="$hitPN + 1"/>, continuation of the sentence</a>
+	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a> / <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN + 1}&amp;{$modeValue}&amp;highlightQuery={$query}#s0">Page <xsl:value-of select="$hitPN + 1"/>, continuation of the sentence</a>
 	          </xsl:otherwise>
 	        </xsl:choose>
 	        <xsl:value-of select="':'"/>
 	      </div>
           <div class="queryResultPageHitContent">
 	        <!-- Highlight the query terms in each hit sentence and clip the result -->
-	        <xsl:sequence select="text:highlight(s, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/>
+	        <xsl:sequence select="text:highlight($hitString, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/>
 	      </div>
 	    </div>
 	  </xsl:for-each>
--- a/software/eXist/webapp/mpdl/query.xql	Mon Aug 29 17:40:02 2011 +0200
+++ b/software/eXist/webapp/mpdl/query.xql	Mon Aug 29 17:40:19 2011 +0200
@@ -54,10 +54,10 @@
     </colgroup>
     <tr>
     <td align="left" valign="top">
-      <text style="font-weight:bold;font-size:30px">MPDL prototype <a href="info.xql?info=mpdl" onclick="window.open(&quot;info.xql?info=mpdl&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info MPDL"/></a></text>
+      <text style="font-weight:bold;font-size:30px">MPDL prototype <a href="info.xql?info=mpdl" target="_blank"><img src="images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info MPDL"/></a></text>
     </td>
     <td align="left" valign="top">
-      <a href="info.xql?info=malcolm" onclick="window.open(&quot;info.xql?info=malcolm&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false">Dedicated to Dr. Malcolm Hyman</a><br/><text style="margin-left:20px;"></text>† September 4, 2009
+      <a href="info.xql?info=malcolm" target="_blank">Dedicated to Dr. Malcolm Hyman</a><br/><text style="margin-left:20px;"></text>† September 4, 2009
     </td>
     <td align="left" valign="top">
       <a href="http://exist-db.org"><img alt="powered by eXist" align="right" border="0" src="/resources/powered.gif"/></a>
@@ -97,7 +97,7 @@
           <text style="margin-left:1px;"></text><input type="checkbox" name="docbase" value="tei" checked="checked"/>
         </td>
         <td valign="top"><text style="margin-left:40px;"></text><button type="submit" name="browseQuery" onclick="document.getElementById('ietype').value='browse';">Browse</button></td>
-        <td valign="top"><a href="info.xql?info=docBases" onclick="window.open(&quot;info.xql?info=docBases&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info Document bases"/></a></td>
+        <td valign="top"><a href="info.xql?info=docBases" target="_blank"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info Document bases"/></a></td>
       </tr>
       <tr>
       </tr>
@@ -136,7 +136,7 @@
       <td>
       <input type="text" size="40" name="attr-query1" value="{$attrQueryAuthor}" onkeypress="return checkCR(event)"/>
       <button type="submit" name="attributeQuery" onclick="document.getElementById('ietype').value='attribute';">Query</button>
-      <a href="info.xql?info=attr" onclick="window.open(&quot;info.xql?info=attr&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info Attribute search"/></a>
+      <a href="info.xql?info=attr" target="_blank"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info Attribute search"/></a>
       </td>
       </tr>
 
@@ -202,7 +202,7 @@
         <button type="submit" name="fulltextQuery" onclick="document.getElementById('ietype').value='fulltext';">Query</button>
         </td>
         <td>
-        <a href="info.xql?info=fulltext" onclick="window.open(&quot;info.xql?info=fulltext&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info fulltext search"/></a>
+        <a href="info.xql?info=fulltext" target="_blank"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info fulltext search"/></a>
         </td>
         </tr>
       </table>
@@ -229,7 +229,7 @@
         <button type="submit" name="fulltextMorphQuery" onclick="document.getElementById('ietype').value='fulltextMorph';">Query</button>
         </td>
         <td valign="bottom">
-        <a href="info.xql?info=fulltextMorph" onclick="window.open(&quot;info.xql?info=fulltextMorph&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 morphological search"/></a>
+        <a href="info.xql?info=fulltextMorph" target="_blank"><img src="images/info.png" width="15" height="15" border="0" alt="Info morphological search"/></a>
         </td>
         </tr>
         <input type="hidden" name="order-by" value="author"/>
@@ -242,7 +242,7 @@
   <hr/>
   <p/>
   See the <a href="/exist/xquery.xml">eXist XQuery documentation</a> and the <a href="query.xql?_source=yes">XQuery source</a> of this page, if you find a bug <a href="https://itgroup.mpiwg-berlin.mpg.de:8080/tracs/mpdl-project-software/newticket">let us know</a>
-  <br/>Last MPDL software update: March, 2011
+  <br/>Last MPDL software update: August, 2011
 </form>
 </body>
 </html>
\ No newline at end of file
Binary file software/eXist/webapp/mpdl/text/.DS_Store has changed