changeset 17:7e883ce72fec

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Sep 2011 16:41:15 +0200
parents 257f67be5c00
children dc5e9fcb3fdc
files software/eXist/webapp/mpdl/_stuff/.DS_Store software/eXist/webapp/mpdl/_stuff/tmp/.DS_Store software/eXist/webapp/mpdl/attribute-query-result.xql software/eXist/webapp/mpdl/doc/doc-operation-exist.xql software/eXist/webapp/mpdl/info.xql software/eXist/webapp/mpdl/interface/.DS_Store software/eXist/webapp/mpdl/interface/page-fragment.xql software/eXist/webapp/mpdl/lucene/search.xql software/eXist/webapp/mpdl/page-query-result.xql software/eXist/webapp/mpdl/presentation/functions-text.xsl 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/all.xql
diffstat 17 files changed, 439 insertions(+), 221 deletions(-) [+]
line wrap: on
line diff
Binary file software/eXist/webapp/mpdl/_stuff/.DS_Store has changed
Binary file software/eXist/webapp/mpdl/_stuff/tmp/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/attribute-query-result.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/attribute-query-result.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -46,45 +46,80 @@
 let $docBaseArch := "archimedes"
 let $docBaseEcho := "echo"
 let $docBaseTei := "tei"
+let $docBaseDiverse := "diverse"
 let $fulltextMorphArchDocPath := concat($docPathMorph, "/", $docBaseArch, "/", $language)
 let $fulltextMorphEchoDocPath := concat($docPathMorph, "/", $docBaseEcho, "/", $language)
 let $fulltextMorphTeiDocPath := concat($docPathMorph, "/", $docBaseTei, "/", $language)
+let $fulltextMorphDiverseDocPath := concat($docPathMorph, "/", $docBaseDiverse, "/", $language)
 let $fulltextMorphCollection := 
-  if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei))
+  if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphArchDocPath, $fulltextMorphEchoDocPath, $fulltextMorphTeiDocPath, $fulltextMorphDiverseDocPath)
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
   then collection($fulltextMorphArchDocPath, $fulltextMorphEchoDocPath, $fulltextMorphTeiDocPath)
-  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)))
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphArchDocPath, $fulltextMorphEchoDocPath, $fulltextMorphDiverseDocPath)
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphArchDocPath, $fulltextMorphTeiDocPath, $fulltextMorphDiverseDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphEchoDocPath, $fulltextMorphTeiDocPath, $fulltextMorphDiverseDocPath)
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
   then collection($fulltextMorphArchDocPath, $fulltextMorphEchoDocPath)
-  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei))
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphArchDocPath, $fulltextMorphDiverseDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphTeiDocPath, $fulltextMorphDiverseDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphEchoDocPath, $fulltextMorphDiverseDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
+  then collection($fulltextMorphEchoDocPath, $fulltextMorphTeiDocPath)
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
   then collection($fulltextMorphArchDocPath, $fulltextMorphTeiDocPath)
-  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei))
-  then collection($fulltextMorphEchoDocPath, $fulltextMorphTeiDocPath)
-  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)))
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then collection($fulltextMorphDiverseDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
+  then collection($fulltextMorphTeiDocPath)
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
+  then collection($fulltextMorphEchoDocPath)
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
   then collection($fulltextMorphArchDocPath)
-  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)))
-  then collection($fulltextMorphEchoDocPath)
-  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei))
-  then collection($fulltextMorphTeiDocPath)
   else ()
 
 let $fulltextStandardArchDocPath := concat($docPathStandard, "/", $docBaseArch)
 let $fulltextStandardEchoDocPath := concat($docPathStandard, "/", $docBaseEcho)
 let $fulltextStandardTeiDocPath := concat($docPathStandard, "/", $docBaseTei)
+let $fulltextStandardDiverseDocPath := concat($docPathStandard, "/", $docBaseDiverse)
 let $fulltextStandardCollectionStr := 
-  if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei))
+  if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardEchoDocPath, "', '", $fulltextStandardTeiDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
   then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardEchoDocPath, "', '", $fulltextStandardTeiDocPath, "')")
-  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)))
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardEchoDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardTeiDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardEchoDocPath, "', '", $fulltextStandardTeiDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(contains($docbase, $docBaseArch) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
   then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardEchoDocPath, "')")
-  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei))
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardTeiDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardEchoDocPath, "', '", $fulltextStandardDiverseDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
+  then concat("collection('", $fulltextStandardEchoDocPath, "', '", $fulltextStandardTeiDocPath, "')")
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
   then concat("collection('", $fulltextStandardArchDocPath, "', '", $fulltextStandardTeiDocPath, "')")
-  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and contains($docbase, $docBaseTei))
-  then concat("collection('", $fulltextStandardEchoDocPath, "', '", $fulltextStandardTeiDocPath, "')")
-  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)))
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and contains($docbase, $docBaseDiverse))
+  then concat("collection('", $fulltextStandardDiverseDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei) and not(contains($docbase, $docBaseDiverse)))
+  then concat("collection('", $fulltextStandardTeiDocPath, "')")
+  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
+  then concat("collection('", $fulltextStandardEchoDocPath, "')")
+  else if(contains($docbase, $docBaseArch) and not(contains($docbase, $docBaseEcho)) and not(contains($docbase, $docBaseTei)) and not(contains($docbase, $docBaseDiverse)))
   then concat("collection('", $fulltextStandardArchDocPath, "')")
-  else if(not(contains($docbase, $docBaseArch)) and contains($docbase, $docBaseEcho) and not(contains($docbase, $docBaseTei)))
-  then concat("collection('", $fulltextStandardEchoDocPath, "')")
-  else if(not(contains($docbase, $docBaseArch)) and not(contains($docbase, $docBaseEcho)) and contains($docbase, $docBaseTei))
-  then concat("collection('", $fulltextStandardTeiDocPath, "')")
-  else ""
+  else ()
 let $metadataStr := concat("(", $fulltextStandardCollectionStr, "/archimedes/info", "|" , $fulltextStandardCollectionStr, "/echo:echo/echo:metadata", "|" , $fulltextStandardCollectionStr, "/TEI:TEI/TEI:teiHeader", ")")
 let $fulltextStandardCollection := 
   if($fulltextStandardCollectionStr != "")
@@ -172,9 +207,14 @@
   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 $documentCollection := replace(string($documentUriOrig), "(.+)/.+\..*", "$1")
     let $documentUri := substring-after($documentUriOrig, $docPath)
     let $documentUriWithoutExtension := substring-before($documentUri, ".")
+    let $documentExtension := substring-after($documentUri, ".")
+    let $documentUriHtml := 
+      if ($documentExtension = "html")
+      then concat($documentUriWithoutExtension, "-gen.html")
+      else concat($documentUriWithoutExtension, ".html")
     (: 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, "/"), "/")
@@ -200,11 +240,12 @@
         <td align="middle" valign="top" style="padding-left:7px;"><a href="page-query-result.xql?document={$documentUri}&amp;mode={$mode}{$queryUrlPart}"><img src="images/book.png" width="15" height="15" border="0"/></a> </td>
         <td align="middle" valign="top"><a href="getDoc?doc={$documentUri}" target="_blank"><img src="images/download.png" width="15" height="15" border="0" alt="Download"/></a></td>
         <td align="middle" valign="top"><a href="getDoc?doc={$documentUriWithoutExtension}.pdf"><img src="images/download.png" width="15" height="15" border="0" alt="Download"/></a></td>
-        <td align="middle" valign="top"><a href="getDoc?doc={$documentUriWithoutExtension}.html" target="_blank"><img src="images/download.png" width="15" height="15" border="0" alt="Download"/></a></td>
+        <td align="middle" valign="top"><a href="getDoc?doc={$documentUriHtml}" target="_blank"><img src="images/download.png" width="15" height="15" border="0" alt="Download"/></a></td>
         <td valign="top" style="padding-left:5px;"><i>{$authors}</i></td>
         <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;">{$documentName}</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>
@@ -313,6 +354,7 @@
       <col width="35%"/>
       <col width="5%"/>
       <col width="6%"/>
+      <col width="6%"/>
       <col width="3%"/>
       <col width="3%"/>
       <col width="3%"/>
@@ -324,7 +366,7 @@
       </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="{$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;">Orig</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">
@@ -340,6 +382,9 @@
         <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="document" style="padding:0px;font-weight:bold;font-size:14px;background:none;border:none;">Document</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>
--- a/software/eXist/webapp/mpdl/doc/doc-operation-exist.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/doc/doc-operation-exist.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -108,13 +108,16 @@
     -->
   </script>
 
-let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")
+(: let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")  :)
+let $eSciDocCookieId := "test4711"
+let $bla := session:set-attribute("eSciDocCookieId", $eSciDocCookieId)
 
 let $docBaseOptions :=
           <select>
             <option value ="archimedes">Archimedes</option>
             <option value ="echo">Echo</option>
             <option value ="tei">TEI</option>
+            <option value ="diverse">Diverse</option>
           </select>
 let $docBaseOptionsSelected :=
   for $option in $docBaseOptions/option
--- a/software/eXist/webapp/mpdl/info.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/info.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -33,7 +33,7 @@
   else if ($info = 'malcolm')
   then (<h2><img alt="Malcolm Hyman" align="right" src="images/malcolm.jpg" width="30%" height="30%"/>Dr. Malcolm Hyman<br/> † September 4, 2009</h2>, <h3>In memoriam</h3>, 'This software is dedicated to Malcolm Hyman, who was the founder and leader of this project. He died suddenly and unexpectedly. This project owes everything to him.', <h3>His homepages</h3>, <ul><li><a href="http://archimedes.fas.harvard.edu/mdh">Harvard University, Department of the Classics</a></li><li><a href="http://www.mpiwg-berlin.mpg.de/en/staff/members/hyman">Max Planck Institute for the History of Science</a></li><li><a href="http://www.harvardscience.harvard.edu/directory/researchers/malcolm-hyman">HarvardScience</a></li></ul>)
   else if ($info = 'docBases')
-  then (<b>Archimedes DTD (until 2008): </b>, 'more than 120 documents (4KB - 18MB), coming from Echo collections &quot;Archimedes&quot; and &quot;Historical Travel Guides&quot;, languages: latin, italian, english, german, french, dutch, greek, arabic, chinese', <br/>, <br/>, <b>Echo Schema (since 2009): </b>, 'planned more than 100 documents in different languages', <br/>, <br/>, <b>TEI Schema (since 2011): </b>, 'different languages, mainly by external document providers')
+  then (<b>Archimedes DTD (until 2008): </b>, 'more than 120 documents (4KB - 18MB), coming from Echo collections &quot;Archimedes&quot; and &quot;Historical Travel Guides&quot;, languages: latin, italian, english, german, french, dutch, greek, arabic, chinese', <br/>, <br/>, <b>Echo Schema (since 2009): </b>, 'planned more than 100 documents in different languages', <br/>, <br/>, <b>TEI Schema (since 2011): </b>, 'different languages, mainly by external document providers', <br/>, <br/>, <b>Diverse (since 2011): </b>, 'different languages, no schema prerequesites, mainly HTML documents')
   else if ($info = 'attr')
   then ('Attribute search is case sensitive.', <p/>, 'Query syntax see: ', <a href="http://lucene.apache.org/java/2_3_2/queryparsersyntax.html">Lucene query syntax</a>, '.')
   else if ($info = 'fulltextMorph')
Binary file software/eXist/webapp/mpdl/interface/.DS_Store has changed
--- a/software/eXist/webapp/mpdl/interface/page-fragment.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/interface/page-fragment.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -34,7 +34,7 @@
 let $reqExport := request:get-parameter("export", "")
 let $options := string(request:get-parameter("options", ""))
 
-let $presentationPath := "/db/mpdl/presentation"
+let $presentationPath := "/mpdl/presentation"
 (: e.g. mpdlCollectioName is derived from mpdlDocUri: /archimedes/la/yourDoc.xml  :)
 let $documentName := substring-before(substring-after(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/"), ".")
 let $language := substring-before(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/")
@@ -50,7 +50,7 @@
   then $document/echo:echo/echo:metadata
   else if ($docbase = 'tei')
   then $document/TEI:TEI/TEI:teiHeader
-  else ''
+  else ()
 
 let $pageBreaks := 
   if ($docbase = 'archimedes')
@@ -59,7 +59,7 @@
   then $document//echo:pb
   else if ($docbase = 'tei')
   then $document//TEI:pb
-  else $document//pb
+  else $document//*:pb
 let $countPagesTemp := count($pageBreaks)
 let $countPages := 
   if ($countPagesTemp > 0)
@@ -246,12 +246,13 @@
   else false()
 let $returnPageFragmentWithExtObjects :=
   <result>
+    <options>{$options}</options>
     <externalElements>{$externalElements}</externalElements>
     <xpointer>{$xPointer}</xpointer>
     <fragment>{$returnPageFragmentTmp}</fragment>
   </result>
 let $returnPageFragment := 
-  if (contains($options, "withXmlNodeId") or $containsExternalElements or $xPointer != '')
+  if (contains($options, "withXmlNodeId") or contains($options, "withIdentifier") or $containsExternalElements or $xPointer != '')
   then mpdl-text:transform($returnPageFragmentWithExtObjects, concat($presentationPath, "/insertExternalElements.xsl"))
   else $returnPageFragmentTmp
 
@@ -390,12 +391,13 @@
   then <error><number>{$errorCode}</number><description>View mode {$mode} not available</description></error>
   else <error><number>{$errorCode}</number><description>undefined error: {$errorCode}</description></error>  
 
-let $declare := 
+let $outputProperties := 
   if ($errorCode > 9 or $mode = "text" or $mode = "textPollux" or $mode = "gis" or $mode = "image" or $mode = "xml")
-  then util:declare-option("exist:serialize", "method=xhtml media-type=text/html omit-xml-declaration=no indent=no encoding=utf-8")
+  then "method=xhtml media-type=text/html omit-xml-declaration=no indent=no encoding=utf-8"
   else if ($mode = "pureXml")
-  then util:declare-option("exist:serialize", "method=xml media-type=text/xml 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")
+  then "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8"
+  else "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8"
+let $declare := util:declare-option("exist:serialize", $outputProperties)
 let $xslFilePath := 
   if($mode = "text" or $mode = "textPollux" or $mode = "gis" or $mode = "image" or $mode = "xml")
   then concat($presentationPath, "/pageFragmentHtml.xsl")
--- a/software/eXist/webapp/mpdl/lucene/search.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/lucene/search.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -48,7 +48,7 @@
     then $document//echo:s[ft:query(., $query)]|$document//echo:head[ft:query(., $query)]
     else if ($mpdlCollectionName = 'tei')
     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//*: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
@@ -57,6 +57,22 @@
     for $ss at $poss in $t
     where $poss >= $from and $poss <= $to
     return $ss
+  let $docSentences := 
+    if ($mpdlCollectionName = 'archimedes')
+    then $document//s
+    else if ($mpdlCollectionName = 'echo')
+    then $document//echo:s
+    else if ($mpdlCollectionName = 'tei')
+    then $document//TEI:s
+    else $document//*:s
+  let $docHeads := 
+    if ($mpdlCollectionName = 'archimedes')
+    then $document//head
+    else if ($mpdlCollectionName = 'echo')
+    then $document//echo:head
+    else if ($mpdlCollectionName = 'tei')
+    then $document//TEI:head
+    else $document//*:head
   let $queryResult :=
     for $hit at $pos in $tempQueryResult
       let $hitType := local-name($hit)
@@ -68,20 +84,13 @@
         if ($pbPlus1/parent::node() = $hit and $pbPlus1 intersect $hit/descendant::node())
         then true()
         else false()
-      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 $pageHits := 
+        if ($hitType = 's')
+        then $docSentences/.[. >> $pb and . << $pbPlus1]
+        else if ($hitType = 'head')
+        then $docHeads/.[. >> $pb and . << $pbPlus1]
+        else $docSentences/.[. >> $pb and . << $pbPlus1]
+      let $posOfHit := count($pageHits/.[. << $hit]) + 1
       let $position := $from - 1 + $pos
       let $resultElem := 
         <hit>
@@ -188,8 +197,14 @@
      let $documentUri := document-uri($doc)
      let $docBase := functx:substring-after-last(functx:substring-before-last(functx:substring-before-last($documentUri, "/"), "/"), "/")
      let $metadataElem := mpdl-lucene:getMetadata($docBase, $doc)
-     let $attrElemName := mpdl-lucene:getElemNameByAttr($docBase, $orderBy)
-     let $orderByElem := mpdl-lucene:getElemDynamic($metadataElem, $attrElemName)  (: this costs performance for many result elements   :)
+     let $attrElemName := 
+       if ($orderBy = "document")
+       then "document"
+       else mpdl-lucene:getElemNameByAttr($docBase, $orderBy)
+     let $orderByElem := 
+       if ($attrElemName = "document")
+       then util:document-name($doc)
+       else mpdl-lucene:getElemDynamic($metadataElem, $attrElemName)  (: this costs performance for many result elements   :)
      let $orderByTemp := lower-case(string-join($orderByElem, ', '))
   order by $orderByTemp
    return $attrElem)
 
@@ -225,7 +240,7 @@
     then $doc/echo:echo/echo:text
     else if ($docBase = 'tei')
     then $doc/TEI:TEI/TEI:text
-    else ()
+    else $doc/*[1]
   return $result	
 };
 
--- a/software/eXist/webapp/mpdl/page-query-result.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/page-query-result.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -39,7 +39,7 @@
 let $reqExport := request:get-parameter("export", "")
 let $options := string(request:get-parameter("options", ""))
 
-let $presentationPath := "/db/mpdl/presentation"
+let $presentationPath := "/mpdl/presentation"
 (: e.g. mpdlCollectioName is derived from mpdlDocUri: /archimedes/la/yourDoc.xml  :)
 let $documentName := substring-before(substring-after(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/"), ".")
 let $language := substring-before(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/")
@@ -60,7 +60,7 @@
   then $document/echo:echo/echo:metadata
   else if ($docbase = 'tei')
   then $document/TEI:TEI/TEI:teiHeader
-  else ''
+  else ()
 
 let $pageBreaks := 
   if ($docbase = 'archimedes')
@@ -69,7 +69,7 @@
   then $document//echo:pb
   else if ($docbase = 'tei')
   then $document//TEI:pb
-  else $document//pb
+  else $document//*:pb
 let $countPagesTemp := count($pageBreaks)
 let $countPages := 
   if ($countPagesTemp > 0)
@@ -288,12 +288,13 @@
   else false()
 let $returnPageFragmentWithExtObjects :=
   <result>
+    <options>{$options}</options>
     <externalElements>{$externalElements}</externalElements>
     <xpointer>{$xPointer}</xpointer>
     <fragment>{$returnPageFragmentTmp}</fragment>
   </result>
 let $returnPageFragment := 
-  if (contains($options, "withXmlNodeId") or $containsExternalElements or $xPointer != '')
+  if (contains($options, "withXmlNodeId") or contains($options, "withIdentifier") or $containsExternalElements or $xPointer != '')
   then mpdl-text:transform($returnPageFragmentWithExtObjects, concat($presentationPath, "/insertExternalElements.xsl"))
   else $returnPageFragmentTmp
 
@@ -412,12 +413,13 @@
   then <error><number>{$errorCode}</number><description>View mode {$mode} not available</description></error>
   else <error><number>{$errorCode}</number><description>undefined error: {$errorCode}</description></error>  
 
-let $declare := 
+let $outputProperties := 
   if ($errorCode > 9 or $mode = "text" or $mode = "textPollux" or $mode = "gis" or $mode = "image" or $mode = "xml")
-  then util:declare-option("exist:serialize", "method=xhtml media-type=text/html omit-xml-declaration=no indent=no encoding=utf-8")
+  then "method=xhtml media-type=text/html omit-xml-declaration=no indent=no encoding=utf-8"
   else if ($mode = "pureXml")
-  then util:declare-option("exist:serialize", "method=xml media-type=text/xml 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")
+  then "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8"
+  else "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=utf-8"
+let $declare := util:declare-option("exist:serialize", $outputProperties)
 let $xslFilePath := 
   if($reqExport = "pdf")
   then concat($presentationPath, "/pageFragmentHtml.xsl")
@@ -429,8 +431,10 @@
 let $tmpResult :=
   if ($errorCode < 10 and $reqExport = "pdf")
   then mpdl-text:html2pdf($language, $xmlResult, $xslFilePath, $titleStr, $pn, $mode) 
+  else if ($errorCode < 10 and $reqExport = "pureXml")
+  then $xmlResult
   else if ($errorCode < 10 and not($reqExport = "pdf"))
-  then mpdl-text:transform($xmlResult, $xslFilePath) 
+  then mpdl-text:transform($xmlResult, $xslFilePath)
   else 
     <div>{$xmlResult}</div>  (:  error xml result  :)
 let $result :=
--- a/software/eXist/webapp/mpdl/presentation/functions-text.xsl	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/functions-text.xsl	Tue Sep 27 16:41:15 2011 +0200
@@ -7,7 +7,7 @@
  xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
-<xsl:import href="/db/mpdl/presentation/functions-functx.xsl" />
+<xsl:import href="/mpdl/presentation/functions-functx.xsl" />
 
 <!-- delivers a concatenation of n chars of the given char -->   
 <xsl:function name="text:nchars">
--- a/software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl	Tue Sep 27 16:41:15 2011 +0200
@@ -10,6 +10,7 @@
 <xsl:output method="xml" encoding="utf-8"/>
 <xsl:output name="myXml" indent="yes" omit-xml-declaration="yes"/>
 
+<xsl:variable name="options" select="/result/options"/>
 <xsl:variable name="externalElements" select="/result/externalElements"/>
 <xsl:variable name="xpointer" select="/result/xpointer"/>
 <xsl:variable name="xpointerPath">
@@ -71,6 +72,7 @@
 <xsl:template match="fragment">
   <xsl:apply-templates/>
 </xsl:template>
+<xsl:template match="options"></xsl:template>
 <xsl:template match="externalElements"></xsl:template>
 <xsl:template match="xpointer"></xsl:template>
 
@@ -81,6 +83,7 @@
 </xsl:template>
 
 <xsl:template match="element()">
+  <xsl:variable name="identifier" select="@*:id"/>
   <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"/>
@@ -129,13 +132,28 @@
     </xsl:choose>
   </xsl:variable>
   <xsl:variable name="thisElement">
-    <xsl:copy>
-      <xsl:apply-templates select="attribute()"/>
-      <xsl:attribute name="xmlNodeId">
-        <xsl:value-of select="$elemXmlNodeId"/>
-      </xsl:attribute>
-      <xsl:apply-templates select="element()|text()|comment()|processing-instruction()"/>
-    </xsl:copy>
+    <xsl:choose>
+      <xsl:when test="contains($options, 'withIdentifier')">
+        <xsl:copy>
+          <xsl:apply-templates select="attribute()"/>
+          <xsl:if test="not(empty($identifier))">
+            <xsl:attribute name="identifier">
+              <xsl:value-of select="$identifier"/>
+            </xsl:attribute>
+          </xsl:if>
+          <xsl:apply-templates select="element()|text()|comment()|processing-instruction()"/>
+        </xsl:copy>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy>
+          <xsl:apply-templates select="attribute()"/>
+          <xsl:attribute name="xmlNodeId">
+            <xsl:value-of select="$elemXmlNodeId"/>
+          </xsl:attribute>
+          <xsl:apply-templates select="element()|text()|comment()|processing-instruction()"/>
+        </xsl:copy>
+      </xsl:otherwise>
+    </xsl:choose>
   </xsl:variable>
   <xsl:if test="$extElemXPointerPoint = '.0'">
     <xsl:sequence select="$extElemContent"/>
--- a/software/eXist/webapp/mpdl/presentation/pageFragmentHtml.xsl	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageFragmentHtml.xsl	Tue Sep 27 16:41:15 2011 +0200
@@ -15,11 +15,9 @@
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns:xhtml="http://www.w3.org/1999/xhtml">
 
-<xsl:import href="/db/mpdl/presentation/functions-mpdl.xsl" />
-<xsl:import href="/db/mpdl/presentation/functions-text.xsl" />
-<xsl:import href="/db/mpdl/presentation/functions-util.xsl" />
-
-<xsl:strip-space elements="*"/> 
+<xsl:import href="/mpdl/presentation/functions-mpdl.xsl" />
+<xsl:import href="/mpdl/presentation/functions-text.xsl" />
+<xsl:import href="/mpdl/presentation/functions-util.xsl" />
 
 <xsl:output method="xhtml" encoding="utf-8"/>
 
@@ -75,53 +73,57 @@
     <div class="pageContent">
        <xsl:for-each select="content">
          <xsl:variable name="contentStr" select="normalize-space(string(.))"/>
-         <xsl:variable name="figures" select=".//figure|.//handwritten"/>
+         <xsl:variable name="figures" select=".//figure|.//handwritten|.//anchor[@type='figure']"/>
          <xsl:if test="$contentStr = '' and empty($figures)">
            <div class="emptyPage"><xsl:value-of select="'[Empty page]'"/></div>
          </xsl:if>
+         <xsl:variable name="firstContentNodeName" select="./*[1]/name()"/>
          <xsl:choose>
-         <xsl:when test="$mode = 'text' or $mode = 'textPollux' or $mode = 'gis'">
+           <xsl:when test="($mode = 'text' or $mode = 'textPollux' or $mode = 'gis') and $firstContentNodeName = 'html'">
+             <xsl:apply-templates select=".//body" mode="html"/>
+           </xsl:when>
+           <xsl:when test="($mode = 'text' or $mode = 'textPollux' or $mode = 'gis') and $firstContentNodeName != 'html'">
              <xsl:apply-templates mode="text"/>
-         </xsl:when>
-         <xsl:when test="$mode = 'xml'">
+           </xsl:when>
+           <xsl:when test="$mode = 'xml'">
              <xsl:apply-templates mode="xml"/>
-         </xsl:when>
-         <xsl:when test="$mode = 'image'">
-           <xsl:variable name="imageAvailable" select="/result/page/image-available"/>
-           <xsl:variable name="imageFileName" select="/result/page/image-file-name"/>
-           <xsl:variable name="linkImageEcho" select="/result/page/image-echo"/>
-           <xsl:variable name="linkImageScaler" select="/result/page/image-scaler"/>
-           <xsl:variable name="imageHeight" select="600"/>
-           <xsl:choose>
-             <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'true'">
-               <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border: 1px;">
-                 <a href="{$linkImageEcho}"><img alt="Page image: {$linkImageScaler}" src="{$linkImageScaler}&amp;dh={$imageHeight}"/></a>
-               </div>
-             </xsl:when>
-             <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'false'">
-               <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
+           </xsl:when>
+           <xsl:when test="$mode = 'image'">
+             <xsl:variable name="imageAvailable" select="/result/page/image-available"/>
+             <xsl:variable name="imageFileName" select="/result/page/image-file-name"/>
+             <xsl:variable name="linkImageEcho" select="/result/page/image-echo"/>
+             <xsl:variable name="linkImageScaler" select="/result/page/image-scaler"/>
+             <xsl:variable name="imageHeight" select="600"/>
+             <xsl:choose>
+               <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'true'">
+                 <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border: 1px;">
+                   <a href="{$linkImageEcho}"><img alt="Page image: {$linkImageScaler}" src="{$linkImageScaler}&amp;dh={$imageHeight}"/></a>
+                 </div>
+               </xsl:when>
+               <xsl:when test="$digilibAvailable = 'true' and $imageAvailable = 'false'">
+                 <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
+                   <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
+                   Page image: <br/>
+                   <br/>
+                   <xsl:value-of select="$imageFileName"/> , page <xsl:value-of select="$pageNumber"/>
+                   <br/><br/>
+                   not scanned
+                 </div>
+               </xsl:when>
+               <xsl:when test="$digilibAvailable = 'false'">
+                 <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
                  <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
-                 Page image: <br/>
+                 Could not fetch: <br/>
                  <br/>
                  <xsl:value-of select="$imageFileName"/> , page <xsl:value-of select="$pageNumber"/>
                  <br/><br/>
-                 not scanned
-               </div>
-             </xsl:when>
-             <xsl:when test="$digilibAvailable = 'false'">
-               <div style="height:{$imageHeight}px; margin-left:10px; margin-right:10px; border:1px dashed;">
-               <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
-               Could not fetch: <br/>
-               <br/>
-               <xsl:value-of select="$imageFileName"/> , page <xsl:value-of select="$pageNumber"/>
-               <br/><br/>
-               from nausikaa2.rz-berlin.mpg.de: please try again later
-               </div>
-             </xsl:when>
-             <xsl:otherwise></xsl:otherwise>
-           </xsl:choose>
-         </xsl:when>
-         <xsl:otherwise></xsl:otherwise>
+                 from nausikaa2.rz-berlin.mpg.de: please try again later
+                 </div>
+               </xsl:when>
+               <xsl:otherwise></xsl:otherwise>
+             </xsl:choose>
+           </xsl:when>
+           <xsl:otherwise></xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
     </div>
@@ -129,18 +131,28 @@
   </xsl:for-each>
 </xsl:template>
 
-<xsl:template match="attribute()|element()|text()|comment()|processing-instruction()" mode="xml">
+<!-- html mode: transform html texts -->
+<xsl:template match="@*|node()" mode="html">
   <xsl:copy>
-    <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/>
+    <xsl:apply-templates select="@*|node()" mode="html"/>
   </xsl:copy>
 </xsl:template>
 
-<xsl:template match="element()|comment()|processing-instruction()" mode="xml">
+<xsl:template match="s" mode="html">
+  <xsl:apply-templates select="." mode="text"/>
+</xsl:template>
+
+<xsl:template match="w" mode="html">
+  <xsl:apply-templates select="." mode="text"/>
+</xsl:template>
+
+<!-- xml mode: transform to browser like xml display -->
+<xsl:template match="element()" 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()">
+    <xsl:when test="element() = node() or text() != ''">
       <xsl:value-of select="'&lt;'"/>
       <span class="xml elementName"><xsl:value-of select="$elementName"/></span>
       <xsl:apply-templates select="attribute()" mode="xml"/>
@@ -186,7 +198,15 @@
   </span>
   <xsl:value-of select="'=&quot;'"/>
   <span class="xml attributeValue"><xsl:value-of select="."/></span><xsl:value-of select="'&quot;'"/>
-  <xsl:apply-templates select="attribute()" mode="xml"/>
+</xsl:template>
+
+<xsl:template match="comment()" mode="xml">
+  <span class="xml comment">
+    <xsl:value-of select="'&lt;!-- '"/><xsl:value-of select="."/><xsl:value-of select="' --&gt;'"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="processing-instruction()" mode="xml">
 </xsl:template>
 
 <xsl:template match="text()" mode="xml">
@@ -198,12 +218,12 @@
     </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="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: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>
@@ -274,7 +294,16 @@
   </xsl:if>
   <!--   Notes                      -->
   <xsl:variable name="countEmptyPlaces" select="count($notes/note[empty(@place)])"/>
-  <xsl:variable name="countBottomPlaces" select="count($notes/note[contains(@place, 'bottom')])"/>
+  <xsl:variable name="countBottomPlaces">
+    <xsl:choose>
+      <xsl:when test="$collectionName = 'archimedes' or $collectionName = 'tei'">
+        <xsl:value-of select="count($notes/note[contains(@place, 'bottom')])"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="count($notes/note[contains(@position, 'bottom') or empty(string(@position))])"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:if test="($collectionName = 'archimedes' or $collectionName = 'tei') and count($notes/*) > 0">
     <div>
       <xsl:choose>
@@ -318,30 +347,41 @@
   </xsl:if>
   <xsl:if test="$collectionName = 'echo' and count($notes/*) > 0">
     <div>
-      <hr class="notesBottom"/>
+      <xsl:choose>
+        <xsl:when test="$countBottomPlaces > 0 or $countEmptyPlaces > 0">
+          <hr class="notesBottom"/>
+        </xsl:when>
+        <xsl:otherwise></xsl:otherwise>
+      </xsl:choose>
       <xsl:for-each select="$notes/echo:note">
         <xsl:variable name="label" select="string(@xlink:label)"/>
+        <xsl:variable name="place" select="@position"/>
         <xsl:variable name="uid" select="@uid"/>
         <xsl:variable name="modificationDate" select="@modificationDate"/>
         <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace(.)"/>
-        <p>
-          <a>
-            <xsl:attribute name="name"><xsl:value-of select="$label"/></xsl:attribute>
-            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $label, 'ref')"/></xsl:attribute>
-            <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
-            <xsl:value-of select="$label"/>
-          </a>
-          <xsl:value-of select="': '"/>
-          <xsl:choose>
-            <xsl:when test="$uid = '' or empty($uid)">
-              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
-            </xsl:when>
-            <xsl:otherwise>
-              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
-              <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
-            </xsl:otherwise>
-          </xsl:choose>
-        </p>
+        <xsl:choose>
+          <xsl:when test="$place = '' or empty($place) or $place = 'bottom'">
+            <p>
+              <a>
+                <xsl:attribute name="name"><xsl:value-of select="$label"/></xsl:attribute>
+                <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $label, 'ref')"/></xsl:attribute>
+                <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
+                <xsl:value-of select="$label"/>
+              </a>
+              <xsl:value-of select="': '"/>
+              <xsl:choose>
+                <xsl:when test="$uid = '' or empty($uid)">
+                  <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+                </xsl:when>
+                <xsl:otherwise>
+                  <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+                  <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
+                </xsl:otherwise>
+              </xsl:choose>
+            </p>
+          </xsl:when>
+          <xsl:otherwise></xsl:otherwise>
+         </xsl:choose>
       </xsl:for-each>
     </div>
   </xsl:if>
@@ -365,6 +405,7 @@
     <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
       <xsl:apply-templates mode="text"/>
     </span>
   </p>
@@ -640,6 +681,7 @@
     <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:when test="not(empty(@style))"><xsl:value-of select="concat('p ', @style)"/></xsl:when>
       <xsl:otherwise><xsl:value-of select="'p'"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
@@ -664,7 +706,7 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="lb" mode="text">
+<xsl:template match="lb|br" mode="text">
   <xsl:variable name="withoutLBs">
     <xsl:choose>
       <xsl:when test="contains($options, 'withoutLBs')"><xsl:value-of select="'true'"/></xsl:when>
@@ -695,7 +737,12 @@
 
 <xsl:template match="note" mode="text">
   <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
-  <xsl:variable name="place" select="@place"/>
+  <xsl:variable name="place">
+    <xsl:choose>
+      <xsl:when test="$collectionName = 'tei'"><xsl:value-of select="@place"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="@position"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:variable name="notePos" select="count(preceding::note[. >> $topPB]) + 1"/>
   <xsl:variable name="href" select="concat('note-', $pageNumber, '-', $notePos)"/>
   <xsl:choose>
@@ -707,12 +754,19 @@
         <xsl:value-of select="$href"/>
       </a>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and not($hasLabel) and not(empty($place))">
+      <span>    
+        <xsl:attribute name="class"><xsl:value-of select="concat('note margin ', $place)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
     <xsl:when test="$collectionName = 'echo' and not($hasLabel)">
       <p>
         <xsl:value-of select="'[Note]: '"/>
         <span class="note"><xsl:apply-templates mode="text"/></span>
       </p>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and $hasLabel"></xsl:when>
     <xsl:when test="$collectionName = 'tei'">
       <xsl:choose>
         <xsl:when test="contains($place, 'margin')">
@@ -957,12 +1011,25 @@
       <xsl:sequence select="mpdl-util:copyWithoutNamespace($table)"/>
     </xsl:when>
     <xsl:when test="$type = 'note'">
-      <a>
-        <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
-        <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
-        <xsl:attribute name="class"><xsl:value-of select="'noteRef super'"/></xsl:attribute>
-        <xsl:value-of select="$href"/>
-      </a>
+      <xsl:variable name="note" select="$notes/echo:note[@xlink:label = $href]"/>
+      <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace($note)"/>
+      <xsl:variable name="place" select="$note/@position"/>
+      <xsl:choose>
+        <xsl:when test="not(empty($place))">
+          <span>    
+            <xsl:attribute name="class"><xsl:value-of select="concat('note margin ', $place)"/></xsl:attribute>
+            <xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/>
+          </span>
+        </xsl:when>
+        <xsl:otherwise>
+          <a>
+            <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
+            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
+            <xsl:attribute name="class"><xsl:value-of select="'noteRef super'"/></xsl:attribute>
+            <xsl:value-of select="$href"/>
+          </a>
+        </xsl:otherwise>
+      </xsl:choose>
     </xsl:when>
     <xsl:otherwise><a><xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute><xsl:apply-templates mode="text"/></a></xsl:otherwise>
   </xsl:choose>
@@ -1171,6 +1238,7 @@
     <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
             <xsl:apply-templates mode="text"/>
@@ -1184,6 +1252,7 @@
     <xsl:otherwise>
       <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
             <xsl:apply-templates mode="text"/>
@@ -1207,12 +1276,12 @@
     </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="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: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>
--- a/software/eXist/webapp/mpdl/presentation/pageHtml.css	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageHtml.css	Tue Sep 27 16:41:15 2011 +0200
@@ -23,6 +23,7 @@
 span.xml.elementName { font-weight:bold;color:purple; }
 span.xml.attributeName { font-weight:bold; }
 span.xml.attributeValue { color:blue; }
+span.xml.comment { color:green; font-style:italic; }
 ul.xml.element { margin-left:0px;padding-left:8px }
 ul.xml.element.highlight { background-color:#D3D3D3; }      /* LightGrey    */
 
@@ -105,8 +106,8 @@
 
 /* notes     */
 span.note { font-style:italic; }
-span.note.margin.left { position:absolute; left:2em; font-style:normal; }
-span.note.margin.right { position:absolute; left:30em; font-style:normal; } 
+span.note.margin.left { position:absolute; left:2em; width: 5em; font-style:normal; }
+span.note.margin.right { position:absolute; left:30em; width: 5em; font-style:normal; } 
 
 /* GIS elements    */
 span.place { color:#0000FF; }  /* Blue   */
--- a/software/eXist/webapp/mpdl/presentation/pageHtml.xsl	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/pageHtml.xsl	Tue Sep 27 16:41:15 2011 +0200
@@ -15,14 +15,14 @@
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns:xhtml="http://www.w3.org/1999/xhtml">
 
-<xsl:import href="/db/mpdl/presentation/functions-mpdl.xsl" />
-<xsl:import href="/db/mpdl/presentation/functions-text.xsl" />
-<xsl:import href="/db/mpdl/presentation/functions-util.xsl" />
-
-<xsl:strip-space elements="*"/> 
+<xsl:import href="/mpdl/presentation/functions-mpdl.xsl" />
+<xsl:import href="/mpdl/presentation/functions-text.xsl" />
+<xsl:import href="/mpdl/presentation/functions-util.xsl" />
 
 <xsl:output method="xhtml" encoding="utf-8"/>
 
+<xsl:variable name="documentUri" select="/result/document-description/uri"/>
+<xsl:variable name="documentName" select="/result/document-description/document-name"/>
 <xsl:variable name="errorMessage" select="string(/result/query/result/error)"/>
 <xsl:variable name="mode" select="/result/page/mode"/>
 <xsl:variable name="queryType" select="/result/query/type"/>
@@ -72,10 +72,10 @@
   <xsl:variable name="place" select="string-join(/result/document-description/places/place, ', ')"/>
   <xsl:variable name="date" select="/result/document-description/date"/>
   <xsl:variable name="bookTitle">
-    <xsl:value-of select="$author"/>.
-    <xsl:value-of select="$title"/>.
-    <xsl:value-of select="$place"/><xsl:if test="$place != ''">, </xsl:if>
-    <xsl:value-of select="$date"/>.
+    <xsl:if test="$author != ''"><xsl:value-of select="$author"/>.</xsl:if>
+    <xsl:if test="$title != ''"><xsl:value-of select="$title"/>.</xsl:if>
+    <xsl:if test="$place != ''"><xsl:value-of select="$place"/>, </xsl:if>
+    <xsl:if test="$date != ''"><xsl:value-of select="$date"/>.</xsl:if>
   </xsl:variable>
   <html>
   <head>
@@ -83,11 +83,9 @@
     <link rel="stylesheet" type="text/css" href="presentation/pageHtml.css"/>
   </head>
   <body>
-    <text style="font-weight:bold;font-size:20px"><xsl:value-of select="$bookTitle"/></text>
+    <text style="font-weight:bold;font-size:20px"><xsl:value-of select="$bookTitle"/><xsl:if test="$bookTitle = ''"><xsl:value-of select="$documentUri"/></xsl:if></text>
     <p/>
     <xsl:for-each select="page">
-      <xsl:variable name="documentUri" select="/result/document-description/uri"/>
-      <xsl:variable name="documentName" select="/result/document-description/document-name"/>
       <xsl:variable name="countPages" select="/result/document-description/count-pages"/>
       <xsl:variable name="pageHeader" select="header"/>
       <xsl:variable name="pageNumber" select="number(number)"/>
@@ -241,7 +239,7 @@
                     </tr>
                   </table>
                 </xsl:if>
-                <table>
+                <table style="margin-left:80px">
                 <colgroup>
                   <col width="90%"/>
                   <col width="10%"/>
@@ -249,11 +247,15 @@
                 <tr>
                 <td>
                   <xsl:variable name="contentStr" select="normalize-space(string(.))"/>
-                  <xsl:variable name="figures" select=".//figure|.//handwritten"/>
+                  <xsl:variable name="figures" select=".//figure|.//handwritten|.//anchor[@type='figure']"/>
                   <xsl:if test="$contentStr = '' and empty($figures)">
                     <div class="emptyPage"><xsl:value-of select="'[Empty page]'"/></div>
                   </xsl:if>
-                  <xsl:apply-templates mode="text"/>
+                  <xsl:variable name="firstContentNodeName" select="./*[1]/name()"/>
+                  <xsl:choose>
+                    <xsl:when test="$firstContentNodeName = 'html'"><xsl:apply-templates select=".//body" mode="html"/></xsl:when>
+                    <xsl:otherwise><xsl:apply-templates mode="text"/></xsl:otherwise>
+                  </xsl:choose>
                 </td>
                 <td align="middle" valign="top"><p><a href="?{$documentValue}&amp;mode={$mode}&amp;pn={$pageNumber}&amp;sn={$sn}&amp;export=pdf&amp;options={$options}"><img src="images/download.png" width="24" height="24" border="0" alt="Download"/></a><br/>Download PDF</p></td>
                 </tr>
@@ -578,20 +580,6 @@
                   <xsl:when test="$language = 'zh'">
                     <xsl:variable name="termBig5Encoded" select="/result/query/result/big5-hits/entry-big5-encoded/term[$pos]"/>
                     <a href="http://humanum.arts.cuhk.edu.hk/cgi-bin/agrep-lindict?query={$termBig5Encoded}&amp;category=wholerecord">Lin Yutang</a>
-                    <!-- TODO: replace Java based function by XSL-function like the following, but that does not work yet cause termHexBin is not the same than by Java) also in query.xsl and functions-text.xsl -->
-                    <xsl:variable name="termHexBin"><xsl:value-of select="saxon:string-to-hexBinary($term, 'utf8')"/></xsl:variable>
-                    <xsl:variable name="termHexBinStr" select="string($termHexBin)"/>
-                    <xsl:variable name="termBig5EncodedNew">
-                      <xsl:for-each select="string-to-codepoints($termHexBinStr)">
-                        <xsl:variable name="pos" select="position()"/>
-                        <xsl:variable name="posIDiv" select="$pos idiv 2"/>
-                        <xsl:variable name="posPlus1IDiv" select="($pos + 1) idiv 2"/>
-                        <xsl:if test="$posIDiv != $posPlus1IDiv">
-                          <xsl:variable name="charStr" select="substring($termHexBinStr, $pos, 2)"/>
-                          <xsl:value-of select="encode-for-uri(concat('%', $charStr))"/>
-                        </xsl:if>
-                      </xsl:for-each>
-                    </xsl:variable>
                   </xsl:when>
                   <xsl:otherwise><a href="http://archimedes.mpiwg-berlin.mpg.de/cgi-bin/toc/dict?step=table;word={$term};lang={$language};pro=echo">Echo</a></xsl:otherwise>
                   </xsl:choose>
@@ -660,18 +648,28 @@
   </body></html>
 </xsl:template>
 
-<xsl:template match="attribute()|element()|text()|comment()|processing-instruction()" mode="xml">
+<!-- html mode: transform html texts -->
+<xsl:template match="@*|node()" mode="html">
   <xsl:copy>
-    <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/>
+    <xsl:apply-templates select="@*|node()" mode="html"/>
   </xsl:copy>
 </xsl:template>
 
-<xsl:template match="element()|comment()|processing-instruction()" mode="xml">
+<xsl:template match="s" mode="html">
+  <xsl:apply-templates select="." mode="text"/>
+</xsl:template>
+
+<xsl:template match="w" mode="html">
+  <xsl:apply-templates select="." mode="text"/>
+</xsl:template>
+
+<!-- xml mode: transform to browser like xml display -->
+<xsl:template match="element()" 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()">
+    <xsl:when test="element() = node() or text() != ''">
       <xsl:value-of select="'&lt;'"/>
       <span class="xml elementName"><xsl:value-of select="$elementName"/></span>
       <xsl:apply-templates select="attribute()" mode="xml"/>
@@ -717,7 +715,15 @@
   </span>
   <xsl:value-of select="'=&quot;'"/>
   <span class="xml attributeValue"><xsl:value-of select="."/></span><xsl:value-of select="'&quot;'"/>
-  <xsl:apply-templates select="attribute()" mode="xml"/>
+</xsl:template>
+
+<xsl:template match="comment()" mode="xml">
+  <span class="xml comment">
+    <xsl:value-of select="'&lt;!-- '"/><xsl:value-of select="."/><xsl:value-of select="' --&gt;'"/>
+  </span>
+</xsl:template>
+
+<xsl:template match="processing-instruction()" mode="xml">
 </xsl:template>
 
 <!-- If ft-query is set then highlight all term occurrences in each little text piece for the fulltext query -->
@@ -751,8 +757,6 @@
 
 <!-- variables used by templates in mode "text" -->
 <xsl:variable name="collectionName" select="/result/document-description/collection-name"/>
-<xsl:variable name="documentUri" select="/result/document-description/uri"/>
-<xsl:variable name="documentName" select="/result/document-description/document-name"/>
 <xsl:variable name="documentIdentifier" select="/result/document-description/identifier"/>
 <xsl:variable name="pageNumber" select="/result/page/number"/>
 <xsl:variable name="firstFigurePosition" select="/result/page/firstFigurePosition"/>
@@ -763,6 +767,7 @@
 <xsl:variable name="notes" select="/result/page/notes"/>
 <xsl:variable name="charNorm" select="/result/page/character-normalization"/>
 
+<!-- text mode: transform to text or textPollux display -->
 <xsl:template match="text" mode="text">
   <xsl:apply-templates mode="text"/>
   <!--   TEI Dictionary                      -->
@@ -807,7 +812,16 @@
   </xsl:if>
   <!--   Notes                      -->
   <xsl:variable name="countEmptyPlaces" select="count($notes/note[empty(@place)])"/>
-  <xsl:variable name="countBottomPlaces" select="count($notes/note[contains(@place, 'bottom')])"/>
+  <xsl:variable name="countBottomPlaces">
+    <xsl:choose>
+      <xsl:when test="$collectionName = 'archimedes' or $collectionName = 'tei'">
+        <xsl:value-of select="count($notes/note[contains(@place, 'bottom')])"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="count($notes/note[contains(@position, 'bottom') or empty(string(@position))])"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:if test="($collectionName = 'archimedes' or $collectionName = 'tei') and count($notes/*) > 0">
     <div>
       <xsl:choose>
@@ -851,30 +865,41 @@
   </xsl:if>
   <xsl:if test="$collectionName = 'echo' and count($notes/*) > 0">
     <div>
-      <hr class="notesBottom"/>
+      <xsl:choose>
+        <xsl:when test="$countBottomPlaces > 0 or $countEmptyPlaces > 0">
+          <hr class="notesBottom"/>
+        </xsl:when>
+        <xsl:otherwise></xsl:otherwise>
+      </xsl:choose>
       <xsl:for-each select="$notes/echo:note">
         <xsl:variable name="label" select="string(@xlink:label)"/>
+        <xsl:variable name="place" select="@position"/>
         <xsl:variable name="uid" select="@uid"/>
         <xsl:variable name="modificationDate" select="@modificationDate"/>
         <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace(.)"/>
-        <p>
-          <a>
-            <xsl:attribute name="name"><xsl:value-of select="$label"/></xsl:attribute>
-            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $label, 'ref')"/></xsl:attribute>
-            <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
-            <xsl:value-of select="$label"/>
-          </a>
-          <xsl:value-of select="': '"/>
-          <xsl:choose>
-            <xsl:when test="$uid = '' or empty($uid)">
-              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
-            </xsl:when>
-            <xsl:otherwise>
-              <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
-              <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
-            </xsl:otherwise>
-          </xsl:choose>
-        </p>
+        <xsl:choose>
+          <xsl:when test="$place = '' or empty($place) or $place = 'bottom'">
+            <p>
+              <a>
+                <xsl:attribute name="name"><xsl:value-of select="$label"/></xsl:attribute>
+                <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $label, 'ref')"/></xsl:attribute>
+                <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
+                <xsl:value-of select="$label"/>
+              </a>
+              <xsl:value-of select="': '"/>
+              <xsl:choose>
+                <xsl:when test="$uid = '' or empty($uid)">
+                  <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+                </xsl:when>
+                <xsl:otherwise>
+                  <span class="note"><xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/></span>
+                  <xsl:value-of select="concat(' [external note, ', $uid, ', ', $modificationDate, ']')"/>
+                </xsl:otherwise>
+              </xsl:choose>
+            </p>
+          </xsl:when>
+          <xsl:otherwise></xsl:otherwise>
+        </xsl:choose>
       </xsl:for-each>
     </div>
   </xsl:if>
@@ -898,6 +923,7 @@
     <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
       <xsl:apply-templates mode="text"/>
     </span>
   </p>
@@ -1173,6 +1199,7 @@
     <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:when test="not(empty(@style))"><xsl:value-of select="concat('p ', @style)"/></xsl:when>
       <xsl:otherwise><xsl:value-of select="'p'"/></xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
@@ -1197,7 +1224,7 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="lb" mode="text">
+<xsl:template match="lb|br" mode="text">
   <xsl:variable name="withoutLBs">
     <xsl:choose>
       <xsl:when test="contains($options, 'withoutLBs')"><xsl:value-of select="'true'"/></xsl:when>
@@ -1228,7 +1255,12 @@
 
 <xsl:template match="note" mode="text">
   <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
-  <xsl:variable name="place" select="@place"/>
+  <xsl:variable name="place">
+    <xsl:choose>
+      <xsl:when test="$collectionName = 'tei'"><xsl:value-of select="@place"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="@position"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:variable name="notePos" select="count(preceding::note[. >> $topPB]) + 1"/>
   <xsl:variable name="href" select="concat('note-', $pageNumber, '-', $notePos)"/>
   <xsl:choose>
@@ -1240,12 +1272,19 @@
         <xsl:value-of select="$href"/>
       </a>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and not($hasLabel) and not(empty($place))">
+      <span>    
+        <xsl:attribute name="class"><xsl:value-of select="concat('note margin ', $place)"/></xsl:attribute>
+        <xsl:apply-templates mode="text"/>
+      </span>
+    </xsl:when>
     <xsl:when test="$collectionName = 'echo' and not($hasLabel)">
       <p>
         <xsl:value-of select="'[Note]: '"/>
         <span class="note"><xsl:apply-templates mode="text"/></span>
       </p>
     </xsl:when>
+    <xsl:when test="$collectionName = 'echo' and $hasLabel"></xsl:when>
     <xsl:when test="$collectionName = 'tei'">
       <xsl:choose>
         <xsl:when test="contains($place, 'margin')">
@@ -1490,12 +1529,25 @@
       <xsl:sequence select="mpdl-util:copyWithoutNamespace($table)"/>
     </xsl:when>
     <xsl:when test="$type = 'note'">
-      <a>
-        <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
-        <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
-        <xsl:attribute name="class"><xsl:value-of select="'noteRef super'"/></xsl:attribute>
-        <xsl:value-of select="$href"/>
-      </a>
+      <xsl:variable name="note" select="$notes/echo:note[@xlink:label = $href]"/>
+      <xsl:variable name="noteWithoutNamespace" select="mpdl-util:copyWithoutNamespace($note)"/>
+      <xsl:variable name="place" select="$note/@position"/>
+      <xsl:choose>
+        <xsl:when test="not(empty($place))">
+          <span>    
+            <xsl:attribute name="class"><xsl:value-of select="concat('note margin ', $place)"/></xsl:attribute>
+            <xsl:apply-templates select="$noteWithoutNamespace/node()" mode="text"/>
+          </span>
+        </xsl:when>
+        <xsl:otherwise>
+          <a>
+            <xsl:attribute name="name"><xsl:value-of select="concat($href, 'ref')"/></xsl:attribute>
+            <xsl:attribute name="href"><xsl:value-of select="concat(urlBase, '#', $href)"/></xsl:attribute>
+            <xsl:attribute name="class"><xsl:value-of select="'noteRef super'"/></xsl:attribute>
+            <xsl:value-of select="$href"/>
+          </a>
+        </xsl:otherwise>
+      </xsl:choose>
     </xsl:when>
     <xsl:otherwise><a><xsl:attribute name="href"><xsl:value-of select="$href"/></xsl:attribute><xsl:apply-templates mode="text"/></a></xsl:otherwise>
   </xsl:choose>
@@ -1702,6 +1754,7 @@
     <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
             <xsl:apply-templates mode="text"/>
@@ -1715,6 +1768,7 @@
     <xsl:otherwise>
       <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:if test="not(empty(@identifier))"><xsl:attribute name="identifier"><xsl:value-of select="@identifier"/></xsl:attribute></xsl:if>
         <xsl:choose>
           <xsl:when test="empty(@style)">
             <xsl:apply-templates mode="text"/>
--- a/software/eXist/webapp/mpdl/presentation/queryHtml.xsl	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/presentation/queryHtml.xsl	Tue Sep 27 16:41:15 2011 +0200
@@ -12,8 +12,8 @@
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:functx="http://www.functx.com">
 
-<xsl:import href="/db/mpdl/presentation/functions-functx.xsl"/>
-<xsl:import href="/db/mpdl/presentation/functions-text.xsl"/>
+<xsl:import href="/mpdl/presentation/functions-functx.xsl"/>
+<xsl:import href="/mpdl/presentation/functions-text.xsl"/>
 
 <xsl:output method="html" encoding="utf-8"/>
 
--- a/software/eXist/webapp/mpdl/query.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/query.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -96,6 +96,13 @@
         <td valign="top">
           <text style="margin-left:1px;"></text><input type="checkbox" name="docbase" value="tei" checked="checked"/>
         </td>
+        <td>
+          <text style="margin-left:20px;">Diverse</text><br/>
+          <text style="margin-left:20px;">(since 2011)</text>
+        </td>
+        <td valign="top">
+          <text style="margin-left:1px;"></text><input type="checkbox" name="docbase" value="diverse" 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" target="_blank"><img src="images/info.png" valign="bottom" width="15" height="15" border="0" alt="Info Document bases"/></a></td>
       </tr>
@@ -242,7 +249,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: August, 2011
+  <br/>Last MPDL software update: September, 2011
 </form>
 </body>
 </html>
\ No newline at end of file
--- a/software/eXist/webapp/mpdl/text/all.xql	Tue Sep 27 16:40:57 2011 +0200
+++ b/software/eXist/webapp/mpdl/text/all.xql	Tue Sep 27 16:41:15 2011 +0200
@@ -45,7 +45,7 @@
     then $document/echo:echo/echo:text 
     else if ($mpdlCollectionName = 'tei') 
     then $document/TEI:TEI/TEI:text 
-    else $document/archimedes/text
+    else $document/*[1]
   let $from := ($pn * $pageSize) - $pageSize + 1
   let $to := $pn * $pageSize
   let $maxTo := 10000
@@ -218,7 +218,7 @@
     then $document/echo:echo/echo:metadata
     else if ($docbase = 'tei')
     then $document/TEI:TEI/TEI:teiHeader
-    else ''
+    else ()
   let $documentIdentifier :=
     if ($docbase = 'archimedes')
     then $metadata/locator