diff software/eXist/webapp/mpdl/presentation/pageHtml.xsl @ 17:7e883ce72fec

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Sep 2011 16:41:15 +0200
parents e99964f390e4
children
line wrap: on
line diff
--- 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"/>