source: greenstone3/trunk/web/ui/xslt/util.xsl@ 16448

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

More careful declaration of XSLT header information for produces XML, not HTML output. This is needed for the JAVA code that then takes some transformed code, parses it back in to a DOM (needs to be XML) and then does some final adjustments. When output was HTML, empty elements such as <script ../> could loose their closing />.

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