root/greenstone3/trunk/web/ui/xslt/util.xsl @ 16501

Revision 16501, 16.4 KB (checked in by max, 12 years ago)

Nodes can now be collapsed during browsing action.

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
10<xsl:output
11method="xml"
12encoding="UTF-8"
13doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
14doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
15omit-xml-declaration="yes"
16indent="yes"/>
17
18<!-- general ............................................................................. -->
19
20<xsl:variable name="librarian"></xsl:variable>
21
22<xsl:variable name="action" select="/page/pageRequest/@action"/>
23
24<xsl:variable name="subaction" select="/page/pageRequest/@subaction"/>
25
26<xsl:variable name="lang" select="/page/pageRequest/@lang"/>
27
28<xsl:variable name="css">
29 <xsl:for-each select="/page/pageResponse/cssFileList/cssFile">
30  <link rel="stylesheet" href="{@path}" type="text/css" />
31 </xsl:for-each>
32</xsl:variable>
33
34<xsl:variable name="js">
35 <xsl:for-each select="/page/pageResponse/jsFileList/jsFile">
36    <script type="text/javascript" src="{@path}"></script>
37 </xsl:for-each>
38</xsl:variable>
39
40<xsl:template name="metadataItem">
41  <xsl:param name="name"/>
42
43   <xsl:variable name="x" select="/page/pageResponse/metadataList/metadataItem[@name=$name]" />
44
45  <xsl:choose>
46   <xsl:when test="$x = ''">
47    metadataItem '<xsl:value-of select="$name"/>' not defined.
48   </xsl:when>
49   <xsl:otherwise>
50    <xsl:for-each select="$x">
51     <xsl:call-template name="expandMetadataAndUiItems" />
52    </xsl:for-each>
53   </xsl:otherwise>
54  </xsl:choose>
55 
56</xsl:template>
57
58<!-- get the uiItem for the given name -->
59<xsl:template name="uiItem">
60  <xsl:param name="name"/>
61
62  <xsl:variable name="x" select="/page/pageResponse/uiItemList/uiItem[@name=$name]" />
63 
64  <xsl:choose>
65   <xsl:when test="$x = ''">
66    uiItem '<xsl:value-of select="$name"/>' not defined.
67   </xsl:when>
68   <xsl:otherwise>
69    <xsl:for-each select="$x">
70     <xsl:call-template name="expandMetadataAndUiItems" />
71    </xsl:for-each>
72   </xsl:otherwise>
73  </xsl:choose>
74
75</xsl:template>
76
77<!-- site level stuff ....................................................................... -->
78
79<xsl:variable name="collectionNames" select="/page/pageResponse/collectionList/collection/@name"/>
80
81<xsl:template name="collection_title">
82    <xsl:param name="name"/>
83    <xsl:value-of select="/page/pageResponse/collectionList/collection[@name=$name]/displayItem[@name='name']"/>
84</xsl:template>
85
86<xsl:template name="collection_description">
87    <xsl:param name="name"/>
88    <xsl:value-of select="/page/pageResponse/collectionList/collection[@name=$name]/displayItem[@name='description']"/>
89</xsl:template>
90
91<xsl:template name="collection_url">
92    <xsl:param name="name"/>
93    <xsl:value-of select="$librarian" />
94    ?a=p&amp;sa=about&amp;c=
95    <xsl:value-of select="$name" />
96</xsl:template>
97
98<xsl:variable name="site_homeUrl">
99    <xsl:value-of select="$librarian" />
100    ?a=p&amp;sa=home
101</xsl:variable>
102
103<!-- collection level stuff ....................................................................... -->
104
105<xsl:variable name="collection" select="/page/pageResponse/collection/@name"/>
106
107<xsl:variable name="serviceNames" select="/page/pageResponse/collection/serviceList/service[@type='query' or @type='browse']/@name"/>
108
109<xsl:template name="service_title">
110    <xsl:param name="serviceName"/>
111    <xsl:value-of select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]/displayItem[@name='name']"/>
112</xsl:template>
113
114<xsl:template name="service_description">
115    <xsl:param name="serviceName"/>
116    <xsl:value-of select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]/displayItem[@name='description']"/>
117</xsl:template>
118
119<xsl:template name="service_url">
120    <xsl:param name="serviceName"/>
121   
122   
123    <xsl:variable name="service" select="/page/pageResponse/collection/serviceList/service[@name=$serviceName]"/>
124    <xsl:variable name="serviceAction">
125    <xsl:choose>
126        <!-- this hard coding doesnt seem like a good idea: why isnt the appropriate action given as an attribute of the service? -->
127        <xsl:when test="$service/@type='query'">q</xsl:when>
128        <xsl:when test="$service/@type='browse'">b</xsl:when>
129        <xsl:when test="$service/@type='process'">pr</xsl:when>
130        <xsl:when test="$service/@type='applet'">a</xsl:when>
131        <xsl:otherwise>DO_NOT_DISPLAY</xsl:otherwise>
132        </xsl:choose>
133    </xsl:variable>
134   
135    <xsl:value-of select="$librarian"/>?a=
136    <xsl:value-of select="$serviceAction"/>&amp;rt=d&amp;s=
137    <xsl:value-of select="$serviceName"/>&amp;c=
138    <xsl:value-of select="$collection"/>
139</xsl:template>
140
141<xsl:variable name="classifierNames" select="/page/pageResponse/collection/serviceList//classifier/@name"/>
142
143<xsl:template name="classifier_title">
144    <xsl:param name="clsName"/>
145    <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/displayItem[@name='name']"/>
146</xsl:template>
147
148<xsl:template name="classifier_description">
149    <xsl:param name="clsName"/>
150    <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/displayItem[@name='description']"/>
151</xsl:template>
152
153<xsl:template name="classifier_url">
154    <xsl:param name="clsName"/>
155    <xsl:value-of select="$librarian"/>
156    ?a=b&amp;rt=r&amp;s=
157    <xsl:value-of select="/page/pageResponse/collection/serviceList//classifier[@name=$clsName]/../../@name"/>
158    &amp;c=
159    <xsl:value-of select="$collection"/>
160    &amp;cl=
161    <xsl:value-of select="$clsName"/>
162</xsl:template>
163
164
165<!-- searching ............................................................................. -->
166
167<xsl:template name="hidden_search_params">
168    <input name="c" value="{$collection}" type="hidden"/>
169    <input name="a" value="q" type="hidden"/>
170    <input name="s" value="TextQuery" type="hidden"/>
171</xsl:template>
172
173<xsl:template name="search_param_li">
174    <xsl:param name="search_param"/>
175        <li>
176            <xsl:for-each select="$search_param/displayItem[@name='name']">
177                        <xsl:value-of select="." />             
178            </xsl:for-each>
179           
180            <xsl:choose>
181               
182                <xsl:when test="$search_param/@type='boolean' or $search_param/@type='enum_single'">
183                    <select name="s1.{$search_param/@name}">
184                        <xsl:for-each select="$search_param/option">
185                            <option name="{@name}">
186                                <xsl:for-each select="./displayItem[@name='name']">
187                                    <xsl:value-of select="." />             
188                                </xsl:for-each>
189                            </option>
190                        </xsl:for-each>
191                    </select>
192                </xsl:when>
193               
194       
195                <xsl:when test="$search_param/@type='integer'">
196                    <input name="s1.{$search_param/@name}" value="{$search_param/@default}"/>           
197                </xsl:when>
198               
199                <xsl:when test="$search_param/@type='invisible'">
200                    <input name="s1.{$search_param/@name}" value="{$search_param/@default}" type="hidden"/>         
201                </xsl:when>
202               
203            </xsl:choose>
204    </li>
205   
206</xsl:template>
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224<!-- browsing ............................................................................. -->
225
226<xsl:variable name="currentClassifierName" select="/page/pageResponse/classifier/@name" />
227
228<xsl:variable name="topLevelClassifierNodes" select="/page/pageResponse/classifier/classifierNode"/>
229
230
231<xsl:variable name="topLevelClassifierNodeIds" select="/page/pageResponse/classifier/classifierNode/@nodeID"/>
232
233<!--
234<xsl:template name="classifierNode_title">
235    <xsl:param name="id"/>
236    <xsl:value-of select="/page/pageResponse/classifier//classifierNode[@nodeID=$id]/metadataList/metadata[@name='Title']"/>
237</xsl:template>
238-->
239
240<xsl:template name="classifierNode_url">
241    <xsl:param name="id"/>
242
243<xsl:value-of select="$librarian"/>
244?a=b&amp;rt=r&amp;s=
245<xsl:value-of select="/page/pageResponse/service/@name"/>
246&amp;c=
247<xsl:value-of select="$collection"/>
248&amp;cl=
249<xsl:value-of select="$id" /><xsl:if test="classifierNode|documentNode">.pr</xsl:if>
250
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 browser.