comparison software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/archimedes-text-fragment.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
comparison
equal deleted inserted replaced
6:2396a569e446 7:5589d865af7a
1 <xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:xlink="http://www.w3.org/1999/xlink">
4
5 <xsl:output method="html"/>
6
7 <xsl:variable name="ftQueryName" select="/result/ft-query/name"/>
8 <xsl:variable name="ftQueryStr" select="concat('&amp;', 'ft-query=', $ftQueryName)"/>
9 <xsl:variable name="ftQueryMode">
10 <xsl:choose>
11 <xsl:when test="matches($ftQueryName, concat('&quot;', '.*', '&quot;'))">
12 <xsl:value-of select="'phrase'"/>
13 </xsl:when>
14 <xsl:when test="string-length($ftQueryName) = 0">
15 <xsl:value-of select="'false'"/>
16 </xsl:when>
17 <!-- Because there are problems in recognizing words (in mode word) this fake mode is used (same as phrase mode) -->
18 <xsl:otherwise><xsl:value-of select="'fakeWord'"/></xsl:otherwise>
19 </xsl:choose>
20 </xsl:variable>
21 <xsl:variable name="ftQueryValue">
22 <xsl:choose>
23 <xsl:when test="/result/ft-query[node()]"><xsl:value-of select="$ftQueryStr"/></xsl:when>
24 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
25 </xsl:choose>
26 </xsl:variable>
27
28 <xsl:template match="result">
29 <html><body>
30 <xsl:for-each select="document-description">
31 <h2>
32 <xsl:for-each select="info">
33 <xsl:value-of select="author"/>.
34 <xsl:value-of select="title"/>.
35 <xsl:value-of select="place"/>,
36 <xsl:value-of select="date"/>
37 </xsl:for-each>
38 </h2>
39 </xsl:for-each>
40 <xsl:for-each select="page">
41 <xsl:variable name="documentName" select="/result/document-description/document-name"/>
42 <xsl:variable name="countPages" select="/result/document-description/count-pages"/>
43 <xsl:variable name="number" select="number(number)"/>
44 <xsl:variable name="documentValue" select="concat('document=', $documentName)"/>
45 <xsl:variable name="pnValue" select="concat('pn=', $number)"/>
46 <xsl:variable name="modeImageValue" select="concat('mode=', 'image')"/>
47 <xsl:variable name="modeXmlValue" select="concat('mode=', 'xml')"/>
48 <xsl:variable name="modeTextValue" select="concat('mode=', 'text')"/>
49 <xsl:variable name="imageLink" select="concat($documentValue, '&amp;', $pnValue, '&amp;', $modeImageValue, $ftQueryValue)"/>
50 <xsl:variable name="textLink" select="concat($documentValue, '&amp;', $pnValue, '&amp;', $modeTextValue, $ftQueryValue)"/>
51 <xsl:variable name="xmlLink" select="concat($documentValue, '&amp;', $pnValue, '&amp;', $modeXmlValue, $ftQueryValue)"/>
52 <form action="" method="get"></form>
53 <table width="100%">
54 <colgroup>
55 <col width="30%"/>
56 <col width="70%"/>
57 </colgroup>
58 <tr>
59 <td align="left" nowrap="true">
60 [Text]
61 [<a href="?{$imageLink}">Image</a>]
62 [<a href="?{$xmlLink}">XML</a>]
63 </td>
64 <td valign="right" nowrap="true">
65 <td>
66 <xsl:choose>
67 <xsl:when test="$number &gt; 1">
68 <a href="?{$documentValue}&amp;pn={$number - 1}&amp;{$modeTextValue}{$ftQueryValue}"><img src="images/left.gif" alt="page-down" border="0"/></a>
69 </xsl:when>
70 <xsl:otherwise>
71 <a href="?{$textLink}"><img src="images/left.gif" alt="page-down" border="0"/></a>
72 </xsl:otherwise>
73 </xsl:choose>
74 </td>
75 <td nowrap="true">
76 <xsl:value-of select="$number"/> / <xsl:value-of select="$countPages"/>
77 </td>
78 <td>
79 <xsl:choose>
80 <xsl:when test="$number &lt; $countPages">
81 <a href="?{$documentValue}&amp;pn={$number + 1}&amp;{$modeTextValue}{$ftQueryValue}"><img src="images/right.gif" alt="page-up" border="0"/></a>
82 </xsl:when>
83 <xsl:otherwise>
84 <a href="?{$textLink}"><img src="images/right.gif" alt="page-down" border="0"/></a>
85 </xsl:otherwise>
86 </xsl:choose>
87 </td>
88 <td nowrap="true">
89 <input type="hidden" name="document" value="{$documentName}"/>
90 Page: <input type="text" size="3" name="pn" value="{$number}"/>
91 <input type="hidden" name="mode" value="text"/>
92 <xsl:if test="/result/ft-query[node()]">
93 <input type="hidden" name="ft-query" value="{$ftQueryName}"/>
94 </xsl:if>
95 </td>
96 </td>
97 </tr>
98 </table>
99 <hr/>
100 <table align="middle" width="100%">
101 <colgroup>
102 <col width="70%"/>
103 <col width="30%"/>
104 </colgroup>
105 <tr>
106 <td align="left" valign="top">
107 <xsl:for-each select="content">
108 <xsl:apply-templates/>
109 </xsl:for-each>
110 </td>
111 <xsl:if test="$ftQueryValue!=''">
112 <td align="left" valign="top">
113 <b><xsl:value-of select="/result/ft-query/result/size"/> Hits: "<xsl:value-of select="$ftQueryName"/>"</b>
114 <ol>
115 <xsl:for-each select="/result/ft-query/result/hits/hit">
116 <li>
117 <xsl:variable name="hitPN" select="pn"/>
118 <xsl:variable name="hitPosOfS" select="pos-of-s"/>
119 <a href="?{$documentValue}&amp;pn={$hitPN}&amp;{$modeTextValue}{$ftQueryValue}">Page <xsl:value-of select="$hitPN"/>, Sentence <xsl:value-of select="$hitPosOfS"/></a>
120 </li>
121 </xsl:for-each>
122 </ol>
123 </td>
124 </xsl:if>
125 </tr>
126 </table>
127 <hr/>
128 Elapsed time: <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/xsl/archimedes-text-fragment.xsl?_source=yes">XSL source</a> of this page
129 <br/>
130 [<a href="page-query-result.xql?{$textLink}">fast mechanism (file system search)</a>] [<a href="page-query-result-old.xql?{$textLink}">slower mechanism (XQL search)</a>]
131 </xsl:for-each>
132 </body></html>
133 </xsl:template>
134
135 <xsl:template match="chap|p">
136 <p><xsl:apply-templates/></p>
137 </xsl:template>
138
139 <xsl:template match="lb">
140 <br/>
141 </xsl:template>
142
143 <xsl:template match="expan">
144 <xsl:apply-templates/><xsl:text> </xsl:text>
145 </xsl:template>
146
147 <xsl:variable name="firstFigurePosition" select="/result/page/firstFigurePosition"/>
148
149 <xsl:template match="figure">
150 <xsl:variable name="figurePos" select="count(preceding::figure)"/>
151 <xsl:variable name="figureId" select="$firstFigurePosition + $figurePos"/>
152 <xsl:variable name="documentName" select="/result/document-description/document-name"/>
153 <!-- delivers all fileds from 021/01/001/1.jpg -->
154 <xsl:variable name="figureLink" select="@xlink:href"/>
155 <xsl:variable name="docId" select="substring-before($figureLink, '/')"/>
156 <xsl:variable name="figureLinkAfter1" select="substring-after($figureLink, '/')"/>
157 <xsl:variable name="docId2" select="substring-before($figureLinkAfter1, '/')"/>
158 <xsl:variable name="figureLinkAfter2" select="substring-after($figureLinkAfter1, '/')"/>
159 <xsl:variable name="page" select="substring-before($figureLinkAfter2, '/')"/>
160 <xsl:variable name="figureFileName" select="substring-after($figureLinkAfter2, '/')"/>
161 <p></p>
162 <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>
163 <p></p>
164 Figure: <xsl:value-of select="$figureId"/>
165 <p></p>
166 </xsl:template>
167
168 <!-- Highlight all term occurrences for the fulltext query. It recognizes all text nodes and then does the highlighting -->
169 <xsl:template match="text()">
170 <xsl:choose>
171 <xsl:when test="$ftQueryMode != 'false'">
172 <xsl:variable name="queryExpr" select="$ftQueryName"/>
173 <xsl:call-template name="highlightQueryTerms">
174 <xsl:with-param name="elemTextContent" select="."/>
175 <xsl:with-param name="queryExprStr" select="$queryExpr"/>
176 <xsl:with-param name="mode" select="$ftQueryMode"/>
177 </xsl:call-template>
178 </xsl:when>
179 <xsl:otherwise>
180 <xsl:value-of select="."/>
181 </xsl:otherwise>
182 </xsl:choose>
183 </xsl:template>
184
185 <!-- Highlight term occurrences in one text node. It recognizes the first occorrence in a text node and then does
186 this template recursive with the first substring before the first term cut off -->
187 <xsl:template name="highlightQueryTerms">
188 <xsl:param name="elemTextContent"/>
189 <xsl:param name="queryExprStr"/>
190 <xsl:param name="mode"/>
191 <!-- Translation from Lucene fulltext query to text query -->
192 <xsl:variable name="textQuery">
193 <xsl:choose>
194 <xsl:when test="$mode = 'phrase'">
195 <xsl:value-of select="substring-before(substring-after($queryExprStr, '&quot;'), '&quot;')"/>
196 </xsl:when>
197 <xsl:when test="$mode = 'fakeWord'">
198 <xsl:value-of select="$queryExprStr"/>
199 </xsl:when>
200 <xsl:when test="$mode = 'word'">
201 <xsl:value-of select="$queryExprStr"/>
202 </xsl:when>
203 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
204 </xsl:choose>
205 </xsl:variable>
206 <!-- Word delimiter -->
207 <xsl:variable name="wordDelimRegExpr" select="'[\s,:\.^ ]+'"/>
208 <!-- Recognizes the beginning of the line with ^ and the substring up to the query term -->
209 <xsl:variable name="queryRegExprSubstringBefore">
210 <xsl:choose>
211 <xsl:when test="$mode = 'phrase'">
212 <xsl:value-of select="concat('^.*?', $textQuery)"/>
213 </xsl:when>
214 <xsl:when test="$mode = 'fakeWord'">
215 <xsl:value-of select="concat('^.*?', $textQuery)"/>
216 </xsl:when>
217 <xsl:when test="$mode = 'word'">
218 <xsl:value-of select="concat('^.*?', $wordDelimRegExpr, $textQuery, '(', $wordDelimRegExpr, ')')"/>
219 </xsl:when>
220 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
221 </xsl:choose>
222 </xsl:variable>
223 <!-- Recognizes the substring after the query term -->
224 <xsl:variable name="queryRegExprSubstringAfter">
225 <xsl:choose>
226 <xsl:when test="$mode = 'phrase'">
227 <xsl:value-of select="concat($textQuery, '.*')"/>
228 </xsl:when>
229 <xsl:when test="$mode = 'fakeWord'">
230 <xsl:value-of select="concat($textQuery, '.*')"/>
231 </xsl:when>
232 <xsl:when test="$mode = 'word'">
233 <xsl:value-of select="concat('(', $wordDelimRegExpr, ')', $textQuery, $wordDelimRegExpr, '.*')"/>
234 </xsl:when>
235 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
236 </xsl:choose>
237 </xsl:variable>
238 <!-- Deletes the substring up to the query term -->
239 <xsl:variable name="substringBefore" select="replace($elemTextContent, $queryRegExprSubstringAfter, '$1', 'i')"/>
240 <!-- Deletes the substring after the query term -->
241 <xsl:variable name="substringAfter" select="replace($elemTextContent, $queryRegExprSubstringBefore, '$1', 'i')"/>
242 <xsl:choose>
243 <xsl:when test="matches($elemTextContent, $queryRegExprSubstringBefore, 'i')">
244 <!-- Prints the original part of the substring up to the first occurrence of the query term -->
245 <xsl:value-of select="$substringBefore"/>
246 <!-- Highlight the query term -->
247 <xsl:variable name="matchQueryTermRegExpr">
248 <xsl:choose>
249 <xsl:when test="$mode = 'phrase'">
250 <xsl:value-of select="concat('^.*?', '(', $textQuery, ')', '.*')"/>
251 </xsl:when>
252 <xsl:when test="$mode = 'fakeWord'">
253 <xsl:value-of select="concat('^.*?', '(', $textQuery, ')', '.*')"/>
254 </xsl:when>
255 <xsl:when test="$mode = 'word'">
256 <xsl:value-of select="concat('^.*?', $wordDelimRegExpr, '(', $textQuery, ')', $wordDelimRegExpr, '.*')"/>
257 </xsl:when>
258 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
259 </xsl:choose>
260 </xsl:variable>
261 <xsl:variable name="matchQueryTerm" select="replace($elemTextContent, $matchQueryTermRegExpr, '$1', 'i')"/>
262 <span style="background-color: yellow;">
263 <xsl:value-of select="$matchQueryTerm"/>
264 </span>
265 <!-- Recursive call of this template with the substring after the first occurrence of the term: further occurrences of the query
266 term -->
267 <xsl:call-template name="highlightQueryTerms">
268 <xsl:with-param name="elemTextContent" select="$substringAfter"/>
269 <xsl:with-param name="queryExprStr" select="$queryExprStr"/>
270 <xsl:with-param name="mode" select="$mode"/>
271 </xsl:call-template>
272 </xsl:when>
273 <!-- if no occurrence of the query term could be found the whole string is printed -->
274 <xsl:otherwise>
275 <xsl:value-of select="$elemTextContent"/>
276 </xsl:otherwise>
277 </xsl:choose>
278 </xsl:template>
279
280
281 </xsl:stylesheet>