view software/eXist/webapp/mpdl/presentation/queryHtml.xsl @ 15:e99964f390e4

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Mon, 29 Aug 2011 17:40:19 +0200
parents 5589d865af7a
children 7e883ce72fec
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:saxon="http://saxon.sf.net/"
  xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text"
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:dcterms="http://purl.org/dc/terms"
  xmlns:echo="http://www.mpiwg-berlin.mpg.de/ns/echo/1.0/" 
  xmlns:mml="http://www.w3.org/1998/Math/MathML" 
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  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:output method="html" encoding="utf-8"/>

<xsl:variable name="errorMessage" select="string(/result/query/result/error)"/>
<xsl:variable name="documentUri" select="/result/document-description/uri"/>
<xsl:variable name="documentName" select="/result/document-description/document-name"/>
<xsl:variable name="documentValue" select="concat('document=', $documentUri)"/>
<xsl:variable name="mode" select="/result/page/mode"/>
<xsl:variable name="modeValue" select="concat('mode=', $mode)"/>
<xsl:variable name="queryType" select="/result/query/type"/>
<xsl:variable name="query" select="text:trim(string(/result/query/expression))"/>
<xsl:variable name="queryResultPages" select="number(/result/query/result/pages)"/>
<xsl:variable name="queryResultSize" select="number(/result/query/result/size)"/>
<xsl:variable name="queryResultPN" select="/result/query/result/pn"/>
<xsl:variable name="language" select="/result/document-description/language"/>
<xsl:variable name="ftQueryTermsTemp" select="string-join(text:translateLuceneToTerms($query), '')" as="xs:string"/>
<xsl:variable name="ftQueryMorphForms" select="string(/result/query/result/query-forms)"/>
<!-- Removes the duplicates between ftQueryMorphForms and ftQueryTerms for highlighting them semantically correct: -->
<!-- Morphological forms are hightlighted as whole words but query terms are highlighted also as partly strings -->
<xsl:variable name="ftQueryTerms" select="text:removeDuplicates($ftQueryTermsTemp, $ftQueryMorphForms)"/> 
<xsl:variable name="ftQueryRegularizations" select="string(/result/query/result/query-regularizations)"/>
<xsl:variable name="ftQueryHighlightWords">
  <xsl:choose>
  <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations = ''"><xsl:value-of select="$ftQueryMorphForms"/></xsl:when>
  <xsl:when test="$ftQueryMorphForms = '' and $ftQueryRegularizations != ''"><xsl:value-of select="$ftQueryRegularizations"/></xsl:when>
  <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations != ''"><xsl:value-of select="concat($ftQueryMorphForms, '|', $ftQueryRegularizations)"/></xsl:when>
  <xsl:otherwise><xsl:value-of select="$ftQueryMorphForms"/></xsl:otherwise>
  </xsl:choose>
</xsl:variable>
<xsl:variable name="ftQueryEncodeBig5" select="/result/query/result/big5-mappings"/>

<xsl:template match="result">
  <div class="queryResult">
    <div class="queryResultHits" style="visibility:hidden">
      <xsl:value-of  select="$queryResultSize"/>
	</div>
	<xsl:if test="(($query != '' or $queryType = 'toc' or $queryType = 'figures') and $queryResultPages &gt; 0)">
      <xsl:if test="$ftQueryMorphForms != ''">
        <div class="queryResultMorphExpansion">
	      <xsl:if test="$queryType = 'fulltextMorph'">
	        Morphological expansion: <a href="../lt/lemma.xql?language={$language}&amp;query={$query}">see here</a>
	      </xsl:if>
	      <xsl:if test="$queryType = 'fulltextMorphLemma'">
	        Morphological expansion: <a href="../lt/lemma.xql?language={$language}&amp;lemma={$query}">see here</a>
	      </xsl:if>
	    </div>
	  </xsl:if>
      <div class="queryResultPage">
	  <xsl:if test="$queryType = 'toc' or $queryType = 'figures'">
	    <xsl:for-each select="/result/query/result/hits/toc-entry">
	      <xsl:variable name="page" select="page"/>
	      <xsl:variable name="level">
	        <xsl:choose>
	          <xsl:when test="real-level = '1'"><xsl:value-of select="'one'"/></xsl:when>
	          <xsl:when test="real-level = '2'"><xsl:value-of select="'two'"/></xsl:when>
	          <xsl:when test="real-level = '3'"><xsl:value-of select="'three'"/></xsl:when>
	          <xsl:when test="real-level = '4'"><xsl:value-of select="'four'"/></xsl:when>
	          <xsl:when test="real-level = '5'"><xsl:value-of select="'five'"/></xsl:when>
	          <xsl:when test="real-level = '6'"><xsl:value-of select="'six'"/></xsl:when>
	          <xsl:when test="real-level = '7'"><xsl:value-of select="'seven'"/></xsl:when>
	          <xsl:otherwise><xsl:value-of select="'one'"/></xsl:otherwise>
	        </xsl:choose>
	      </xsl:variable>
          <div class="toc {$level}">
            <xsl:value-of select="'['"/>
	        <xsl:value-of select="concat(level-string, ' ')"/>
	        <xsl:value-of select="content"/>
            <xsl:value-of select="']'"/>
	      </div>
	      <div class="toc float right">
	        <a href="page-fragment.xql?{$documentValue}&amp;mode={$mode}&amp;pn={$page}">
	          <xsl:value-of select="concat('Page: ', $page)"/>
	        </a>
	      </div>
	    </xsl:for-each>
	  </xsl:if>
	  <xsl:if test="$queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma'">
	  <xsl:for-each select="/result/query/result/hits/hit">
	    <xsl:variable name="pos" select="pos"/>
	    <xsl:variable name="term" select="term"/>
        <xsl:variable name="hitString" select="hitString"/>
	    <div class="queryResultPageHit">
          <div class="queryResultPageHitLink">
	        <xsl:value-of select="concat($pos, '.')"/>
            <xsl:variable name="hitType" select="hitType"/>
	        <xsl:variable name="hitPN" select="pn"/>
	        <xsl:variable name="hitPos" select="hitPos"/>
	        <xsl:variable name="hitSurroundsPB" select="hitSurroundsPB"/>
	        <xsl:variable name="queryValue" select="concat('&amp;', 'query=', $query)"/>
	        <xsl:variable name="queryValueEscaped1" select="replace($queryValue, '\+', '%2B')"/>
	        <xsl:variable name="queryValueEscaped2" select="replace($queryValueEscaped1, ' ', '+')"/>
	        <xsl:choose>
	        <!-- if a found sentence surrounds a page break then a special presentation of the hit is done -->
              <xsl:when test="$hitType = 's' and $hitSurroundsPB = 'false'">
	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a>
	          </xsl:when>
              <xsl:when test="$hitType = 'head'">
	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#head{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Head <xsl:value-of select="$hitPos"/></a>
	          </xsl:when>
	          <xsl:otherwise>
	            <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN}&amp;{$modeValue}&amp;highlightQuery={$query}&amp;highlightElement={$hitType}&amp;highlightElementPos={$hitPos}#s{$hitPos}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPos"/></a> / <a href="page-fragment.xql?{$documentValue}&amp;pn={$hitPN + 1}&amp;{$modeValue}&amp;highlightQuery={$query}#s0">Page <xsl:value-of select="$hitPN + 1"/>, continuation of the sentence</a>
	          </xsl:otherwise>
	        </xsl:choose>
	        <xsl:value-of select="':'"/>
	      </div>
          <div class="queryResultPageHitContent">
	        <!-- Highlight the query terms in each hit sentence and clip the result -->
	        <xsl:sequence select="text:highlight($hitString, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/>
	      </div>
	    </div>
	  </xsl:for-each>
	  </xsl:if>
	  <xsl:if test="$queryType = 'ftIndex' or $queryType = 'ftIndexMorph'">
	  <xsl:for-each select="/result/query/result/hits/entry">
	    <xsl:variable name="pos" select="position"/>
	    <xsl:variable name="term" select="term"/>
	    <xsl:variable name="polluxKeys" select="pollux-keys"/>
	    <xsl:variable name="lemmasWithOR" select="lemmas-with-or"/>
	    <xsl:variable name="dictionaryLink">
          <xsl:choose>
	      <xsl:when test="$language = 'zh'">
	      <xsl:variable name="termBig5Encoded" select="/result/query/result/big5-hits/entry-big5-encoded/term[$pos]"/>
	      <a href="http://humanum.arts.cuhk.edu.hk/cgi-bin/agrep-lindict?query={$termBig5Encoded}&amp;category=wholerecord">Lin Yutang</a>
	      </xsl:when>
	      <xsl:otherwise><a href="http://archimedes.mpiwg-berlin.mpg.de/cgi-bin/toc/dict?step=table;word={$term};lang={$language};pro=echo">Echo</a></xsl:otherwise>
	      </xsl:choose>
	    </xsl:variable>
	    <xsl:variable name="polluxLink">
	      <xsl:choose>
	      <xsl:when test="$polluxKeys = ''">Pollux</xsl:when>
	      <xsl:otherwise><a href="../lt/lex.xql?language={$language}&amp;query={$polluxKeys}">Pollux</a></xsl:otherwise>
	      </xsl:choose>
	    </xsl:variable>
	    <xsl:variable name="wikipediaLink">
	      <xsl:choose>
	      <xsl:when test="$lemmasWithOR = ''">Wiki</xsl:when>
	      <xsl:otherwise><a href="http://{$language}.wikipedia.org/wiki/index.php?search={$lemmasWithOR}">Wiki</a></xsl:otherwise>
	      </xsl:choose>
	    </xsl:variable>
	    <xsl:variable name="ftSearchQueryType">
	      <xsl:choose>
	      <xsl:when test="$queryType = 'ftIndex'"><xsl:value-of select="'fulltext'"/></xsl:when>
	      <xsl:when test="$queryType = 'ftIndexMorph'"><xsl:value-of select="'fulltextMorphLemma'"/></xsl:when>
	      <xsl:otherwise></xsl:otherwise>
	      </xsl:choose>
	    </xsl:variable>
	    <div class="queryResultPageHit">
          <xsl:value-of select="concat($pos, '.')"/>
          <a href="../lt/lemma.xql?language={$language}&amp;lemma={$term}"><xsl:value-of select="$term"/></a>(<a href="?{$documentValue}&amp;{$modeValue}&amp;queryType={$ftSearchQueryType}&amp;query={$term}"><xsl:value-of select="frequency"/></a>) [<xsl:sequence select="$polluxLink"/>][<xsl:sequence select="$wikipediaLink"/>][<xsl:sequence select="$dictionaryLink"/>]
        </div>    
	  </xsl:for-each>
	  </xsl:if>
	  <xsl:if test="$queryType = 'xpath' or $queryType = 'xquery'">
	    <xsl:for-each select="/result/query/result/hits">
          <div class="queryResultPageHit">
            <div class="queryResultPageHitContent">
	          <xsl:apply-templates mode="xml"/>
	        </div>
            <div class="queryResultPageHitDownload">
              <xsl:variable name="queryWithoutCRLF" select="replace($query, '\r\n', ' ')"/>
              <a target="_blank" href="?{$documentValue}&amp;mode=pureXml&amp;queryType={$queryType}&amp;query={$queryWithoutCRLF}&amp;queryResultPN={$queryResultPN}"><img src="../images/download.png" width="24" height="24" border="0" alt="Download"/></a><xsl:value-of select="'Download'"/>
            </div>
          </div>
	    </xsl:for-each>
	  </xsl:if>
	  </div>
	</xsl:if>
    <xsl:choose>
      <xsl:when test="$errorMessage != ''">
        <div class="query-result-page">
          <b>Your query delivers an error: </b>
          <xsl:value-of select="$errorMessage"/>
        </div>
      </xsl:when>
      <xsl:when test="$errorMessage = '' and $query != '' and $queryResultPages = 0">
        <div class="query-result-page">
          <b>No results</b>
        </div>
      </xsl:when>
    </xsl:choose>
  </div>
</xsl:template>

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

<xsl:template match="element()|comment()|processing-instruction()" mode="xml">
  <xsl:variable name="elementName" select="name()"/>
  <xsl:variable name="elementPresentation">
    <xsl:choose>
    <xsl:when test="element() = node() or text() != '' or self::comment() or self::processing-instruction()">
      &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;
    </xsl:when>
    <xsl:otherwise>
      &lt;<span style="font-weight:bold;color:purple;"><xsl:value-of select="$elementName"/></span><xsl:apply-templates select="attribute()" mode="xml"/>/&gt;
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <ul style="margin-left:0px;padding-left:8px"><xsl:sequence select="$elementPresentation"/></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>

</xsl:stylesheet>