view software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/page.xsl @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children
line wrap: on
line source

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:functx="http://www.functx.com"
 xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text">

<xsl:output method="html" encoding="utf-8"/>

<!-- see http://www.xsltfunctions.com     -->
<xsl:function name="functx:contains-any-of" as="xs:boolean">
  <xsl:param name="arg" as="xs:string?"/> 
  <xsl:param name="searchStrings" as="xs:string*"/> 
  <xsl:sequence select="some $searchString in $searchStrings satisfies contains($arg, $searchString)"/>
</xsl:function>

 <xsl:function name="text:nchars">
   <xsl:param name="count" as="xs:integer"/>
   <xsl:param name="char" as="xs:string"/>
   <xsl:sequence select="if ($count > 0) then concat($char, text:nchars($count - 1, $char)) else $char"/>
 </xsl:function>
  
 <xsl:function name="text:cutStringBefore">
  <xsl:param name="inputString" as="xs:string"/>
  <xsl:param name="cutLength" as="xs:integer"/>
  <xsl:variable name="length" select="string-length($inputString)"/>  
  <xsl:if test="$length &gt; $cutLength"> (...)</xsl:if>
  <xsl:value-of select="substring($inputString, $length - $cutLength)"/>  
</xsl:function>

<xsl:function name="text:cutStringAfter">
  <xsl:param name="inputString" as="xs:string"/>
  <xsl:param name="cutLength" as="xs:integer"/>
  <xsl:variable name="length" select="string-length($inputString)"/>  
  <xsl:value-of select="substring($inputString, 0, $cutLength)"/>  
  <xsl:if test="$length &gt; $cutLength">(...) </xsl:if>
</xsl:function>


<!-- Highlight all term occurrences for the Lucene query. 
Result is a sequence of text and highlighted nodes (with span):
Example: LE<span ...>MECHANICHE</span>...<span ...>Mechaniche</span>... 
-->
<xsl:function name="text:highlight">
  <xsl:param name="inputStr" as="xs:string" />
  <xsl:param name="luceneQuery" as="xs:string" />
  <xsl:param name="clipped" as="xs:string" />
  <xsl:variable name="terms" select="text:translateLuceneToTerms($luceneQuery)" as="xs:string*"/>
  <xsl:sequence select="text:highlightTerms($inputStr, $terms, $clipped)" />
</xsl:function>


<!-- Translation of Lucene query to a sequence of terms  -->  
<xsl:function name="text:translateLuceneToTerms">
  <xsl:param name="luceneQuery" as="xs:string" />
  <!-- Escape special chars; Lucene special chars are not handled here: *?-+  -->
  <xsl:variable name="luceneQueryEscaped" select="replace($luceneQuery, '[.^${}()|\[\]\\]', '\\$0')" /> 
  <xsl:variable name="luceneQueryWithoutSpaces" select="normalize-space($luceneQueryEscaped)" />
  <xsl:choose>
    <!-- phrase  -->
    <xsl:when test="matches($luceneQueryEscaped, concat('&quot;', '.*', '&quot;'))">
      <xsl:variable name="queryWithoutQuotes" select="substring-before(substring-after($luceneQueryEscaped, '&quot;'), '&quot;')"/>
      <xsl:variable name="escapeLuceneChars" select="replace($queryWithoutQuotes, '[*+?]', '\\$0')"/>
      <xsl:sequence select="$escapeLuceneChars"/>
    </xsl:when>
    <!-- single word without star and without quotations -->
    <xsl:when test="matches($luceneQueryEscaped, concat('^[^', '&quot;' , '*]*$'))">
      <xsl:sequence select="$luceneQueryEscaped"/>
    </xsl:when>
    <!-- single word with star and without quotations -->
    <xsl:when test="matches($luceneQueryEscaped, concat('^[^', '&quot;' , ']*\*$'))">
      <xsl:sequence select="substring-before($luceneQueryEscaped, '*')"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:sequence select="''"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>

<xsl:function name="text:translateLuceneToTermsOld">
  <xsl:param name="luceneQuery" as="xs:string" />
  <xsl:variable name="luceneQueryEscaped" select="replace($luceneQuery, '[.^${}()|\[\]\\]', '\\$0')" /> <!-- without *?-+  -->
  <xsl:variable name="luceneQueryWithoutSpaces" select="normalize-space($luceneQueryEscaped)" />
  <xsl:choose>
    <!-- phrase  -->
    <xsl:when test="matches($luceneQueryEscaped, concat('&quot;', '.*', '&quot;'))">
      <xsl:variable name="queryWithoutQuotes" select="substring-before(substring-after($luceneQueryEscaped, '&quot;'), '&quot;')"/>
      <xsl:variable name="escapeLuceneChars" select="replace($queryWithoutQuotes, '[*+?]', '\\$0')"/>
      <xsl:value-of select="$escapeLuceneChars"/>
    </xsl:when>
    <!-- single word without star and without quotations -->
    <xsl:when test="matches($luceneQueryEscaped, concat('^[^', '&quot;' , '*]*$'))">
      <xsl:value-of select="$luceneQueryEscaped"/>
    </xsl:when>
    <!-- single word with star and without quotations -->
    <xsl:when test="matches($luceneQueryEscaped, concat('^[^', '&quot;' , ']*\*$'))">
      <xsl:value-of select="substring-before($luceneQueryEscaped, '*')"/>
    </xsl:when>
    <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
  </xsl:choose>
</xsl:function>

<xsl:function name="text:highlightTerms">
  <xsl:param name="inputStr" as="xs:string" />
  <xsl:param name="terms" as="xs:string*" />
  <xsl:param name="clipped" as="xs:string" />
  <xsl:variable name="term" select="$terms[1]"/>
  <xsl:variable name="inputString" select="replace($inputStr, '\n', '')"/>
  <!-- Word delimiter: not tested yet -->
  <xsl:variable name="wordDelimRegExpr" select="'[\s\(\)\[\]\.\\\{\}\$\^\+\?\!\* ยง%:,;=/]+'"/>   <!-- TODO: bol, eol, ", &, <, >    --> 
  <!-- Recognizes the beginning of the line with ^ and the substring up to the query term -->
  <xsl:variable name="queryRegExprSubstringBefore">
    <xsl:value-of select="concat('^.*?', $term)"/>
  </xsl:variable>
  <!-- Recognizes the substring after the query term -->
  <xsl:variable name="queryRegExprSubstringAfter">
    <xsl:value-of select="concat($term, '.*')"/>
  </xsl:variable>
  <!-- Recognizes the query term -->
  <xsl:variable name="matchQueryTermRegExpr">
    <xsl:value-of select="concat('^.*?', '(', $term, ')', '.*')"/>
  </xsl:variable>
  <!-- Deletes the substring up to the query term -->
  <xsl:variable name="substringBefore" select="replace($inputString, $queryRegExprSubstringAfter, '$1', 'im')"/>
  <!-- Deletes the substring after the query term -->
  <xsl:variable name="substringAfter" select="replace($inputString, $queryRegExprSubstringBefore, '$1', 'im')"/>
  <xsl:choose>
    <xsl:when test="matches($inputString, $matchQueryTermRegExpr, 'im')">
      <!-- Prints the original part of the substring up to the first occurrence of the query term -->
      <xsl:choose>
      <xsl:when test="$clipped='true'">
        <xsl:value-of select="text:cutStringBefore($substringBefore, 70)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$substringBefore"/>
      </xsl:otherwise>
      </xsl:choose>
      <!-- Highlight the query term -->
      <xsl:variable name="matchQueryTerm" select="replace($inputString, $matchQueryTermRegExpr, '$1', 'im')"/>
      <span style="background-color: #77DD77;"><!-- pastell green  -->
        <xsl:value-of select="$matchQueryTerm"/>
      </span>
      <!-- Recursive call of this function with the substring after the first occurrence of the term: further occurrences of the query 
      term  -->
      <xsl:sequence select="text:highlight($substringAfter, $terms, $clipped)"/>
    </xsl:when>
    <!-- if no occurrence of the query term could be found the whole string is printed -->
    <xsl:otherwise>
      <xsl:choose>
      <xsl:when test="$clipped='true'">
        <xsl:value-of select="text:cutStringAfter($inputString, 70)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$inputString"/>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>








<xsl:variable name="mode" select="/result/mode"/>
<xsl:variable name="language" select="/result/document-description/info/lang"/>
<xsl:variable name="ftQueryName" select="/result/ft-query/name"/>
<xsl:variable name="ftQueryStr" select="concat('&amp;', 'ft-query=', $ftQueryName)"/>
<xsl:variable name="ftQueryMode">
  <xsl:choose>
  <xsl:when test="matches($ftQueryName, concat('&quot;', '.*', '&quot;'))">
    <xsl:value-of select="'phrase'"/>
  </xsl:when>
  <xsl:when test="string-length($ftQueryName) = 0">
    <xsl:value-of select="'false'"/>
  </xsl:when>
  <!-- Because there are  problems in recognizing words (in mode word) this fake mode is used (same as phrase mode)  -->
  <xsl:otherwise><xsl:value-of select="'fakeWord'"/></xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:variable name="ftQueryValue">
  <xsl:choose>
  <xsl:when test="/result/ft-query[node()]"><xsl:value-of select="$ftQueryStr"/></xsl:when>
  <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:variable name="indexTermsStartStr" select="/result/index-terms/start-string"/>
<xsl:variable name="indexTermsPN" select="/result/index-terms/pn"/>

<xsl:template match="result">
  <html><body>
    <xsl:for-each select="document-description">
      <h2>
      <xsl:for-each select="info">
        <xsl:value-of select="author"/>.
        <xsl:value-of select="title"/>.
        <xsl:value-of select="place"/>, 
        <xsl:value-of select="date"/>
      </xsl:for-each>
      </h2>
    </xsl:for-each>
    <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="number" select="number(number)"/>
      <xsl:variable name="documentValue" select="concat('document=', $documentUri)"/>
      <xsl:variable name="pnValue" select="concat('pn=', $number)"/>
      <xsl:variable name="modeValue" select="concat('mode=', $mode)"/>
      <table width="100%">
        <colgroup>
          <col width="30%"/>
          <col width="60%"/>
          <col width="2%"/>
          <col width="2%"/>
        </colgroup>
        <tr>
        <td align="left" nowrap="true">
          <form action="page-query-result.xql" method="get">
          <input type="hidden" name="document" value="{$documentUri}"/>
          <xsl:choose>
          <xsl:when test="$mode = 'text'"><input type="image" src="images/text.jpg" name="mode" value="text"/></xsl:when>
          <xsl:otherwise><input type="image" src="images/textU.jpg" name="mode" value="text"/></xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
          <xsl:when test="$mode = 'image'"><input type="image" src="images/image.jpg" name="mode" value="image"/></xsl:when>
          <xsl:otherwise><input type="image" src="images/imageU.jpg" name="mode" value="image"/></xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
          <xsl:when test="$mode = 'xml'"><input type="image" src="images/xml.jpg" name="mode" value="xml"/></xsl:when>
          <xsl:otherwise><input type="image" src="images/xmlU.jpg" name="mode" value="xml"/></xsl:otherwise>
          </xsl:choose>
          <input type="hidden" name="pn" value="{$number}"/>
          <xsl:if test="/result/ft-query[node()]">
            <input type="hidden" name="ft-query" value="{$ftQueryName}"/>
          </xsl:if>
          <xsl:if test="/result/index-terms[node()]">
            <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
            <input type="hidden" name="index-terms-pn" value="{$indexTermsPN}"/>
          </xsl:if>
          </form>
        </td>
        <td></td>
        <td align="right" nowrap="true">
          <td nowrap="true">
            <xsl:variable name="leftNumber">
              <xsl:choose>
              <xsl:when test="$number &gt; 1"><xsl:value-of select="$number - 1"/></xsl:when>
              <xsl:otherwise><xsl:value-of select="$number"/></xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <form action="page-query-result.xql" method="get">
            <input type="hidden" name="document" value="{$documentUri}"/>
            <input type="image" src="images/left.gif" name="pn" value="{$leftNumber}"/> 
            <input type="hidden" name="mode" value="{$mode}"/>
            <xsl:if test="/result/ft-query[node()]">
              <input type="hidden" name="ft-query" value="{$ftQueryName}"/>
            </xsl:if>
            <xsl:if test="/result/index-terms[node()]">
              <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
              <input type="hidden" name="index-terms-pn" value="{$indexTermsPN}"/>
            </xsl:if>
            </form>
          </td>
          <td nowrap="true">
            <form action="" method="get">
            <xsl:value-of select="$number"/> / <xsl:value-of select="$countPages"/> 
            </form>
          </td>
          <td nowrap="true">
            <xsl:variable name="rightNumber">
              <xsl:choose>
              <xsl:when test="$number &lt; $countPages"><xsl:value-of select="$number + 1"/></xsl:when>
              <xsl:otherwise><xsl:value-of select="$number"/></xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <form action="page-query-result.xql" method="get">
            <input type="hidden" name="document" value="{$documentUri}"/>
            <input type="image" src="images/right.gif" name="pn" value="{$rightNumber}"/> 
            <input type="hidden" name="mode" value="{$mode}"/>
            <xsl:if test="/result/ft-query[node()]">
              <input type="hidden" name="ft-query" value="{$ftQueryName}"/>
            </xsl:if>
            <xsl:if test="/result/index-terms[node()]">
              <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
              <input type="hidden" name="index-terms-pn" value="{$indexTermsPN}"/>
            </xsl:if>
            </form>
          </td>
        </td>
        <td align="right">
          <td nowrap="true">
            <form action="page-query-result.xql" method="get">
            <input type="hidden" name="document" value="{$documentUri}"/>
            Page: <input type="text" size="3" name="pn" value="{$number}"/> 
            <input type="hidden" name="mode" value="{$mode}"/>
            <xsl:if test="/result/ft-query[node()]">
              <input type="hidden" name="ft-query" value="{$ftQueryName}"/>
            </xsl:if>
            <xsl:if test="/result/index-terms[node()]">
              <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
              <input type="hidden" name="index-terms-pn" value="{$indexTermsPN}"/>
            </xsl:if>
            </form>
          </td>
        </td>
        </tr>
      </table>
      <hr/>   
      <xsl:variable name="tableContent">
        <colgroup>
          <col width="65%"/>
          <col width="35%"/>
        </colgroup>
        <tr>
          <xsl:for-each select="content">
            <xsl:choose>
            <xsl:when test="$mode = 'text'"><td align="left" valign="top"><xsl:apply-templates mode="text"/></td></xsl:when>
            <xsl:when test="$mode = 'xml'"><td align="left" valign="top"><xsl:apply-templates mode="xml"/></td></xsl:when>
            <xsl:when test="$mode = 'image'">
              <xsl:variable name="linkImageEcho" select="/result/page/image-echo"/>
              <xsl:variable name="linkImageScaler" select="/result/page/image-scaler"/>
              <td align="middle" valign="top">
                <a href="{$linkImageEcho}"><img alt="Page image: {$number}" src="{$linkImageScaler}&amp;dh=600" border="1"/></a>
              </td>
            </xsl:when>
            <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
          <td align="left" valign="top">
            <form action="page-query-result.xql" method="get">
              <input type="hidden" name="document" value="{$documentUri}"/>
              <input type="hidden" name="pn" value="{$number}"/>
              <input type="hidden" name="mode" value="{$mode}"/>
              Book contains: <input type="text" size="15" name="ft-query" value="{$ftQueryName}"/>
              <input type="submit" value="Query"/>
            </form>
            <form action="page-query-result.xql" method="get">
              <input type="hidden" name="document" value="{$documentUri}"/>
              <input type="hidden" name="pn" value="{$number}"/>
              <input type="hidden" name="mode" value="{$mode}"/>
              Index terms: <input type="text" size="10" name="index-terms-start-str" value="{$indexTermsStartStr}"/> 
              <input type="hidden" name="index-terms-pn" value="1"/>
              <input type="submit" value="Query"/>
            </form>
            <xsl:if test="/result/ft-query[node()]">
              <hr/>
              <b><xsl:value-of select="/result/ft-query/result/size"/> sentences contain: "<xsl:value-of select="$ftQueryName"/>"</b>
              <ol>
                <xsl:for-each select="/result/ft-query/result/hits/hit">
                <li>
                  <xsl:variable name="hitPN" select="pn"/>
                  <xsl:variable name="hitPosOfS" select="pos-of-s"/>
                  <a href="?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}{$ftQueryValue}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a>:<br></br>
                  <!-- Highlight the query terms in each hit sentence and clip the result -->
                  <xsl:sequence select="text:highlight(string(s), $ftQueryName, 'true')"/>
                </li>
                </xsl:for-each>
              </ol>
            </xsl:if>
            <xsl:if test="/result/index-terms/pages > 0">
              <hr/>
              <xsl:variable name="pn" select="/result/index-terms/pn"/>
              <xsl:variable name="size" select="/result/index-terms/size"/>
              <xsl:variable name="pages" select="/result/index-terms/pages"/>
              <b><xsl:value-of select="$size"/> terms beginning with: "<xsl:value-of select="$indexTermsStartStr"/>"</b><br/>
              <table width="100%">
              <colgroup>
                <col width="90%"/>
                <col width="10%"/>
              </colgroup>
              <tr valign="top">
              <td>
              <ol>
              <xsl:for-each select="/result/index-terms/entry">
                <xsl:variable name="pos" select="position"/>
                <xsl:variable name="term" select="term"/>
                <xsl:variable name="dictionaryLink">
                  <xsl:choose>
                  <xsl:when test="$language = 'zh'">
                  <xsl:variable name="termBig5Encoded" select="/result/index-terms/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></xsl:when>
                  <xsl:otherwise><a href="http://archimedes.mpiwg-berlin.mpg.de/cgi-bin/toc/dict?step=table;word={$term};lang={$language};pro=echo">Echo</a></xsl:otherwise>
                  </xsl:choose>
                </xsl:variable>
                <li value="{$pos}">
                   <xsl:value-of select="$term"/>(<xsl:value-of select="frequency"/>) [<xsl:sequence select="$dictionaryLink"/>]
                </li>
              </xsl:for-each>
              </ol>
              </td>
                <td nowrap="true">
                  <td nowrap="true">
                  <xsl:variable name="leftNumber">
                    <xsl:choose>
                    <xsl:when test="$pn &gt; 1"><xsl:value-of select="$pn - 1"/></xsl:when>
                    <xsl:otherwise><xsl:value-of select="$pn"/></xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>
                  <form action="page-query-result.xql" method="get">
                  <input type="hidden" name="document" value="{$documentUri}"/>
                  <input type="hidden" name="pn" value="{$number}"/>
                  <input type="hidden" name="mode" value="{$mode}"/>
                  <input type="image" src="images/left.gif" name="index-terms-pn" value="{$leftNumber}"/> 
                  <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
                  </form>
                  </td>
                  <td nowrap="true">
                  <form action="" method="get">
                  <xsl:value-of select="$pn"/> / <xsl:value-of select="$pages"/>
                  </form>
                  </td>
                  <td nowrap="true">
                  <xsl:variable name="rightNumber">
                    <xsl:choose>
                    <xsl:when test="$pn &lt; $pages"><xsl:value-of select="$pn + 1"/></xsl:when>
                    <xsl:otherwise><xsl:value-of select="$pn"/></xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>
                  <form action="page-query-result.xql" method="get">
                  <input type="hidden" name="document" value="{$documentUri}"/>
                  <input type="hidden" name="pn" value="{$number}"/>
                  <input type="hidden" name="mode" value="{$mode}"/>
                  <input type="image" src="images/right.gif" name="index-terms-pn" value="{$rightNumber}"/> 
                  <input type="hidden" name="index-terms-start-str" value="{$indexTermsStartStr}"/>
                  </form>
                  </td>
                </td>
              </tr>
              </table>
            </xsl:if>
            <xsl:if test="/result/index-terms/pages = 0">
              <hr/>
              <b>No results</b>
            </xsl:if>
          </td>
        </tr>
      </xsl:variable>
      <table align="middle" width="100%" rules="cols" frame="void" cellpadding="5">
          <xsl:sequence select="$tableContent"/>
      </table>
      <hr/>
      Elapsed time: <xsl:value-of select="text:nchars(6, 'bla')"/>, <xsl:value-of select="/result/document-description/performance"/> ms, Back to <a href="query.xql">query page</a>, see the <a href="page-query-result.xql?_source=yes">XQuery source</a> and <a href="/exist/rest/db/mpdl-example/archimedes/xsl/page.xsl?_source=yes">XSL source</a> of this page
      <br/>
      <xsl:variable name="thisUrl" select="concat($documentValue, '&amp;', $pnValue, '&amp;', $modeValue, $ftQueryValue)"/>
      [<a href="page-query-result-old.xql?{$thisUrl}">slower mechanism (XQL search)</a>]
    </xsl:for-each>
  </body></html>
</xsl:template>

<xsl:template match="attribute()|element()|text()|comment()|processing-instruction()" mode="xml">
  <xsl:copy>
    <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="element()|comment()|processing-instruction()" mode="xml">
  <ul style="margin-left:0px;padding-left:8px">
    <xsl:variable name="elementName" select="name()"/>&lt;<span style="font-weight:bold;color: purple;"><xsl:value-of select="$elementName"/></span><xsl:apply-templates select="attribute()" mode="xml"/>&gt;<xsl:apply-templates select="element()|text()|comment()|processing-instruction()" mode="xml"/>&lt;/<span style="font-weight:bold;color: purple;"><xsl:value-of select="$elementName"/></span>&gt;
  </ul>
</xsl:template>

<xsl:template match="attribute()" mode="xml">
  <xsl:variable name="attributeName" select="name()"/><xsl:text> </xsl:text><b><xsl:value-of select="$attributeName"/></b>=&quot;<span style="color: blue;"><xsl:value-of select="."/></span>&quot;<xsl:apply-templates select="attribute()" mode="xml"/>
</xsl:template>

<!-- If ft-query is set then highlight all term occurrences in each little text piece for the fulltext query -->
<xsl:template match="text()" mode="xml">
  <xsl:choose>
  <xsl:when test="$ftQueryMode != 'false'">
    <xsl:sequence select="text:highlight(string(.), $ftQueryName, 'false')"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="."/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<xsl:template match="chap|p" mode="text">
  <p><xsl:apply-templates mode="text"/></p>
</xsl:template>

<xsl:template match="lb" mode="text">
  <br/>
</xsl:template>

<xsl:template match="expan" mode="text">
  <xsl:apply-templates mode="text"/><xsl:text> </xsl:text>
</xsl:template>

<xsl:variable name="firstFigurePosition" select="/result/page/firstFigurePosition"/>

<xsl:template match="figure" mode="text">
  <xsl:variable name="figurePos" select="count(preceding::figure)"/>
  <xsl:variable name="figureId" select="$firstFigurePosition + $figurePos"/>
  <xsl:variable name="documentName" select="/result/document-description/document-name"/>
  <!-- delivers all fileds from 021/01/001/1.jpg -->
  <xsl:variable name="figureLink" select="@xlink:href"/>
  <xsl:variable name="docId" select="substring-before($figureLink, '/')"/>
  <xsl:variable name="figureLinkAfter1" select="substring-after($figureLink, '/')"/>
  <xsl:variable name="docId2" select="substring-before($figureLinkAfter1, '/')"/>
  <xsl:variable name="figureLinkAfter2" select="substring-after($figureLinkAfter1, '/')"/>
  <xsl:variable name="page" select="substring-before($figureLinkAfter2, '/')"/>
  <xsl:variable name="figureFileName" select="substring-after($figureLinkAfter2, '/')"/>
  <p></p>
  <a href="http://echo.mpiwg-berlin.mpg.de/zogilib?fn=/permanent/archimedes/{$documentName}/{$docId}-{$docId2}-figures&amp;pn={$figureId}"><img alt="figure: {$figureId}" src="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=/permanent/archimedes/{$documentName}/{$docId}-{$docId2}-figures&amp;pn={$figureId}&amp;dh=150" align="middle" border="1"/></a>
  <p></p>
  Figure: <xsl:value-of select="$figureId"/>
  <p></p>
</xsl:template>

<!-- If ft-query is set then highlight all term occurrences in each little text piece for the fulltext query -->
<xsl:template match="text()" mode="text">
  <xsl:choose>
  <xsl:when test="$ftQueryMode != 'false'">
    <!-- <xsl:sequence select="text:highlight(string(.), $ftQueryName, $ftQueryMode, 'false')"/>  -->
    <xsl:sequence select="text:highlight(string(.), $ftQueryName, 'false')"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="."/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>



</xsl:stylesheet>