source: other-projects/tipple-android/i-greenstone-server-files/greenstone/webapps/greenstone3/interfaces/gs2/transform/query-common.xsl@ 26899

Last change on this file since 26899 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

  • Property svn:mime-type set to application/xml
File size: 10.0 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 <xsl:choose>
31 <xsl:when test="/page/pageResponse/collection/@type = 'lucene'">
32 <span class="textselect">
33 Search in
34 <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>
35 <xsl:if test="param[@name='indexSubcollection']">
36 of <xsl:apply-templates select="param[@name='indexSubcollection']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexSubcollection']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates>
37 </xsl:if>
38 <xsl:if test="param[@name='indexLanguage']">
39 in <xsl:apply-templates select="param[@name='indexLanguage']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexLanguage']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates>
40 </xsl:if>
41 <xsl:if test="param[@name='sortBy']">
42 , sorting results by <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>
43 </xsl:if>
44
45 <xsl:call-template name='query_mode'/>
46 </span>
47 </xsl:when>
48 <xsl:otherwise>
49 <span class="textselect">
50 Search for
51 <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>
52 <xsl:if test="param[@name='indexSubcollection']">
53 of <xsl:apply-templates select="param[@name='indexSubcollection']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexSubcollection']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates>
54 </xsl:if>
55 <xsl:if test="param[@name='indexLanguage']">
56 in <xsl:apply-templates select="param[@name='indexLanguage']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexLanguage']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates>
57 </xsl:if>
58
59 <xsl:if test="param[@name='level' and not(@type='invisible')]">
60 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
61 </xsl:if>
62
63 <xsl:call-template name='query_mode'/>
64
65 </span>
66 </xsl:otherwise>
67 </xsl:choose>
68 <span class="querybox">
69 <xsl:call-template name="query-and-submit"/>
70 </span>
71 </xsl:template>
72
73 <!-- new template for match mode -->
74 <xsl:template name='query_mode'>
75 <xsl:variable name="qt" select="/page/pageRequest/paramList/param[@name='qt']/@value"/>
76 <xsl:choose>
77 <xsl:when test="$qt=1">
78 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
79 <xsl:choose>
80 <xsl:when test="$qfm=1">
81 <!-- 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 -->
82 </xsl:when>
83 <xsl:otherwise>
84 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
85 </xsl:otherwise>
86 </xsl:choose>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:variable name="ct" select="/page/pageRequest/paramList/param[@name='ct']/@value"/>
90 <xsl:variable name="qm" select="/page/pageRequest/paramList/param[@name='qm']/@value"/>
91 <xsl:choose>
92 <xsl:when test="$qm=1 and $ct=0">
93 using ranked/bool query
94 </xsl:when>
95 <xsl:when test="$qm=1 and $ct=1">
96 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
97 </xsl:when>
98 <xsl:otherwise>
99 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
100 </xsl:otherwise>
101 </xsl:choose>
102 </xsl:otherwise>
103 </xsl:choose>
104 </xsl:template>
105
106 <xsl:template match="param[@name='matchMode']" mode='query1'>
107 <xsl:param name='default'/>
108 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
109 <xsl:choose>
110 <xsl:when test="$qfm=1">
111 and display results in <xsl:apply-templates select="../param[@name='sortBy']"><xsl:with-param name="default" select="$default"/></xsl:apply-templates> order
112 </xsl:when>
113 <xsl:otherwise>
114 which contain <xsl:apply-templates select='.'><xsl:with-param name="default" select="$default"/></xsl:apply-templates> of the words
115 </xsl:otherwise>
116 </xsl:choose>
117 </xsl:template>
118
119 <xsl:template name="query-and-submit">
120 <xsl:variable name="qt" select="/page/pageRequest/paramList/param[@name='qt']/@value"/>
121 <xsl:choose>
122 <xsl:when test="$qt=1"> <!-- doing form query -->
123 <xsl:variable name="qfm" select="/page/pageRequest/paramList/param[@name='qfm']/@value"/>
124 <xsl:choose>
125 <xsl:when test="$qfm=1">
126 <xsl:apply-templates select="param[@name='complexField']"/>
127 </xsl:when>
128 <xsl:otherwise>
129 <xsl:apply-templates select="param[@name='simpleField']"/>
130 </xsl:otherwise>
131 </xsl:choose>
132 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input>
133
134 </xsl:when>
135 <xsl:otherwise> <!-- doing text query -->
136 <xsl:variable name="qb" select="/page/pageRequest/paramList/param[@name='qb']/@value"/>
137 <xsl:choose>
138 <xsl:when test="$qb=1"><!-- large query box -->
139 <textarea name="s1.query" cols='63' rows='10'>
140 <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 -->
141 </textarea>
142 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input>
143 </xsl:when>
144 <xsl:otherwise>
145 <xsl:variable name="qs"><xsl:apply-templates select="param[@name='query']" mode="calculate-default"/></xsl:variable>
146 <nobr><xsl:apply-templates select="param[@name='query']"><xsl:with-param name="default" select="java:org.greenstone.gsdl3.util.XSLTUtil.tidyWhitespace($qs,/page/@lang)"/></xsl:apply-templates><input type="submit"><xsl:attribute name="value"><xsl:value-of select="../displayItem[@name='submit']"/></xsl:attribute></input></nobr>
147 </xsl:otherwise>
148 </xsl:choose>
149 </xsl:otherwise>
150 </xsl:choose>
151 </xsl:template>
152
153 <!-- overwrite the multi param to use our value of occurs, not the one with the param -->
154 <xsl:template match="param[@type='multi']" priority='2'>
155 <xsl:variable name="parent" select="@name"/>
156 <table>
157 <tr>
158 <xsl:for-each select="param">
159 <xsl:variable name='pname' select='@name'/>
160 <td><xsl:value-of select="displayItem[@name='name']"/></td>
161 </xsl:for-each>
162 </tr>
163 <!-- the number of times to display this is the qfn variable -->
164 <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>
165 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$numbox"/><xsl:with-param name="pos" select="0"/></xsl:apply-templates>
166 </table>
167 </xsl:template>
168
169 <xsl:template match="param[@type='multi']" mode="contents">
170 <xsl:param name="occurs"/>
171 <xsl:param name="ns">s1.</xsl:param>
172 <xsl:param name="pos"/>
173 <!-- <xsl:variable name="pos" select="@occurs - $occurs"/>-->
174 <tr><xsl:for-each select="param">
175 <xsl:variable name="pname" select="@name"/>
176 <xsl:variable name="values" select="/page/pageRequest/paramList/param[@name=concat($ns,$pname)]/@value"/>
177 <td><xsl:choose>
178 <xsl:when test="not(@ignore) or @ignore != $pos">
179 <xsl:apply-templates select='.'><xsl:with-param name="default" select="java:org.greenstone.gsdl3.util.XSLTUtil.getNumberedItem($values, $pos)"/></xsl:apply-templates>
180 </xsl:when>
181 <xsl:otherwise><!-- put in a hidden placeholder -->
182 <input type="hidden" name='{$ns}{@name}' value=''/>
183 </xsl:otherwise>
184 </xsl:choose></td>
185 </xsl:for-each></tr>
186 <!-- recursively call this template to get multiple entries -->
187 <xsl:if test="$pos &lt; ($occurs - 1)">
188 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$occurs"/><xsl:with-param name="pos" select="$pos+1"/></xsl:apply-templates>
189 </xsl:if>
190 </xsl:template>
191
192</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.