Mercurial > hg > mpdl-group
comparison software/eXist/webapp/mpdl/presentation/queryHtml.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 | e99964f390e4 |
comparison
equal
deleted
inserted
replaced
6:2396a569e446 | 7:5589d865af7a |
---|---|
1 <?xml version="1.0"?> | |
2 <xsl:stylesheet version="2.0" | |
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
4 xmlns:xlink="http://www.w3.org/1999/xlink" | |
5 xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
6 xmlns:saxon="http://saxon.sf.net/" | |
7 xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text" | |
8 xmlns:dc="http://purl.org/dc/elements/1.1/" | |
9 xmlns:dcterms="http://purl.org/dc/terms" | |
10 xmlns:echo="http://www.mpiwg-berlin.mpg.de/ns/echo/1.0/" | |
11 xmlns:mml="http://www.w3.org/1998/Math/MathML" | |
12 xmlns:xhtml="http://www.w3.org/1999/xhtml" | |
13 xmlns:functx="http://www.functx.com"> | |
14 | |
15 <xsl:import href="/db/mpdl/presentation/functions-functx.xsl"/> | |
16 <xsl:import href="/db/mpdl/presentation/functions-text.xsl"/> | |
17 | |
18 <xsl:output method="html" encoding="utf-8"/> | |
19 | |
20 <xsl:variable name="errorMessage" select="string(/result/query/result/error)"/> | |
21 <xsl:variable name="documentUri" select="/result/document-description/uri"/> | |
22 <xsl:variable name="documentName" select="/result/document-description/document-name"/> | |
23 <xsl:variable name="documentValue" select="concat('document=', $documentUri)"/> | |
24 <xsl:variable name="mode" select="/result/page/mode"/> | |
25 <xsl:variable name="modeValue" select="concat('mode=', $mode)"/> | |
26 <xsl:variable name="queryType" select="/result/query/type"/> | |
27 <xsl:variable name="query" select="text:trim(string(/result/query/expression))"/> | |
28 <xsl:variable name="queryResultPages" select="number(/result/query/result/pages)"/> | |
29 <xsl:variable name="queryResultSize" select="number(/result/query/result/size)"/> | |
30 <xsl:variable name="queryResultPN" select="/result/query/result/pn"/> | |
31 <xsl:variable name="language" select="/result/document-description/language"/> | |
32 <xsl:variable name="ftQueryTermsTemp" select="string-join(text:translateLuceneToTerms($query), '')" as="xs:string"/> | |
33 <xsl:variable name="ftQueryMorphForms" select="string(/result/query/result/query-forms)"/> | |
34 <!-- Removes the duplicates between ftQueryMorphForms and ftQueryTerms for highlighting them semantically correct: --> | |
35 <!-- Morphological forms are hightlighted as whole words but query terms are highlighted also as partly strings --> | |
36 <xsl:variable name="ftQueryTerms" select="text:removeDuplicates($ftQueryTermsTemp, $ftQueryMorphForms)"/> | |
37 <xsl:variable name="ftQueryRegularizations" select="string(/result/query/result/query-regularizations)"/> | |
38 <xsl:variable name="ftQueryHighlightWords"> | |
39 <xsl:choose> | |
40 <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations = ''"><xsl:value-of select="$ftQueryMorphForms"/></xsl:when> | |
41 <xsl:when test="$ftQueryMorphForms = '' and $ftQueryRegularizations != ''"><xsl:value-of select="$ftQueryRegularizations"/></xsl:when> | |
42 <xsl:when test="$ftQueryMorphForms != '' and $ftQueryRegularizations != ''"><xsl:value-of select="concat($ftQueryMorphForms, '|', $ftQueryRegularizations)"/></xsl:when> | |
43 <xsl:otherwise><xsl:value-of select="$ftQueryMorphForms"/></xsl:otherwise> | |
44 </xsl:choose> | |
45 </xsl:variable> | |
46 <xsl:variable name="ftQueryEncodeBig5" select="/result/query/result/big5-mappings"/> | |
47 | |
48 <xsl:template match="result"> | |
49 <div class="queryResult"> | |
50 <div class="queryResultHits" style="visibility:hidden"> | |
51 <xsl:value-of select="$queryResultSize"/> | |
52 </div> | |
53 <xsl:if test="(($query != '' or $queryType = 'toc' or $queryType = 'figures') and $queryResultPages > 0)"> | |
54 <xsl:if test="$ftQueryMorphForms != ''"> | |
55 <div class="queryResultMorphExpansion"> | |
56 <xsl:if test="$queryType = 'fulltextMorph'"> | |
57 Morphological expansion: <a href="../lt/lemma.xql?language={$language}&query={$query}">see here</a> | |
58 </xsl:if> | |
59 <xsl:if test="$queryType = 'fulltextMorphLemma'"> | |
60 Morphological expansion: <a href="../lt/lemma.xql?language={$language}&lemma={$query}">see here</a> | |
61 </xsl:if> | |
62 </div> | |
63 </xsl:if> | |
64 <div class="queryResultPage"> | |
65 <xsl:if test="$queryType = 'toc' or $queryType = 'figures'"> | |
66 <xsl:for-each select="/result/query/result/hits/toc-entry"> | |
67 <xsl:variable name="page" select="page"/> | |
68 <xsl:variable name="level"> | |
69 <xsl:choose> | |
70 <xsl:when test="real-level = '1'"><xsl:value-of select="'one'"/></xsl:when> | |
71 <xsl:when test="real-level = '2'"><xsl:value-of select="'two'"/></xsl:when> | |
72 <xsl:when test="real-level = '3'"><xsl:value-of select="'three'"/></xsl:when> | |
73 <xsl:when test="real-level = '4'"><xsl:value-of select="'four'"/></xsl:when> | |
74 <xsl:when test="real-level = '5'"><xsl:value-of select="'five'"/></xsl:when> | |
75 <xsl:when test="real-level = '6'"><xsl:value-of select="'six'"/></xsl:when> | |
76 <xsl:when test="real-level = '7'"><xsl:value-of select="'seven'"/></xsl:when> | |
77 <xsl:otherwise><xsl:value-of select="'one'"/></xsl:otherwise> | |
78 </xsl:choose> | |
79 </xsl:variable> | |
80 <div class="toc {$level}"> | |
81 <xsl:value-of select="'['"/> | |
82 <xsl:value-of select="concat(level-string, ' ')"/> | |
83 <xsl:value-of select="content"/> | |
84 <xsl:value-of select="']'"/> | |
85 </div> | |
86 <div class="toc float right"> | |
87 <a href="page-fragment.xql?{$documentValue}&mode={$mode}&pn={$page}"> | |
88 <xsl:value-of select="concat('Page: ', $page)"/> | |
89 </a> | |
90 </div> | |
91 </xsl:for-each> | |
92 </xsl:if> | |
93 <xsl:if test="$queryType = 'fulltext' or $queryType = 'fulltextMorph' or $queryType = 'fulltextMorphLemma'"> | |
94 <xsl:for-each select="/result/query/result/hits/hit"> | |
95 <xsl:variable name="pos" select="pos"/> | |
96 <xsl:variable name="term" select="term"/> | |
97 <div class="queryResultPageHit"> | |
98 <div class="queryResultPageHitLink"> | |
99 <xsl:value-of select="concat($pos, '.')"/> | |
100 <xsl:variable name="hitPN" select="pn"/> | |
101 <xsl:variable name="hitPosOfS" select="pos-of-s"/> | |
102 <xsl:variable name="sSurroundsPB" select="s-surrounds-pb"/> | |
103 <xsl:variable name="queryValue" select="concat('&', 'query=', $query)"/> | |
104 <xsl:variable name="queryValueEscaped1" select="replace($queryValue, '\+', '%2B')"/> | |
105 <xsl:variable name="queryValueEscaped2" select="replace($queryValueEscaped1, ' ', '+')"/> | |
106 <xsl:choose> | |
107 <!-- if a found sentence surrounds a page break then a special presentation of the hit is done --> | |
108 <xsl:when test="$sSurroundsPB = 'false'"> | |
109 <a href="page-fragment.xql?{$documentValue}&pn={$hitPN}&sn={$hitPosOfS}&{$modeValue}&highlightQuery={$query}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a> | |
110 </xsl:when> | |
111 <xsl:otherwise> | |
112 <a href="page-fragment.xql?{$documentValue}&pn={$hitPN}&sn={$hitPosOfS}&{$modeValue}&highlightQuery={$query}#sn{$hitPosOfS}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a> / <a href="page-fragment.xql?{$documentValue}&pn={$hitPN + 1}&sn=0&{$modeValue}&highlightQuery={$query}#sn0">Page <xsl:value-of select="$hitPN + 1"/>, continuation of the sentence</a> | |
113 </xsl:otherwise> | |
114 </xsl:choose> | |
115 <xsl:value-of select="':'"/> | |
116 </div> | |
117 <div class="queryResultPageHitContent"> | |
118 <!-- Highlight the query terms in each hit sentence and clip the result --> | |
119 <xsl:sequence select="text:highlight(s, $ftQueryTerms, $ftQueryHighlightWords, 'true')"/> | |
120 </div> | |
121 </div> | |
122 </xsl:for-each> | |
123 </xsl:if> | |
124 <xsl:if test="$queryType = 'ftIndex' or $queryType = 'ftIndexMorph'"> | |
125 <xsl:for-each select="/result/query/result/hits/entry"> | |
126 <xsl:variable name="pos" select="position"/> | |
127 <xsl:variable name="term" select="term"/> | |
128 <xsl:variable name="polluxKeys" select="pollux-keys"/> | |
129 <xsl:variable name="lemmasWithOR" select="lemmas-with-or"/> | |
130 <xsl:variable name="dictionaryLink"> | |
131 <xsl:choose> | |
132 <xsl:when test="$language = 'zh'"> | |
133 <xsl:variable name="termBig5Encoded" select="/result/query/result/big5-hits/entry-big5-encoded/term[$pos]"/> | |
134 <a href="http://humanum.arts.cuhk.edu.hk/cgi-bin/agrep-lindict?query={$termBig5Encoded}&category=wholerecord">Lin Yutang</a> | |
135 </xsl:when> | |
136 <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> | |
137 </xsl:choose> | |
138 </xsl:variable> | |
139 <xsl:variable name="polluxLink"> | |
140 <xsl:choose> | |
141 <xsl:when test="$polluxKeys = ''">Pollux</xsl:when> | |
142 <xsl:otherwise><a href="../lt/lex.xql?language={$language}&query={$polluxKeys}">Pollux</a></xsl:otherwise> | |
143 </xsl:choose> | |
144 </xsl:variable> | |
145 <xsl:variable name="wikipediaLink"> | |
146 <xsl:choose> | |
147 <xsl:when test="$lemmasWithOR = ''">Wiki</xsl:when> | |
148 <xsl:otherwise><a href="http://{$language}.wikipedia.org/wiki/index.php?search={$lemmasWithOR}">Wiki</a></xsl:otherwise> | |
149 </xsl:choose> | |
150 </xsl:variable> | |
151 <xsl:variable name="ftSearchQueryType"> | |
152 <xsl:choose> | |
153 <xsl:when test="$queryType = 'ftIndex'"><xsl:value-of select="'fulltext'"/></xsl:when> | |
154 <xsl:when test="$queryType = 'ftIndexMorph'"><xsl:value-of select="'fulltextMorphLemma'"/></xsl:when> | |
155 <xsl:otherwise></xsl:otherwise> | |
156 </xsl:choose> | |
157 </xsl:variable> | |
158 <div class="queryResultPageHit"> | |
159 <xsl:value-of select="concat($pos, '.')"/> | |
160 <a href="../lt/lemma.xql?language={$language}&lemma={$term}"><xsl:value-of select="$term"/></a>(<a href="?{$documentValue}&{$modeValue}&queryType={$ftSearchQueryType}&query={$term}"><xsl:value-of select="frequency"/></a>) [<xsl:sequence select="$polluxLink"/>][<xsl:sequence select="$wikipediaLink"/>][<xsl:sequence select="$dictionaryLink"/>] | |
161 </div> | |
162 </xsl:for-each> | |
163 </xsl:if> | |
164 <xsl:if test="$queryType = 'xpath' or $queryType = 'xquery'"> | |
165 <xsl:for-each select="/result/query/result/hits"> | |
166 <div class="queryResultPageHit"> | |
167 <div class="queryResultPageHitContent"> | |
168 <xsl:apply-templates mode="xml"/> | |
169 </div> | |
170 <div class="queryResultPageHitDownload"> | |
171 <xsl:variable name="queryWithoutCRLF" select="replace($query, '\r\n', ' ')"/> | |
172 <a target="_blank" href="?{$documentValue}&mode=pureXml&queryType={$queryType}&query={$queryWithoutCRLF}&queryResultPN={$queryResultPN}"><img src="../images/download.png" width="24" height="24" border="0" alt="Download"/></a><xsl:value-of select="'Download'"/> | |
173 </div> | |
174 </div> | |
175 </xsl:for-each> | |
176 </xsl:if> | |
177 </div> | |
178 </xsl:if> | |
179 <xsl:choose> | |
180 <xsl:when test="$errorMessage != ''"> | |
181 <div class="query-result-page"> | |
182 <b>Your query delivers an error: </b> | |
183 <xsl:value-of select="$errorMessage"/> | |
184 </div> | |
185 </xsl:when> | |
186 <xsl:when test="$errorMessage = '' and $query != '' and $queryResultPages = 0"> | |
187 <div class="query-result-page"> | |
188 <b>No results</b> | |
189 </div> | |
190 </xsl:when> | |
191 </xsl:choose> | |
192 </div> | |
193 </xsl:template> | |
194 | |
195 <xsl:template match="attribute()|element()|text()|comment()|processing-instruction()" mode="xml"> | |
196 <xsl:copy> | |
197 <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/> | |
198 </xsl:copy> | |
199 </xsl:template> | |
200 | |
201 <xsl:template match="element()|comment()|processing-instruction()" mode="xml"> | |
202 <xsl:variable name="elementName" select="name()"/> | |
203 <xsl:variable name="elementPresentation"> | |
204 <xsl:choose> | |
205 <xsl:when test="element() = node() or text() != '' or self::comment() or self::processing-instruction()"> | |
206 <<span style="font-weight:bold;color:purple;"><xsl:value-of select="$elementName"/></span><xsl:apply-templates select="attribute()" mode="xml"/>><xsl:apply-templates select="element()|text()|comment()|processing-instruction()" mode="xml"/></<span style="font-weight:bold;color:purple;"><xsl:value-of select="$elementName"/></span>> | |
207 </xsl:when> | |
208 <xsl:otherwise> | |
209 <<span style="font-weight:bold;color:purple;"><xsl:value-of select="$elementName"/></span><xsl:apply-templates select="attribute()" mode="xml"/>/> | |
210 </xsl:otherwise> | |
211 </xsl:choose> | |
212 </xsl:variable> | |
213 <ul style="margin-left:0px;padding-left:8px"><xsl:sequence select="$elementPresentation"/></ul> | |
214 </xsl:template> | |
215 | |
216 <xsl:template match="attribute()" mode="xml"> | |
217 <xsl:variable name="attributeName" select="name()"/><xsl:text> </xsl:text><b><xsl:value-of select="$attributeName"/></b>="<span style="color:blue;"><xsl:value-of select="."/></span>"<xsl:apply-templates select="attribute()" mode="xml"/> | |
218 </xsl:template> | |
219 | |
220 </xsl:stylesheet> |