root/greenstone3/trunk/web/ui/xslt/utile.xsl @ 16315

Revision 16315, 16.2 KB (checked in by davidb, 12 years ago)

Merging of skin work with the main trunk

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