source: main/trunk/greenstone3/web/interfaces/oran/transform/pages/query.xsl@ 24727

Last change on this file since 24727 was 24727, checked in by davidb, 13 years ago

Restructured template rule to be more in line with the 'match=documentNode' form used in browsing and document display

File size: 18.6 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:java="http://xml.apache.org/xslt/java"
5 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6 xmlns:gslib="http://www.greenstone.org/skinning"
7 extension-element-prefixes="java util"
8 exclude-result-prefixes="java util">
9
10 <!-- use the 'main' layout -->
11 <xsl:include href="layouts/main.xsl"/>
12
13 <!-- set page title -->
14 <xsl:template name="pageTitle"><gslib:serviceName/></xsl:template>
15
16 <!-- set page breadcrumbs -->
17 <xsl:template name="breadcrumbs"> <gslib:siteLink/><gslib:rightArrow/><xsl:if test="/page/pageResponse/collection"> <gslib:collectionNameLinked/><gslib:rightArrow/></xsl:if></xsl:template>
18
19 <!-- the page content -->
20 <xsl:template match="/page">
21 <xsl:choose>
22 <xsl:when test="not(pageResponse/documentNodeList)">
23 <xsl:for-each select="pageResponse/service">
24 <form name="QueryForm" method="get" action="{$library_name}">
25 <div>
26 <input type="hidden" name="a" value="q"/>
27 <input type="hidden" name="sa"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/@subaction"/></xsl:attribute></input>
28 <input type="hidden" name="rt" value="rd"/>
29 <input type="hidden" name="s" value="{@name}"/>
30 <input type="hidden" name="c" value="{$collName}"/>
31 <xsl:if test="not(paramList/param[@name='startPage'])">
32 <input type="hidden" name="startPage" value="1"/>
33 </xsl:if>
34 <xsl:choose>
35 <xsl:when test="/page/pageRequest/paramList/param[@name = 's1.maxDocs']">
36 <input type="hidden" name="s1.maxDocs">
37 <xsl:attribute name="value">
38 <xsl:value-of select="/page/pageRequest/paramList/param[@name = 's1.maxDocs']/@value"/>
39 </xsl:attribute>
40 </input>
41 </xsl:when>
42 <xsl:otherwise>
43 <input type="hidden" name="s1.maxDocs" value="100"/>
44 </xsl:otherwise>
45 </xsl:choose>
46 <xsl:choose>
47 <xsl:when test="/page/pageRequest/paramList/param[@name = 's1.hitsPerPage']">
48 <input type="hidden" name="s1.hitsPerPage">
49 <xsl:attribute name="value">
50 <xsl:value-of select="/page/pageRequest/paramList/param[@name = 's1.hitsPerPage']/@value"/>
51 </xsl:attribute>
52 </input>
53 </xsl:when>
54 <xsl:otherwise>
55 <input type="hidden" name="s1.hitsPerPage" value="20"/>
56 </xsl:otherwise>
57 </xsl:choose>
58
59 <xsl:variable name="ns">s1.</xsl:variable>
60 <xsl:for-each select="paramList/param">
61 <xsl:choose>
62 <xsl:when test="@name='case' or @name='stem' or @name='accent'">
63 </xsl:when>
64 <xsl:when test="@type='multi'">
65 <xsl:apply-templates select="."><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates>
66 </xsl:when>
67 <xsl:when test="@name = 'maxDocs' or @name = 'hitsPerPage'"></xsl:when>
68 <xsl:otherwise>
69 <xsl:variable name="pvalue"><xsl:apply-templates select="." mode="calculate-default"><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates></xsl:variable>
70 <div class="paramLabel"><xsl:value-of select="displayItem[@name='name']"/></div>
71 <div class="paramValue">
72 <xsl:apply-templates select=".">
73 <xsl:with-param name="default" select="$pvalue"/>
74 <xsl:with-param name="ns" select="$ns"/>
75 </xsl:apply-templates>
76 </div>
77 <br class="clear"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 </xsl:for-each>
81
82 <br/>
83
84 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="displayItem[@name='submit']"/></xsl:attribute></input>
85
86 </div>
87 </form>
88 </xsl:for-each>
89 </xsl:when>
90
91 <xsl:otherwise>
92 <!-- The list of search terms with their frequency and document count -->
93 <p class="termList">
94 <xsl:if test="count(/page/pageResponse/termList/stopword) &gt; 0">
95 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.common')"/><xsl:text> </xsl:text>
96 </xsl:if>
97
98 <xsl:for-each select="/page/pageResponse/termList/stopword">
99 <span style="font-style:italic;"><xsl:value-of select="@name"/></span><xsl:text> </xsl:text>
100 </xsl:for-each>
101 <br /><br />
102
103 <xsl:for-each select="/page/pageResponse/termList/term">
104 <xsl:choose>
105 <!-- If there is only one or two search terms then show the expanded information -->
106 <xsl:when test="count(/page/pageResponse/termList/term) &lt; 3">
107 <span style="font-style:italic;"><xsl:value-of select="@name"/></span>
108 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.occurs')"/><xsl:text> </xsl:text>
109 <xsl:value-of select="@freq"/>
110 <xsl:choose>
111 <xsl:when test="@freq = 1">
112 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.time')"/>
113 </xsl:when>
114 <xsl:otherwise>
115 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.time_plural')"/>
116 </xsl:otherwise>
117 </xsl:choose>
118 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.in')"/><xsl:text> </xsl:text>
119 <xsl:value-of select="@numDocsMatch"/>
120 <xsl:choose>
121 <xsl:when test="@numDocsMatch = 1">
122 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.document')"/>
123 </xsl:when>
124 <xsl:otherwise>
125 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.document_plural')"/>
126 </xsl:otherwise>
127 </xsl:choose>
128 <br />
129 </xsl:when>
130 <xsl:otherwise>
131 <span style="font-style:italic;"><xsl:value-of select="@name"/></span> (<xsl:value-of select="@freq"/>)
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:for-each>
135 </p>
136
137 <!-- <ul id="results"> -->
138 <table id="results">
139 <xsl:for-each select="pageResponse/documentNodeList/documentNode">
140
141 <tr class="document">
142
143 <xsl:apply-templates select="."/>
144 </tr>
145<!--
146
147 <li class="document">
148 <a>
149 <xsl:choose>
150 <xsl:when test="/page/pageResponse/collection/@name">
151 <xsl:attribute name="href"><xsl:value-of select="$library_name"/>?a=d&amp;c=<xsl:value-of select="/page/pageResponse/collection/@name"/>&amp;d=<xsl:value-of select="@nodeID"/>&amp;dt=<xsl:value-of select="@docType"/>&amp;p.a=q&amp;p.s=<xsl:value-of select="/page/pageResponse/service/@name"/>&amp;hl=on&amp;ed=1#<xsl:value-of select="@nodeID"/></xsl:attribute>
152 </xsl:when>
153 <xsl:when test="@collection">
154 <xsl:attribute name="href"><xsl:value-of select="$library_name"/>?a=d&amp;c=<xsl:value-of select="@collection"/>&amp;d=<xsl:value-of select="@nodeID"/>&amp;dt=<xsl:value-of select="@docType"/>&amp;p.a=q&amp;p.s=<xsl:value-of select="/page/pageResponse/service/@name"/>&amp;hl=on&amp;ed=1#<xsl:value-of select="@nodeID"/></xsl:attribute>
155 </xsl:when>
156 </xsl:choose>
157
158 <xsl:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='Title']"/>
159 </a>
160 ***** -->
161 <!-- If this is results from a cross collection search then add a link to the collection that it is from --><!--
162 <xsl:if test="@collection">
163 (<a style="background-image:none; padding:3px;">
164 <xsl:attribute name="href">
165 <xsl:value-of select="$library_name"/>?a=p&amp;sa=about&amp;c=<xsl:value-of select="@collection"/>
166 </xsl:attribute>
167 <xsl:value-of select="@collection"/>
168 </a>)
169 </xsl:if>
170 <xsl:call-template name="documentBerryForClassifierOrSearchPage"/>
171 </li>
172-->
173
174 </xsl:for-each>
175 <br/>
176
177 <!-- Previous/Next buttons-->
178 <xsl:call-template name="prevNextButtons"/>
179 </table>
180 <!-- </ul> -->
181
182 </xsl:otherwise>
183
184 </xsl:choose>
185
186 </xsl:template>
187
188 <xsl:template name="prevNextButtons">
189 <!-- Current page -->
190 <xsl:variable name="currentPage">
191 <xsl:choose>
192 <xsl:when test="/page/pageRequest/paramList/param[@name='startPage']/@value">
193 <xsl:value-of select="/page/pageRequest/paramList/param[@name='startPage']/@value" />
194 </xsl:when>
195 <xsl:when test="/page/pageRequest/paramList/param[@name='s1.startPage']/@value">
196 <xsl:value-of select="/page/pageRequest/paramList/param[@name='s1.startPage']/@value" />
197 </xsl:when>
198 <xsl:otherwise>1</xsl:otherwise>
199 </xsl:choose>
200 </xsl:variable>
201
202 <!-- Find the total number of documents returned -->
203 <xsl:variable name="docMax">
204 <xsl:choose>
205 <xsl:when test="/page/pageResponse/metadataList/metadata[@name = 'numDocsReturned']">
206 <xsl:value-of select="/page/pageResponse/metadataList/metadata[@name = 'numDocsReturned']"/>
207 </xsl:when>
208 <xsl:when test="/page/pageResponse/metadataList/metadata[@name = 'numDocsMatched']">
209 <xsl:value-of select="/page/pageResponse/metadataList/metadata[@name = 'numDocsMatched']"/>
210 </xsl:when>
211 <xsl:otherwise><xsl:value-of select="count(/page/pageResponse/documentNodeList/documentNode)"/></xsl:otherwise>
212 </xsl:choose>
213 </xsl:variable>
214
215 <!-- Find the number of documents displayed per page -->
216 <xsl:variable name="docsPerPage">
217 <xsl:choose>
218 <xsl:when test="/page/pageRequest/paramList/param[@name='hitsPerPage']">
219 <xsl:value-of select="/page/pageRequest/paramList/param[@name='hitsPerPage']/@value" />
220 </xsl:when>
221 <xsl:when test="/page/pageRequest/paramList/param[@name='s1.hitsPerPage']">
222 <xsl:value-of select="/page/pageRequest/paramList/param[@name='s1.hitsPerPage']/@value" />
223 </xsl:when>
224 <xsl:otherwise>20</xsl:otherwise>
225 </xsl:choose>
226 </xsl:variable>
227
228 <table id="searchResultNavTable"><tr>
229 <!-- Previous button -->
230 <td id="prevArrowTD">
231 <xsl:if test="$currentPage != 1">
232 <a href="{$library_name}?a=q&amp;sa={/page/pageRequest/@subaction}&amp;c={$collName}&amp;s={/page/pageResponse/service/@name}&amp;rt=rd&amp;startPage={$currentPage - 1}">
233 <img src="interfaces/oran/images/previous.png"/>
234 </a>
235 </xsl:if>
236 </td>
237 <td id="prevTD">
238 <xsl:if test="$currentPage != 1">
239 <a href="{$library_name}?a=q&amp;sa={/page/pageRequest/@subaction}&amp;c={$collName}&amp;s={/page/pageResponse/service/@name}&amp;rt=rd&amp;startPage={$currentPage - 1}">Previous</a>
240 </xsl:if>
241 </td>
242
243 <!-- Search result status bar (in english it reads "Displaying X to Y of Z documents") -->
244 <xsl:if test="$docMax &gt; 0">
245 <td id="searchResultsStatusBar">
246 <!-- "Displaying" -->
247 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.displaying')"/><xsl:text> </xsl:text>
248 <!-- "X" -->
249 <xsl:value-of select="($currentPage - 1) * $docsPerPage + 1"/>
250 <!-- "to" -->
251 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.to')"/><xsl:text> </xsl:text>
252 <!-- "Y" -->
253 <xsl:choose>
254 <xsl:when test="($currentPage * $docsPerPage + 1) &gt; $docMax">
255 <xsl:value-of select="$docMax"/>
256 </xsl:when>
257 <xsl:otherwise>
258 <xsl:value-of select="$currentPage * $docsPerPage"/>
259 </xsl:otherwise>
260 </xsl:choose>
261 <!-- "of" -->
262 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.of')"/><xsl:text> </xsl:text>
263 <!-- "Z" -->
264 <xsl:value-of select="$docMax"/>
265 <!-- "document[s]"-->
266 <xsl:choose>
267 <xsl:when test="$docMax = 1">
268 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.document')"/>
269 </xsl:when>
270 <xsl:otherwise>
271 <xsl:text> </xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.document_plural')"/>
272 </xsl:otherwise>
273 </xsl:choose>
274 </td>
275 </xsl:if>
276
277 <!-- Next button -->
278 <td id="nextTD">
279 <xsl:if test="($currentPage * $docsPerPage + 1) &lt; $docMax">
280 <a href="{$library_name}?a=q&amp;sa={/page/pageRequest/paramList/param[@name = 'sa']/@value}&amp;c={$collName}&amp;s={/page/pageResponse/service/@name}&amp;rt=rd&amp;startPage={$currentPage + 1}">Next</a>
281 </xsl:if>
282 </td>
283 <td id="nextArrowTD">
284 <xsl:if test="($currentPage * $docsPerPage + 1) &lt; $docMax">
285 <a href="{$library_name}?a=q&amp;sa={/page/pageRequest/paramList/param[@name = 'sa']/@value}&amp;c={$collName}&amp;s={/page/pageResponse/service/@name}&amp;rt=rd&amp;startPage={$currentPage + 1}">
286 <img src="interfaces/oran/images/next.png"/>
287 </a>
288 </xsl:if>
289 </td>
290 </tr></table>
291 </xsl:template>
292
293 <!-- puts all the params into a=p&p=h type form - need to change this if use
294 multi params -->
295 <xsl:template match="paramList" mode="cgi">
296 <xsl:param name="ns">s1.</xsl:param>
297 <xsl:for-each select="param">
298 <xsl:variable name='pname' select="@name"/>
299 <xsl:text>&amp;</xsl:text><xsl:value-of select="$ns"/><xsl:value-of select="@name"/>=<xsl:apply-templates select="." mode="calculate-default"><xsl:with-param name='ns' select='$ns'/></xsl:apply-templates>
300 </xsl:for-each>
301 </xsl:template>
302
303 <xsl:template match="param" mode="calculate-default">
304 <xsl:param name="ns">s1.</xsl:param>
305 <xsl:variable name="pname"><xsl:value-of select="$ns"/><xsl:value-of select="@name"/></xsl:variable>
306 <xsl:choose>
307 <xsl:when test="/page/pageRequest/paramList/param[@name=$pname]">
308 <xsl:choose>
309 <xsl:when test="@type='enum_multi'"><xsl:text>,</xsl:text>
310 <xsl:for-each select="/page/pageRequest/paramList/param[@name=$pname]">
311 <xsl:value-of select="@value"/>,
312 </xsl:for-each>
313 </xsl:when>
314 <xsl:otherwise>
315 <xsl:value-of select="/page/pageRequest/paramList/param[@name=$pname]/@value"/>
316 </xsl:otherwise>
317 </xsl:choose>
318 </xsl:when>
319 <xsl:otherwise>
320 <xsl:value-of select="@default"/>
321 </xsl:otherwise>
322 </xsl:choose>
323 </xsl:template>
324
325 <!-- invisible params - used by other stuff. in the query form, we set to the default -->
326 <xsl:template match="param[@type='invisible']">
327 <xsl:param name="ns">s1.</xsl:param>
328 <input type='hidden' name='{$ns}{@name}' value='{@default}'/>
329 </xsl:template>
330
331 <!-- boolean params -->
332 <xsl:template match="param[@type='boolean']">
333 <xsl:param name="ns">s1.</xsl:param>
334 <xsl:param name="default"/>
335 <select name='{$ns}{@name}'>
336 <option value="0"><xsl:if test="$default='0'"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="option[@name='0']/displayItem[@name='name']"/></option>
337 <option value="1"><xsl:if test="$default='1'"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="option[@name='1']/displayItem[@name='name']"/></option>
338 </select>
339 </xsl:template>
340
341 <!-- integer params -->
342 <xsl:template match="param[@type='integer']">
343 <xsl:param name="ns">s1.</xsl:param>
344 <xsl:param name="default"/>
345 <input type="text" name="{$ns}{@name}" size="3" value="{$default}"/>
346 </xsl:template>
347
348 <!-- single selection enum params -->
349 <xsl:template match="param[@type='enum_single']">
350 <xsl:param name="ns">s1.</xsl:param>
351 <xsl:param name="default"/>
352 <xsl:choose>
353 <xsl:when test="count(option) = 1">
354 <xsl:value-of select="option/displayItem[@name='name']"/>
355 <input type='hidden' name='{$ns}{@name}'><xsl:attribute name='value'><xsl:value-of select='option/@name'/></xsl:attribute></input>
356 </xsl:when>
357 <xsl:otherwise>
358 <select name="{$ns}{@name}">
359 <xsl:for-each select="option">
360 <option value="{@name}"><xsl:if test="@name=$default"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="displayItem[@name='name']"/></option>
361 </xsl:for-each>
362 </select>
363 </xsl:otherwise>
364 </xsl:choose>
365 </xsl:template>
366
367
368 <!-- multiple selection enum params -->
369 <!-- how to do defaults for this?? -->
370 <xsl:template match="param[@type='enum_multi']">
371 <xsl:param name="ns">s1.</xsl:param>
372 <xsl:param name="default"/>
373 <select name="{$ns}{@name}" size="2">
374 <xsl:attribute name="multiple"></xsl:attribute>
375 <xsl:for-each select="option">
376 <option value="{@name}"><xsl:if test="contains($default, concat(',', @name, ','))"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="displayItem[@name='name']"/></option>
377 </xsl:for-each>
378 </select>
379 </xsl:template>
380
381 <!-- string params -->
382 <xsl:template match="param[@type='string']">
383 <xsl:param name="ns">s1.</xsl:param>
384 <xsl:param name="default"/>
385 <input type="text" name="{$ns}{@name}" size="30" value="{$default}"/>
386 </xsl:template>
387
388 <!-- large string params -->
389 <xsl:template match="param[@type='text']">
390 <xsl:param name="ns">s1.</xsl:param>
391 <xsl:param name="default"/>
392 <textarea name="{$ns}{@name}" cols="50" rows="3"><xsl:value-of select='$default'/></textarea>
393 </xsl:template>
394
395 <!-- multi params - params that are combinations of other params -->
396 <xsl:template match="param[@type='multi']">
397 <xsl:param name="ns">s1.</xsl:param>
398 <xsl:variable name="parent" select="@name"/>
399
400 <table>
401 <tr class="queryfieldheading">
402 <xsl:value-of select="displayItem[@name='name']"/>
403 <xsl:for-each select="param">
404 <td class="queryfieldname"><xsl:value-of select="displayItem[@name='name']"/></td>
405 </xsl:for-each>
406 </tr>
407 <xsl:apply-templates select="." mode="contents">
408 <xsl:with-param name="occurs" select="@occurs"/>
409 <xsl:with-param name="ns" select="$ns"/>
410 </xsl:apply-templates>
411 </table>
412
413 </xsl:template>
414
415 <xsl:template match="param[@type='multi']" mode="contents">
416 <xsl:param name="ns">s1.</xsl:param>
417 <xsl:param name="occurs">1</xsl:param>
418 <xsl:variable name="pos" select="@occurs - $occurs"/>
419 <tr class="queryfieldrow">
420 <xsl:for-each select="param">
421 <xsl:variable name="pname" select="@name"/>
422 <xsl:variable name="values" select="/page/pageRequest/paramList/param[@name=$pname]/@value"/>
423 <td class="queryfieldcell">
424 <xsl:choose>
425 <xsl:when test="not(@ignore) or @ignore != $pos">
426 <xsl:apply-templates select="."><xsl:with-param name="default" select="java:org.greenstone.gsdl3.util.XSLTUtil.getNumberedItem($values, $pos)"/><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates>
427 </xsl:when>
428 <xsl:otherwise><!-- put in a hidden placeholder -->
429 <input type="hidden" name='{$ns}{@name}' value=''/>
430 </xsl:otherwise>
431 </xsl:choose>
432 </td>
433 </xsl:for-each>
434 </tr>
435
436 <!-- recursively call this template to get multiple entries -->
437 <xsl:if test="$occurs &gt; 1">
438 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$occurs - 1"/><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates>
439 </xsl:if>
440 </xsl:template>
441
442</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.