source: greenstone3/trunk/web/interfaces/gs2/transform/query-common.xsl@ 20631

Last change on this file since 20631 was 20631, checked in by oranfry, 14 years ago

changed xml whitespace for readability

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