source: main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl@ 26460

Last change on this file since 26460 was 26460, checked in by sjm84, 11 years ago

Reformatting this file

File size: 19.0 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:xslt="output.xsl"
5 xmlns:java="http://xml.apache.org/xslt/java"
6 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
7 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
8 extension-element-prefixes="java">
9 <xsl:param name="interface_name"/>
10 <xsl:param name="library_name"/>
11 <xsl:param name="site_name"/>
12 <xsl:param name="collName"/>
13
14 <xsl:output method="xml"/>
15 <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
16
17 <xsl:template match="format">
18 <format>
19 <xsl:apply-templates/>
20 </format>
21 </xsl:template>
22
23 <xsl:template match="gsf:template">
24 <xslt:template>
25 <xsl:copy-of select="@*"/>
26 <xsl:attribute name="priority">2</xsl:attribute>
27 <xsl:if test=".//gsf:link">
28 <xslt:param name="serviceName"/>
29 <xslt:param name="collName"/>
30 </xsl:if>
31 <xsl:apply-templates/>
32 </xslt:template>
33 </xsl:template>
34
35 <xsl:template match="gsf:variable">
36 <xslt:variable>
37 <xsl:copy-of select="@*"/>
38 <xsl:apply-templates/>
39 </xslt:variable>
40 <script type="text/javascript">
41 gs.variables.<xsl:value-of select="@name"/>
42 <xslt:text disable-output-escaping="yes"> = "</xslt:text>
43 <xsl:apply-templates/>
44 <xslt:text disable-output-escaping="yes">";</xslt:text>
45 </script>
46 </xsl:template>
47
48 <xsl:template match="gsf:defaultClassifierNode">
49 <xslt:call-template name="defaultClassifierNode"/>
50 </xsl:template>
51
52
53 <xsl:template match="gsf:script[@src]">
54 <script>
55 <xsl:attribute name='src'>
56 <xsl:value-of select="@src"/>
57 </xsl:attribute>
58 <xslt:attribute name='type'>text/javascript</xslt:attribute>
59 <xslt:comment/>
60 <!-- comment used to ensure script tag is not collapsed -->
61 </script>
62 </xsl:template>
63
64
65 <xsl:template match="gsf:script">
66 <script type="text/javascript">
67 <xslt:text disable-output-escaping="yes">
68 <xsl:apply-templates/>
69 </xslt:text>
70 </script>
71 </xsl:template>
72
73
74 <xsl:template match="gsf:style[@src]">
75 <link rel="stylesheet" type="text/css">
76 <xsl:attribute name='href'>
77 <xsl:value-of select="@src"/>
78 </xsl:attribute>
79 </link>
80 </xsl:template>
81
82 <xsl:template match="gsf:style">
83 <style type="text/css">
84 <xsl:apply-templates/>
85 </style>
86 </xsl:template>
87
88
89 <xsl:template match="gsf:image">
90 <xslt:variable name="metaName">
91 <xsl:choose>
92 <xsl:when test="@type = 'thumb'">Thumb</xsl:when>
93 <xsl:when test="@type = 'screen'">Screen</xsl:when>
94 <xsl:when test="@type = 'source'">SourceFile</xsl:when>
95 </xsl:choose>
96 </xslt:variable>
97 <xslt:if test="(.//metadataList)[last()]/metadata[@name = $metaName]">
98 <img>
99 <xslt:attribute name='src'>
100 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
101 <xsl:text>/index/assoc/</xsl:text>
102 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/metadataList/metadata[@name = 'assocfilepath']"/>
103 <xsl:text>/</xsl:text>
104 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name = $metaName]"/>
105 </xslt:attribute>
106 </img>
107 </xslt:if>
108 </xsl:template>
109
110 <xsl:template match="gsf:link">
111 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
112 <xsl:variable name="opt-title">
113 <xsl:choose>
114 <xsl:when test="@title">
115 <xslt:attribute name="title">
116 <xsl:value-of select="@title"/>
117 </xslt:attribute>
118 </xsl:when>
119 <xsl:when test="@titlekey">
120 <xslt:attribute name="title">
121 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collName, $site_name, /page/@lang, '{@titlekey}')"/>
122 </xslt:attribute>
123 </xsl:when>
124 </xsl:choose>
125 </xsl:variable>
126 <xsl:choose>
127 <xsl:when test="@type='query'">
128 <a>
129 <xslt:attribute name='href'>
130 <xslt:value-of select='$library_name'/>
131 <xsl:text>/collection/</xsl:text>
132 <xslt:value-of select='/page/pageResponse/collection/@name'/>
133 <xsl:text>/search/</xsl:text>
134 <xsl:choose>
135 <xsl:when test="@name">
136 <xsl:value-of select="@name"/>
137 </xsl:when>
138 <xsl:otherwise>
139 <xsl:text>TextQuery</xsl:text>
140 </xsl:otherwise>
141 </xsl:choose>
142 </xslt:attribute>
143 <xsl:copy-of select="$opt-title"/>
144 <xsl:apply-templates/>
145 </a>
146 </xsl:when>
147 <xsl:when test="@type='classifier'">
148 <a>
149 <xslt:attribute name='href'>
150 <xslt:value-of select='$library_name'/>
151 <xsl:text>/collection/</xsl:text>
152 <xslt:value-of select='/page/pageResponse/collection/@name'/>
153 <xsl:text>/browse/</xsl:text>
154 <xsl:choose>
155 <xsl:when test="@nodeID">
156 <xsl:value-of select="@nodeID"/>
157 </xsl:when>
158 <xsl:otherwise>
159 <xslt:value-of select='util:replace(@nodeID, ".", "/")'/>
160 </xsl:otherwise>
161 </xsl:choose>
162 </xslt:attribute>
163 <xsl:copy-of select="$opt-title"/>
164 <xsl:apply-templates/>
165 </a>
166 </xsl:when>
167 <xsl:when test="@type='source'">
168 <a>
169 <xslt:attribute name='href'>
170 <xslt:value-of
171 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
172 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='assocfilepath']" />/<xslt:value-of
173 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='srclinkFile']" />
174 </xslt:attribute>
175 <xsl:copy-of select="$opt-title"/>
176 <xsl:apply-templates/>
177 </a>
178 </xsl:when>
179 <xsl:when test="@type='web'">
180 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'weblink')]"/>
181 <xsl:apply-templates/>
182 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, '/weblink')]"/>
183 </xsl:when>
184 <xsl:when test="@type='page'">
185 <a>
186 <xslt:attribute name='href'>
187 <xslt:value-of select='$library_name'/>
188 <xsl:text>/collection/</xsl:text>
189 <xslt:value-of select='/page/pageResponse/collection/@name'/>
190 <xsl:text>/page/</xsl:text>
191 <xsl:value-of select="@page"/>
192 </xslt:attribute>
193 <xsl:copy-of select="$opt-title"/>
194 <xsl:apply-templates/>
195 </a>
196 </xsl:when>
197 <xsl:when test="@type='equivdoc'">
198 <xsl:call-template name="gsf:equivlinkgs3"/>
199 </xsl:when>
200 <xsl:otherwise>
201 <!-- a document link -->
202 <xslt:variable name="bookswitch">
203 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
204 </xslt:variable>
205 <a>
206 <xsl:copy-of select="$opt-title"/>
207 <xslt:attribute name="href">
208 <xslt:value-of select='$library_name'/>
209 <xsl:text>/collection/</xsl:text>
210 <xslt:value-of select='/page/pageResponse/collection/@name'/>
211 <xsl:text>/document/</xsl:text>
212 <xsl:choose>
213 <xsl:when test="@OID">
214 <xsl:value-of select="@OID"/>
215 </xsl:when>
216 <xsl:when test="@OIDmetadata">
217 <xsl:variable name="OIDmeta" select="@OIDmetadata"/>
218 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/>
219 </xsl:when>
220 <xsl:otherwise>
221 <xslt:value-of select='@nodeID'/>
222 </xsl:otherwise>
223 </xsl:choose>
224 <xslt:choose>
225 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
226 <xsl:text>?book=on</xsl:text>
227 </xslt:when>
228 <xslt:otherwise>
229 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
230 </xslt:if>
231 </xslt:otherwise>
232 </xslt:choose>
233 </xslt:attribute>
234 <xsl:apply-templates/>
235 </a>
236 </xsl:otherwise>
237 </xsl:choose>
238 </xsl:template>
239
240 <xsl:template match="gsf:icon">
241 <xsl:choose>
242 <xsl:when test="@type='classifier'">
243 <img style="border:0px">
244 <xsl:attribute name="src">
245 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/>
246 </xsl:attribute>
247 </img>
248 </xsl:when>
249 <xsl:when test="@type='web'">
250 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
251 </xsl:when>
252 <xsl:when test="@file">
253 <img>
254 <xslt:attribute name='src'>
255 <xsl:choose>
256 <xsl:when test="not(@select) or @select='site'">
257 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
258 </xsl:when>
259 <xsl:when test="@select='collection'">
260 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
261 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
262 </xsl:when>
263 </xsl:choose>
264 </xslt:attribute>
265 </img>
266 </xsl:when>
267 <xsl:when test="not(@type) or @type='document'">
268 <img style="border:0px">
269 <xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
270 </xslt:attribute>
271 <xslt:attribute name="src">
272 <xslt:choose>
273 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
274 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
275 </xslt:when>
276 <xslt:otherwise>
277 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
278 </xslt:otherwise>
279 </xslt:choose>
280 </xslt:attribute>
281 </img>
282 </xsl:when>
283 </xsl:choose>
284 </xsl:template>
285
286 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
287 <!--<xsl:template match="gsf:equivlinkgs3">
288 <xslt:call-template name="equivDocLinks">
289 <xslt:with-param name="count" select="0"/>
290 </xslt:call-template>
291 </xsl:template>-->
292
293 <!-- Another way (also works with DSpace tutorial): build all the equivalent document links for the current document in one go. No looping necessary: handled in function call. -->
294 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
295 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
296 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
297 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
298
299 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
300 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
301 </xsl:template>
302
303 <!--
304In the collection's format statement, could have the following javascript+XSLT in place of
305the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
306<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
307</xsl:text>
308<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
309<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
310</xsl:text>
311<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
312<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
313</xsl:text>
314<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
315<xsl:text disable-output-escaping="yes">&quot;];for (var i=0; i&lt;equivDocIcon.length; i++) { document.write(equivDocStartLink[i]+ equivDocIcon[i] + equivDocEndLink[i]); }&lt;/script&gt;
316</xsl:text>
317-->
318
319 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
320 <a><xsl:attribute name="href"><gsf:metadata name="httpPath" type="collection"/>/index/assoc/<gsf:metadata name="archivedir"/>/<gsf:metadata name="srclinkFile"/>#search=&amp;quot;<gsf:cgi-param name="query"/>&amp;quot;</xsl:attribute>src doc link with query highlighting</a> -->
321 <xsl:template match="gsf:cgi-param">
322 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
323 </xsl:template>
324
325 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
326 a string defined in either collectionConfig.xml or else the interface dictionaries.
327 If the requested string occurs in neither, the request string itself will be output. -->
328 <xsl:template match="gsf:displayText">
329 <xslt:variable name="displaytext">
330 <xsl:call-template name="gsf:displayItem"/>
331 </xslt:variable>
332
333 <xslt:choose>
334 <xslt:when test="$displaytext != ''">
335 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
336 </xslt:when>
337 <xslt:otherwise>
338 <xslt:variable name="interfacetxt">
339 <xsl:call-template name="gsf:interfaceText"/>
340 </xslt:variable>
341
342 <xslt:choose>
343 <xslt:when test="$interfacetxt != ''">
344 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
345 </xslt:when>
346 <xslt:otherwise>
347 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
348 </xslt:otherwise>
349 </xslt:choose>
350 </xslt:otherwise>
351 </xslt:choose>
352 </xsl:template>
353
354 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
355 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
356 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
357 </xsl:template>
358
359 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
360 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
361 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
362 </xsl:template>
363 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
364 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
365 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
366 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
367 </xsl:template>
368
369 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
370 <xsl:template match="gsf:metadata">
371 <xsl:if test="not(@hidden = 'true')">
372 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
373 <xsl:variable name="meta_name">
374 <xsl:call-template name="getMetadataName"/>
375 </xsl:variable>
376 <xsl:variable name="separator">
377 <xsl:choose>
378 <xsl:when test="@separator">
379 <xsl:value-of disable-output-escaping='yes' select="@separator"/>
380 </xsl:when>
381 <xsl:when test="separator">
382 <xsl:copy-of select="separator/node()"/>
383 </xsl:when>
384 <xsl:otherwise>
385 <xsl:text>, </xsl:text>
386 </xsl:otherwise>
387 </xsl:choose>
388 </xsl:variable>
389 <xsl:variable name="prefix">
390 <xsl:choose>
391 <xsl:when test="@prefix">
392 <xsl:value-of disable-output-escaping='yes' select="@prefix"/>
393 </xsl:when>
394 <xsl:when test="prefix">
395 <xsl:copy-of select="prefix/node()"/>
396 </xsl:when>
397 </xsl:choose>
398 </xsl:variable>
399 <xsl:variable name="suffix">
400 <xsl:choose>
401 <xsl:when test="@suffix">
402 <xsl:value-of disable-output-escaping='yes' select="@suffix"/>
403 </xsl:when>
404 <xsl:when test="suffix">
405 <xsl:copy-of select="suffix/node()"/>
406 </xsl:when>
407 </xsl:choose>
408 </xsl:variable>
409 <xsl:variable name="postest">
410 <xsl:choose>
411 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
412 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
413 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
414 </xsl:when>
415 <xsl:otherwise>true()</xsl:otherwise>
416 </xsl:choose>
417 </xsl:variable>
418 <xsl:variable name="multiple">
419 <xsl:choose>
420 <xsl:when test="@pos">false()</xsl:when>
421 <xsl:otherwise>true()</xsl:otherwise>
422 </xsl:choose>
423 </xsl:variable>
424 <xslt:for-each>
425 <xsl:attribute name="select">
426 <xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>(.//metadataList)[last()]/metadata[@name='<xsl:value-of select="$meta_name"/>'<xsl:if test="@lang">
427 <xsl:text> and @lang=</xsl:text>
428 <xsl:value-of select="@lang"/>
429 </xsl:if>
430 <xsl:text>]</xsl:text>
431 </xsl:attribute>
432 <xslt:if test="{$postest}">
433 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
434 </xslt:if>
435 <xsl:copy-of select="$prefix"/>
436 <xsl:choose>
437 <xsl:when test="@format">
438 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
439 </xsl:when>
440 <xsl:otherwise>
441 <xslt:value-of disable-output-escaping='yes' select="."/>
442 </xsl:otherwise>
443 </xsl:choose>
444 </xslt:if>
445 <xsl:copy-of select="$suffix"/>
446 </xslt:for-each>
447 </xsl:if>
448 </xsl:template>
449
450 <xsl:template name="getMetadataName">
451 <xsl:if test='@select'>
452 <xsl:value-of select='@select'/>
453 <xsl:text>_</xsl:text>
454 </xsl:if>
455 <xsl:value-of select="@name"/>
456 </xsl:template>
457
458 <xsl:template match="gsf:text">
459 <xslt:call-template name="documentNodeText"/>
460 </xsl:template>
461
462 <xsl:template match="gsf:if-metadata-exists">
463 <xsl:variable name="meta-path">
464 <xsl:for-each select="gsf:metadata">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:for-each>
465 </xsl:variable>
466 <xslt:choose>
467 <xslt:when test="{$meta-path}">
468 <xsl:apply-templates select="gsf:if/node()"/>
469 </xslt:when>
470 <xsl:if test="gsf:else">
471 <xslt:otherwise>
472 <xsl:apply-templates select="gsf:else/node()"/>
473 </xslt:otherwise>
474 </xsl:if>
475 </xslt:choose>
476 </xsl:template>
477
478 <xsl:template match="gsf:choose-metadata">
479 <xslt:choose>
480 <xsl:for-each select="gsf:metadata">
481 <xslt:when>
482 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
483 <xsl:apply-templates select="."/>
484 </xslt:when>
485 </xsl:for-each>
486 <xsl:if test="gsf:default">
487 <xslt:otherwise>
488 <xsl:apply-templates select="gsf:default"/>
489 </xslt:otherwise>
490 </xsl:if>
491 </xslt:choose>
492 </xsl:template>
493
494 <xsl:template match="gsf:switch">
495 <xsl:variable name="meta-name">
496 <xsl:for-each select="gsf:metadata">
497 <xsl:call-template name="getMetadataName"/>
498 </xsl:for-each>
499 </xsl:variable>
500 <xslt:variable name="meta">
501 <xsl:choose>
502 <xsl:when test="@preprocess">
503 <xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/>
504 </xsl:when>
505 <xsl:otherwise>
506 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/>
507 </xsl:otherwise>
508 </xsl:choose>
509 </xslt:variable>
510 <xslt:choose>
511 <xsl:for-each select="gsf:when">
512 <xslt:when test="util:{@test}($meta, '{@test-value}')">
513 <xsl:apply-templates/>
514 </xslt:when>
515 </xsl:for-each>
516 <xsl:if test="gsf:otherwise">
517 <xslt:otherwise>
518 <xsl:apply-templates select="gsf:otherwise/node()"/>
519 </xslt:otherwise>
520 </xsl:if>
521 </xslt:choose>
522 </xsl:template>
523
524 <xsl:template match="*">
525 <xsl:copy>
526 <xsl:copy-of select="@*"/>
527 <xsl:apply-templates/>
528 </xsl:copy>
529 </xsl:template>
530
531</xsl:stylesheet>
532
533
Note: See TracBrowser for help on using the repository browser.