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

Last change on this file since 19856 was 19856, checked in by oranfry, 15 years ago

reorganising transform for new interface

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 xmlns:gslib="http://www.greenstone.org/skinning"
7 extension-element-prefixes="java util"
8 exclude-result-prefixes="java util">
9
10 <!-- make this page use the 'main' layout -->
11 <xsl:include href="layouts/main.xsl"/>
12
13 <!-- set page title and subtitle-->
14 <xsl:template name="title"><gslib:aboutCollectionPageTitle/></xsl:template>
15 <xsl:template name="linked-title"><a href=""><gslib:aboutCollectionPageTitle/></a></xsl:template>
16
17 <!-- the main page layout template is here -->
18 <xsl:template match="/page/pageResponse/service">
19
20 <form name="QueryForm" method="get" action="{$library_name}">
21 <div>
22 <input type="hidden" name="a" value="q"/>
23 <input type="hidden" name="sa"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/@subaction"/></xsl:attribute></input>
24 <input type="hidden" name="rt" value="rd"/>
25 <input type="hidden" name="s" value="{@name}"/>
26 <input type="hidden" name="c" value="{$collName}"/>
27 <xsl:if test="not(paramList/param[@name='startPage'])">
28 <input type="hidden" name="startPage" value="1"/>
29 </xsl:if>
30
31 <xsl:apply-templates select="paramList"/>
32
33 <input type="submit"><xsl:attribute name="value"><xsl:value-of select="displayItem[@name='submit']"/></xsl:attribute></input>
34
35 </div>
36 </form>
37
38 <xsl:if test="contains(/page/pageRequest/paramList/param[@name='rt']/@value, 'r')">
39 <xsl:call-template name="query-response">
40 <xsl:with-param name="collName" select="$collName"/>
41 </xsl:call-template>
42 </xsl:if>
43
44 </xsl:template>
45
46 <xsl:template match="/page"><xsl:apply-templates select="/page/pageResponse/service"/></xsl:template>
47
48
49 <!-- the default param list handling -->
50 <xsl:template match="paramList">
51 <xsl:param name="ns">s1.</xsl:param>
52 <ul id="queryitemlist">
53 <xsl:for-each select="param">
54 <xsl:choose>
55 <xsl:when test="@type='multi'">
56 <li><xsl:apply-templates select='.'><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates></li>
57 </xsl:when>
58 <xsl:otherwise>
59 <xsl:variable name="pvalue"><xsl:apply-templates select="." mode="calculate-default"><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates></xsl:variable>
60 <li><xsl:value-of select="displayItem[@name='name']"/><xsl:apply-templates select="."><xsl:with-param name="default" select="$pvalue"/><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates></li>
61 </xsl:otherwise>
62 </xsl:choose>
63 </xsl:for-each>
64 </ul>
65 </xsl:template>
66
67 <!-- puts all the params into a=p&p=h type form - need to change this if use
68 multi params -->
69 <xsl:template match="paramList" mode="cgi">
70 <xsl:param name="ns">s1.</xsl:param>
71 <xsl:for-each select="param">
72 <xsl:variable name='pname' select="@name"/>
73 <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>
74 </xsl:for-each>
75 </xsl:template>
76
77 <xsl:template match="param" mode="calculate-default">
78 <xsl:param name="ns">s1.</xsl:param>
79 <xsl:variable name="pname"><xsl:value-of select="$ns"/><xsl:value-of select="@name"/></xsl:variable>
80 <xsl:choose>
81 <xsl:when test="/page/pageRequest/paramList/param[@name=$pname]">
82 <xsl:choose>
83 <xsl:when test="@type='enum_multi'"><xsl:text>,</xsl:text>
84 <xsl:for-each select="/page/pageRequest/paramList/param[@name=$pname]">
85 <xsl:value-of select="@value"/>,
86 </xsl:for-each>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:value-of select="/page/pageRequest/paramList/param[@name=$pname]/@value"/>
90 </xsl:otherwise>
91 </xsl:choose>
92 </xsl:when>
93 <xsl:otherwise>
94 <xsl:value-of select="@default"/>
95 </xsl:otherwise>
96 </xsl:choose>
97 </xsl:template>
98
99 <!-- invisible params - used by other stuff. in the query form, we set to teh default -->
100 <xsl:template match="param[@type='invisible']">
101 <xsl:param name="ns">s1.</xsl:param>
102 <input type='hidden' name='{$ns}{@name}' value='{@default}'/>
103 </xsl:template>
104 <!-- boolean params -->
105 <xsl:template match="param[@type='boolean']">
106 <xsl:param name="ns">s1.</xsl:param>
107 <xsl:param name="default"/>
108 <select name='{$ns}{@name}'>
109 <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>
110 <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>
111 </select>
112 </xsl:template>
113
114 <!-- integer params -->
115 <xsl:template match="param[@type='integer']">
116 <xsl:param name="ns">s1.</xsl:param>
117 <xsl:param name="default"/>
118 <input type="text" name="{$ns}{@name}" size="3" value="{$default}"/>
119 </xsl:template>
120
121 <!-- single selection enum params -->
122 <xsl:template match="param[@type='enum_single']">
123 <xsl:param name="ns">s1.</xsl:param>
124 <xsl:param name="default"/>
125 <xsl:choose>
126 <xsl:when test="count(option) = 1">
127 <xsl:value-of select="option/displayItem[@name='name']"/>
128 <input type='hidden' name='{$ns}{@name}'><xsl:attribute name='value'><xsl:value-of select='option/@name'/></xsl:attribute></input>
129 </xsl:when>
130 <xsl:otherwise>
131 <select name="{$ns}{@name}">
132 <xsl:for-each select="option">
133 <option value="{@name}"><xsl:if test="@name=$default"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="displayItem[@name='name']"/></option>
134 </xsl:for-each>
135 </select>
136 </xsl:otherwise>
137 </xsl:choose>
138 </xsl:template>
139
140
141 <!-- multiple selection enum params -->
142 <!-- how to do defaults for this?? -->
143 <xsl:template match="param[@type='enum_multi']">
144 <xsl:param name="ns">s1.</xsl:param>
145 <xsl:param name="default"/>
146 <select name="{$ns}{@name}" size='2'><xsl:attribute name="multiple"></xsl:attribute>
147 <xsl:for-each select="option">
148 <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>
149 </xsl:for-each>
150 </select>
151 </xsl:template>
152
153 <!-- string params -->
154 <xsl:template match="param[@type='string']">
155 <xsl:param name="ns">s1.</xsl:param>
156 <xsl:param name="default"/>
157 <input type="text" name="{$ns}{@name}" size="50" value="{$default}"/>
158 </xsl:template>
159
160 <!-- large string params -->
161 <xsl:template match="param[@type='text']">
162 <xsl:param name="ns">s1.</xsl:param>
163 <xsl:param name="default"/>
164 <textarea name="{$ns}{@name}" cols="50" rows="3"><xsl:value-of select='$default'/></textarea>
165 </xsl:template>
166
167 <!-- multi params - params that are combinations of other params -->
168 <xsl:template match="param[@type='multi']">
169 <xsl:param name="ns">s1.</xsl:param>
170 <xsl:variable name="parent" select="@name"/>
171 <table>
172 <tr class="queryfieldheading"><xsl:value-of select="displayItem[@name='name']"/>
173 <xsl:for-each select="param">
174 <td class="queryfieldname"><xsl:value-of select="displayItem[@name='name']"/></td>
175 </xsl:for-each>
176 </tr>
177
178 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="@occurs"/><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates>
179 </table>
180 </xsl:template>
181
182 <xsl:template match="param[@type='multi']" mode="contents">
183 <xsl:param name="ns">s1.</xsl:param>
184 <xsl:param name="occurs">1</xsl:param>
185 <xsl:variable name="pos" select="@occurs - $occurs"/>
186 <tr class="queryfieldrow"><xsl:for-each select="param">
187 <xsl:variable name="pname" select="@name"/>
188 <xsl:variable name="values" select="/page/pageRequest/paramList/param[@name=$pname]/@value"/>
189 <td class="queryfieldcell"><xsl:choose>
190 <xsl:when test="not(@ignore) or @ignore != $pos">
191 <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>
192 </xsl:when>
193 <xsl:otherwise><!-- put in a hidden placeholder -->
194 <input type="hidden" name='{$ns}{@name}' value=''/>
195 </xsl:otherwise>
196 </xsl:choose></td>
197 </xsl:for-each></tr>
198 <!-- recursively call this template to get multiple entries -->
199 <xsl:if test="$occurs &gt; 1">
200 <xsl:apply-templates select="." mode="contents"><xsl:with-param name="occurs" select="$occurs - 1"/><xsl:with-param name="ns" select="$ns"/></xsl:apply-templates>
201 </xsl:if>
202 </xsl:template>
203
204
205</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.