source: greenstone3/trunk/web/ui/xslt/util2.xsl/util2.xsl@ 16315

Last change on this file since 16315 was 16315, checked in by davidb, 16 years ago

Merging of skin work with the main trunk

File size: 16.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gslib="http://www.greenstone.org/XSL/Library" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan">
4
5<!-- general ............................................................................. -->
6
7<xsl:variable name="librarian">dev</xsl:variable>
8
9<xsl:variable name="action" select="/page/pageRequest/@action"/>
10
11<xsl:variable name="subaction" select="/page/pageRequest/@subaction"/>
12
13<xsl:variable name="lang" select="/page/pageRequest/@lang"/>
14
15<xsl:variable name="css">
16 <xsl:for-each select="/page/pageResponse/cssFileList/cssFile">
17 <link rel="stylesheet" href="{@path}" type="text/css"/>
18 </xsl:for-each>
19</xsl:variable>
20
21<xsl:variable name="js">
22 <xsl:for-each select="/page/pageResponse/jsFileList/jsFile">
23 <script type="text/javascript" src="{@path}"></script>
24 </xsl:for-each>
25</xsl:variable>
26
27<xsl:template name="metadataItem">
28 <xsl:param name="name"/>
29
30 <xsl:variable name="x" select="/page/pageResponse/metadataList/metadataItem[@name=$name]" />
31
32 <xsl:choose>
33 <xsl:when test="$x = ''">
34 metadataItem '<xsl:value-of select="$name"/>' not defined.
35 </xsl:when>
36 <xsl:otherwise>
37 <xsl:for-each select="$x">
38 <xsl:call-template name="expandMetadataAndUiItems" />
39 </xsl:for-each>
40 </xsl:otherwise>
41 </xsl:choose>
42
43</xsl:template>
44
45<!-- get the uiItem for the given name -->
46<xsl:template name="uiItem">
47 <xsl:param name="name"/>
48
49 <xsl:variable name="x" select="/page/pageResponse/uiItemList/uiItem[@name=$name]" />
50
51 <xsl:choose>
52 <xsl:when test="$x = ''">
53 uiItem '<xsl:value-of select="$name"/>' not defined.
54 </xsl:when>
55 <xsl:otherwise>
56 <xsl:for-each select="$x">
57 <xsl:call-template name="expandMetadataAndUiItems" />
58 </xsl:for-each>
59 </xsl:otherwise>
60 </xsl:choose>
61
62</xsl:template>
63
64<!-- site level stuff ....................................................................... -->
65
66<xsl:variable name="collectionNames" select="/page/pageResponse/collectionList/collection/@name"/>
67
68<xsl:template name="collection_title">
69 <xsl:param name="name"/>
70 <xsl:value-of select="/page/pageResponse/collectionList/collection[@name=$name]/displayItem[@name='name']"/>
71</xsl:template>
72
73<xsl:template name="collection_description">
74 <xsl:param name="name"/>
75 <xsl:value-of select="/page/pageResponse/collectionList/collection[@name=$name]/displayItem[@name='description']"/>
76</xsl:template>
77
78<xsl:template name="collection_url">
79 <xsl:param name="name"/>
80 <xsl:value-of select="$librarian" />
81 ?a=p&amp;sa=about&amp;c=
82 <xsl:value-of select="$name" />
83</xsl:template>
84
85<xsl:variable name="site_homeUrl">
86 <xsl:value-of select="$librarian" />
87 ?a=p&amp;sa=home
88</xsl:variable>
89
90<!-- collection level stuff ....................................................................... -->
91
92<xsl:variable name="collection" select="/page/pageResponse/collection/@name"/>
93
94<xsl:variable name="serviceNames" select="/page/pageResponse/collection/serviceList/service[@type='query' or @type='browse']/@name"/>
95
96<xsl:template name="service_title">
97 <xsl:param name="serviceName"/>
98 <xsl:value-of select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]/displayItem[@name='name']"/>
99</xsl:template>
100
101<xsl:template name="service_description">
102 <xsl:param name="serviceName"/>
103 <xsl:value-of select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]/displayItem[@name='description']"/>
104</xsl:template>
105
106<xsl:template name="service_url">
107 <xsl:param name="serviceName"/>
108
109
110 <xsl:variable name="service" select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]"/>
111 <xsl:variable name="serviceAction">
112 <xsl:choose>
113 <!-- this hard coding doesnt seem like a good idea: why isnt the appropriate action given as an attribute of the service? -->
114 <xsl:when test="$service/@type='query'">q</xsl:when>
115 <xsl:when test="$service/@type='browse'">b</xsl:when>
116 <xsl:when test="$service/@type='process'">pr</xsl:when>
117 <xsl:when test="$service/@type='applet'">a</xsl:when>
118 <xsl:otherwise>DO_NOT_DISPLAY</xsl:otherwise>
119 </xsl:choose>
120 </xsl:variable>
121
122 <xsl:value-of select="$librarian"/>?a=
123 <xsl:value-of select="$serviceAction"/>&amp;rt=d&amp;s=
124 <xsl:value-of select="$serviceName"/>&amp;c=
125 <xsl:value-of select="$collection"/>
126</xsl:template>
127
128<xsl:variable name="classifierNames" select="/page/pageResponse/collection/serviceList//classifier/@name"/>
129
130<xsl:template name="classifier_title">
131 <xsl:param name="clsName"/>
132 <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/displayItem[@name='name']"/>
133</xsl:template>
134
135<xsl:template name="classifier_description">
136 <xsl:param name="clsName"/>
137 <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/displayItem[@name='description']"/>
138</xsl:template>
139
140<xsl:template name="classifier_url">
141 <xsl:param name="clsName"/>
142 <xsl:value-of select="$librarian"/>
143 ?a=b&amp;rt=r&amp;s=
144 <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/../../@name"/>
145 &amp;c=
146 <xsl:value-of select="$collection"/>
147 &amp;cl=
148 <xsl:value-of select="$clsName"/>
149</xsl:template>
150
151
152<!-- searching ............................................................................. -->
153
154<xsl:template name="hidden_search_params">
155 <input name="c" value="{$collection}" type="hidden"/>
156 <input name="a" value="q" type="hidden"/>
157 <input name="s" value="TextQuery" type="hidden"/>
158</xsl:template>
159
160<xsl:template name="search_param_li">
161 <xsl:param name="search_param"/>
162 <li>
163 <xsl:for-each select="$search_param/displayItem[@name='name']">
164 <xsl:value-of select="." />
165 </xsl:for-each>
166
167 <xsl:choose>
168
169 <xsl:when test="$search_param/@type='boolean' or $search_param/@type='enum_single'">
170 <select name="s1.{$search_param/@name}">
171 <xsl:for-each select="$search_param/option">
172 <option name="{@name}">
173 <xsl:for-each select="./displayItem[@name='name']">
174 <xsl:value-of select="." />
175 </xsl:for-each>
176 </option>
177 </xsl:for-each>
178 </select>
179 </xsl:when>
180
181
182 <xsl:when test="$search_param/@type='integer'">
183 <input name="s1.{$search_param/@name}" value="{$search_param/@default}"/>
184 </xsl:when>
185
186 <xsl:when test="$search_param/@type='invisible'">
187 <input name="s1.{$search_param/@name}" value="{$search_param/@default}" type="hidden"/>
188 </xsl:when>
189
190 </xsl:choose>
191 </li>
192
193</xsl:template>
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211<!-- browsing ............................................................................. -->
212
213<xsl:variable name="currentClassifierName" select="/page/pageResponse/classifier/@name" />
214
215<xsl:variable name="topLevelClassifierNodes" select="/page/pageResponse/classifier/classifierNode"/>
216
217
218<xsl:variable name="topLevelClassifierNodeIds" select="/page/pageResponse/classifier/classifierNode/@nodeID"/>
219
220<!--
221<xsl:template name="classifierNode_title">
222 <xsl:param name="id"/>
223 <xsl:value-of select="/page/pageResponse/classifier//classifierNode[@nodeID=$id]/metadataList/metadata[@name='Title']"/>
224</xsl:template>
225-->
226
227<xsl:template name="classifierNode_url">
228 <xsl:param name="id"/>
229
230 <xsl:value-of select="$librarian"/>
231 ?a=b&amp;rt=r&amp;s=
232 <xsl:value-of select="/page/pageResponse/service/@name"/>
233 &amp;c=
234 <xsl:value-of select="$collection"/>
235 &amp;cl=
236 <xsl:value-of select="$id" />
237</xsl:template>
238
239<xsl:template name="classifierNode_childNodeIds">
240 <xsl:param name="id"/>
241 <xsl:value-of select="xalan:nodeset(/page/pageResponse/classifier//classifierNode[@nodeID=$id])/classifierNode/@nodeID"/>
242</xsl:template>
243
244
245
246
247
248<xsl:template name="list_classifer_data">
249 <ul>
250 <xsl:for-each select="/page/pageResponse/classifier/classifierNode">
251 <xsl:call-template name="expand_classifier_node" />
252 </xsl:for-each>
253 <xsl:for-each select="/page/pageResponse/classifier/documentNode">
254 <li class="leafNode">
255 <!-- call format statement for docuement node -->
256 <xsl:call-template name="documentNode" />
257 </li>
258 </xsl:for-each>
259 </ul>
260</xsl:template>
261
262<xsl:template name="expand_classifier_node">
263 <xsl:choose>
264
265 <xsl:when test="classifierNode or documentNode">
266 <!-- if there are children -->
267 <li class="expandedNode">
268 <!-- call format statement for classifier node -->
269 <xsl:call-template name="classifierNode" />
270
271 <xsl:if test="classifierNode">
272 <ul>
273 <xsl:for-each select="classifierNode">
274 <xsl:call-template name="expand_classifier_node"/>
275 </xsl:for-each>
276 </ul>
277 </xsl:if>
278 <xsl:if test="documentNode">
279 <ul>
280 <xsl:for-each select="documentNode">
281 <li class="leafNode">
282 <!-- call format statement for docuement node -->
283 <xsl:call-template name="documentNode" />
284 </li>
285 </xsl:for-each>
286 </ul>
287 </xsl:if>
288 </li>
289 </xsl:when>
290 <xsl:otherwise>
291 <li class="collapsedNode">
292 <!-- call format statement for classifier node -->
293 <xsl:call-template name="classifierNode" />
294 </li>
295 </xsl:otherwise>
296 </xsl:choose>
297</xsl:template>
298
299<!-- document viewing..................................................................... -->
300
301<xsl:variable name="document_coverImage_exists" select="/page/pageResponse/document/@hasCoverImage" />
302
303<xsl:variable name="document_coverImage_url">
304 <xsl:if test="$document_coverImage_exists">
305 <xsl:value-of select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<xsl:value-of select="normalize-space(/page/pageResponse/document/metadataList/metadata[@name='archivedir'])"/>/cover.jpg
306 </xsl:if>
307</xsl:variable>
308
309<xsl:variable name="document_type" select="/page/pageResponse/document/@docType"/>
310
311<xsl:variable name="document_hash" select="/page/pageResponse/document/documentNode/@nodeID" />
312
313<xsl:variable name="document_is_expanded" select="/page/pageRequest/paramList/param[@name='ed']/@value=1"/>
314
315<xsl:variable name="document_expanded_url">
316 <xsl:value-of select="$librarian"/>?a=d&amp;
317 c=<xsl:value-of select="$collection"/>&amp;
318 d=<xsl:value-of select="$document_hash"/>&amp;
319 ed=1
320</xsl:variable>
321
322<xsl:variable name="document_collapsed_url">
323 <xsl:value-of select="$librarian"/>?a=d&amp;
324 c=<xsl:value-of select="$collection"/>&amp;
325 d=<xsl:value-of select="$document_hash"/>
326</xsl:variable>
327
328<xsl:variable name="document_title" >
329 <xsl:choose>
330 <xsl:when test="$document_type='simple'">
331 <xsl:value-of disable-output-escaping='yes' select="/page/pageResponse/document/metadataList/metadata[@name='Title']" />
332 </xsl:when>
333 <xsl:otherwise>
334 <xsl:value-of disable-output-escaping='yes' select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']"/>
335 </xsl:otherwise>
336 </xsl:choose>
337</xsl:variable>
338
339<xsl:variable name="document_content" >
340 <xsl:choose>
341 <xsl:when test="$document_type='simple'">
342 <xsl:value-of select="$document_currentSection_content" />
343 </xsl:when>
344 </xsl:choose>
345</xsl:variable>
346
347<xsl:variable name="document_allSectionIds" select="/page/pageResponse/document//documentNode[@nodeType!='root']" />
348
349<xsl:variable name="document_topLevelSectionIds" select="/page/pageResponse/document/documentNode/documentNode" />
350
351<xsl:template name="document_section_title">
352 <xsl:param name="sectionId" />
353 <xsl:value-of disable-output-escaping='yes' select="//page/pageResponse/document//documentNode[@nodeID=$sectionId]/metadataList/metadata[@name='Title']"/>
354</xsl:template>
355
356<!--
357<xsl:template name="document_section_depth">
358 <xsl:param name="index" />
359 <xsl:value-of select="count($document_allSections[$index]/ancestor::documentNode)"/>
360</xsl:template>
361
362<xsl:template name="document_section_content">
363 <xsl:param name="index" />
364 <xsl:value-of disable-output-escaping='yes' select="$document_allSections[$index]/nodeContent"/>
365</xsl:template>
366
367-->
368
369<xsl:variable name="document_currentSection" select="/page/pageResponse/document//nodeContent/.." />
370
371<xsl:variable name="document_currentSection_title" select="$document_currentSection/metadataList/metadata[@name='Title']" />
372
373<xsl:variable name="document_currentSection_content" select="$document_currentSection/nodeContent" />
374
375<xsl:variable name="document_previousSection" select="$document_currentSection/preceding::documentNode[@nodeType='leaf'][1]"/>
376
377<xsl:variable name="document_previousSection_title" select="$document_previousSection/metadataList/metadata[@name='Title']"/>
378
379<xsl:variable name="document_previousSection_url">
380 <xsl:value-of select="$librarian"/>?a=d&amp;
381 c=<xsl:value-of select="$collection"/>&amp;
382 d=<xsl:value-of select="$document_previousSection/@nodeID"/>&amp;
383 sib=1&amp;ec=1
384</xsl:variable>
385
386<xsl:variable name="document_nextSection" select="$document_currentSection/following::documentNode[@nodeType='leaf'][1]"/>
387
388<xsl:variable name="document_nextSection_title" select="$document_nextSection/metadataList/metadata[@name='Title']"/>
389
390<xsl:variable name="document_nextSection_url">
391 <xsl:value-of select="$librarian"/>?a=d&amp;
392 c=<xsl:value-of select="$collection"/>&amp;
393 d=<xsl:value-of select="$document_nextSection/@nodeID"/>&amp;
394 sib=1&amp;ec=1
395</xsl:variable>
396
397<xsl:variable name="document_ancestorSections" select="$document_currentSection/ancestor::documentNode[@nodeType='internal']"/>
398<xsl:variable name="document_ancestorSections_titles" select="$document_ancestorSections/metadataList/metadata[@name='Title']"/>
399
400<xsl:template name="list_document_content">
401 <ul>
402 <xsl:for-each select="/page/pageResponse/document/documentNode/documentNode">
403 <xsl:call-template name="expand_doc_content_node" />
404 </xsl:for-each>
405 </ul>
406</xsl:template>
407
408<xsl:template name="expand_doc_content_node">
409 <xsl:variable name="class">
410 <xsl:choose>
411 <xsl:when test="@nodeType='leaf'">leaf</xsl:when>
412 <xsl:otherwise>collapsed</xsl:otherwise>
413 </xsl:choose>
414 </xsl:variable>
415
416 <li class="{$class}" id="{@nodeID}" >
417 <xsl:choose>
418 <xsl:when test="nodeContent">
419 <span id="currentSection">
420 <xsl:value-of disable-output-escaping='yes' select="metadataList/metadata[@name='Title']"/>
421 </span>
422 </xsl:when>
423 <xsl:when test="@nodeType='leaf'">
424 <a href="{$librarian}?a=d&amp;c={$collection}&amp;d={@nodeID}&amp;sib=1&amp;ec=1">
425 <xsl:value-of disable-output-escaping='yes' select="metadataList/metadata[@name='Title']"/>
426 </a>
427 </xsl:when>
428 <xsl:otherwise>
429 <a onclick="toggleNode('{@nodeID}')">
430 <xsl:value-of disable-output-escaping='yes' select="metadataList/metadata[@name='Title']"/>
431 </a>
432 </xsl:otherwise>
433 </xsl:choose>
434
435 <xsl:if test="documentNode">
436 <ul>
437 <xsl:for-each select="documentNode">
438 <xsl:call-template name="expand_doc_content_node" />
439 </xsl:for-each>
440 </ul>
441 </xsl:if>
442 </li>
443</xsl:template>
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459<!-- stuff that no-one should need to know about........................................ -->
460
461<!-- produce an exact copy of the current node, but expand and replace all metadataItems and uiItems found within. -->
462<xsl:template name="expandMetadataAndUiItems">
463 <xsl:for-each select="*|text()">
464 <xsl:choose>
465
466 <!-- if node is a metadataItem, expand it -->
467 <xsl:when test="self::node()[self::metadataItem]">
468 <xsl:call-template name="metadataItem">
469 <xsl:with-param name="name"><xsl:value-of select="@name"/></xsl:with-param>
470 </xsl:call-template>
471 </xsl:when>
472
473 <!-- if node is a uiItem, expand it -->
474 <xsl:when test="self::node()[self::uiItem]">
475 <xsl:call-template name="uiItem">
476 <xsl:with-param name="name"><xsl:value-of select="@name"/></xsl:with-param>
477 </xsl:call-template>
478 </xsl:when>
479
480 <xsl:when test="self::text()">
481 <xsl:value-of select="."/>
482 </xsl:when>
483
484 <!-- if a regular node -->
485 <xsl:otherwise>
486 <xsl:variable name="element-name" select="name()"/>
487 <xsl:element name="{$element-name}">
488 <xsl:for-each select="@*">
489 <xsl:variable name="attribute-name" select="name()"/>
490 <xsl:attribute name="{$attribute-name}">
491 <xsl:call-template name="attribute-filter"/>
492 </xsl:attribute>
493 </xsl:for-each>
494 <xsl:call-template name="expandMetadataAndUiItems" />
495 </xsl:element>
496 </xsl:otherwise>
497 </xsl:choose>
498 </xsl:for-each>
499
500</xsl:template>
501
502<xsl:template name="attribute-filter"><xsl:value-of select="."/></xsl:template>
503
504<xsl:template match="gslib:blah">
505 <p> Blah </p>
506</xsl:template>
507
508
509
510</xsl:stylesheet>
511
512
Note: See TracBrowser for help on using the repository browser.