source: greenstone3/trunk/web/interfaces/classic/transform/query-common.xsl@ 14385

Last change on this file since 14385 was 14385, checked in by anna, 14 years ago

Changed paramList template so that don't generate the search level drop down list if the level param is invisible. Added namespace prefix in hidden placeholder of a param in the param(multi, contents) template, to make the AdvancedFieldSearch work.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 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 extension-element-prefixes="java util"
7 exclude-result-prefixes="java util">
8
9 <!--<xsl:include href="service-params.xsl"/>-->
10 <xsl:template match="service">
11 <xsl:param name="collName"/>
12 <xsl:variable name="subaction" select="../pageRequest/@subaction"/>
13 <div class="queryform">
14 <p>
15 <form name="QueryForm" method="get" action="{$library_name}">
16 <input type="hidden" name="a" value="q"/>
17 <input type="hidden" name="sa" value="{$subaction}"/>
18 <input type="hidden" name="rt" value="rd"/>
19 <input type="hidden" name="s" value="{@name}"/>
20 <input type="hidden" name="c" value="{$collName}"/>
21 <input type="hidden" name="startPage" value="1"/>
22 <xsl:apply-templates select="paramList"/>
23 </form>
24 </p>
25 </div>
26 </xsl:template>
27
28 <!-- a special handling of the param list - we override the one in service-params -->
29 <xsl:template match="paramList" priority='2'>
30 <span class="textselect">
31 Search for <xsl:apply-templates select="param[@name='index']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='index']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates><xsl:if test="param[@name='level' and not(@type='invisible')]">at <xsl:apply-templates select="param[@name='level']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='level']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> level</xsl:if><xsl:call-template name='query_mode'/>
32 </span>
33 <span class="querybox">
34 <xsl:call-template name="query-and-submit"/>
35 </span>
36 </xsl:template>
37
38 <!-- new template for match mode -->
39 <xsl:template name='query_mode'>
40 <xsl:variable name="qt" select="/page/pageRequest/paramList/param[@name='qt']/@value"/>
41 <xsl:choose>
42 <xsl:when test="$qt=1">
43 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
44 <xsl:choose>
45 <xsl:when test="$qfm=1">
46 and display results in <xsl:apply-templates select="param[@name='sortBy']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='sortBy']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> order
47 </xsl:when>
48 <xsl:otherwise>
49 which contain <xsl:apply-templates select="param[@name='matchMode']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='matchMode']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> of
50 </xsl:otherwise>
51 </xsl:choose>
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:variable name="ct" select="/page/pageRequest/paramList/param[@name='ct']/@value"/>
55 <xsl:variable name="qm" select="/page/pageRequest/paramList/param[@name='qm']/@value"/>
56 <xsl:choose>
57 <xsl:when test="$qm=1 and $ct=0">
58 using ranked/bool query
59 </xsl:when>
60 <xsl:when test="$qm=1 and $ct=1">
61 and display results in <xsl:apply-templates select="param[@name='sortBy']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='sortBy']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> order
62 </xsl:when>
63 <xsl:otherwise>
64 which contain <xsl:apply-templates select="param[@name='matchMode']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='matchMode']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> of the words
65 </xsl:otherwise>
66 </xsl:choose>
67 </xsl:otherwise>
68 </xsl:choose>
69 </xsl:template>
70
71 <xsl:template match="param[@name='matchMode']" mode='query1'>
72 <xsl:param name='default'/>
73 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
74 <xsl:choose>
75 <xsl:when test="$qfm=1">
76 and display results in <xsl:apply-templates select="../param[@name='sortBy']"><xsl:with-param name="default" select="$default"/></xsl:apply-templates> order
77 </xsl:when>
78 <xsl:otherwise>
79 which contain <xsl:apply-templates select='.'><xsl:with-param name="default" select="$default"/></xsl:apply-templates> of the words
80 </xsl:otherwise>
81 </xsl:choose>
82 </xsl:template>
83
84 <xsl:template name="query-and-submit">
85 <xsl:variable name="qt" select="/page/pageRequest/paramList/param[@name='qt']/@value"/>
86 <xsl:choose>
87 <xsl:when test="$qt=1"> <!-- doing form query -->
88 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
89 <xsl:choose>
90 <xsl:when test="$qfm=1">
91 <xsl:apply-templates select="param[@name='complexField']"/>
92 </xsl:when>
93 <xsl:otherwise>
94 <xsl:apply-templates select="param[@name='simpleField']"/>
95 </xsl:otherwise>
96 </xsl:choose>
97 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input>
98
99 </xsl:when>
100 <xsl:otherwise> <!-- doing text query -->
101 <xsl:variable name="qb" select="/page/pageRequest/paramList/param[@name='qb']/@value"/>
102 <xsl:choose>
103 <xsl:when test="$qb=1"><!-- large query box -->
104 <textarea name="query" cols='63' rows='10'>
105 <xsl:apply-templates select="param[@name='query']" mode="calculate-default"/><xsl:text> </xsl:text><!-- put a space here just in case there is no value- mozilla craps out if have a <textarea /> element -->
106 </textarea>
107 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input>
108 </xsl:when>
109 <xsl:otherwise>
110 <xsl:variable name="qs"><xsl:apply-templates select="param[@name='query']" mode="calculate-default"/></xsl:variable>
111 <nobr><xsl:apply-templates select="param[@name='query']"><xsl:with-param name="default" select="java:org.greenstone.gsdl3.util.XSLTUtil.tidyWhitespace($qs)"/></xsl:apply-templates><input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input></nobr>
112 </xsl:otherwise>
113 </xsl:choose>
114 </xsl:otherwise>
115 </xsl:choose>
116 </xsl:template>
117
118 <!-- overwrite the multi param to use our value of occurs, not the one with the param -->
119 <xsl:template match="param[@type='multi']" priority='2'>
120 <xsl:variable name="parent" select="@name"/>
121 <table>
122 <tr>
123 <xsl:for-each select="param">
124 <xsl:variable name='pname' select='@name'/>
125 <td><xsl:value-of select="displayItem[@name='name']"/></td>
126 </xsl:for-each>
127 </tr>
128 <!-- the number of times to display this is the qfn variable -->
129 <xsl:variable name="numbox"><xsl:choose><xsl:when test="/page/pageRequest/paramList/param[@name='qfn']"><xsl:value-of select="/page/pageRequest/paramList/param[@name='qfn']/@value"/></xsl:when><xsl:otherwise>4</xsl:otherwise></xsl:choose></xsl:variable>
130 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$numbox"/><xsl:with-param name="pos" select="0"/></xsl:apply-templates>
131 </table>
132 </xsl:template>
133
134 <xsl:template match="param[@type='multi']" mode="contents">
135 <xsl:param name="occurs"/>
136 <xsl:param name="ns">s1.</xsl:param>
137 <xsl:param name="pos"/>
138 <!-- <xsl:variable name="pos" select="@occurs - $occurs"/>-->
139 <tr><xsl:for-each select="param">
140 <xsl:variable name="pname" select="@name"/>
141 <xsl:variable name="values" select="/page/pageRequest/paramList/param[@name=$pname]/@value"/>
142 <td><xsl:choose>
143 <xsl:when test="not(@ignore) or @ignore != $pos">
144 <xsl:apply-templates select='.'><xsl:with-param name="default" select="java:org.greenstone.gsdl3.util.XSLTUtil.getNumberedItem($values, $pos)"/></xsl:apply-templates>
145 </xsl:when>
146 <xsl:otherwise><!-- put in a hidden placeholder -->
147 <input type="hidden" name='{$ns}{@name}' value=''/>
148 </xsl:otherwise>
149 </xsl:choose></td>
150 </xsl:for-each></tr>
151 <!-- recursively call this template to get multiple entries -->
152 <xsl:if test="$pos &lt; ($occurs - 1)">
153 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$occurs"/><xsl:with-param name="pos" select="$pos+1"/></xsl:apply-templates>
154 </xsl:if>
155 </xsl:template>
156
157</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.