source: main/trunk/greenstone3/web/interfaces/default/transform/expand-gsf.xsl@ 36287

Last change on this file since 36287 was 36027, checked in by cstephen, 2 years ago

Migrate to using jQuery3 and jQuery-UI-1.13.2; and integrate cookie consent manager

File size: 30.0 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
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:xalan="http://xml.apache.org/xalan"
8 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
9 extension-element-prefixes="java xalan">
10
11 <xsl:param name="interface_name"/>
12 <xsl:param name="library_name"/>
13 <xsl:param name="site_name"/>
14 <xsl:param name="use_client_side_xslt"/>
15 <xsl:param name="collName"/>
16 <xsl:param name="lang"/>
17
18 <xsl:output method="xml"/>
19 <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
20
21 <!-- don't output anything for gsf:format-gs2 elements,
22 they just exist in collectionconfig files to keep the XML valid -->
23 <xsl:template match="gsf:format-gs2" />
24
25 <xsl:template match="format">
26 <format>
27 <xsl:apply-templates/>
28 </format>
29 </xsl:template>
30
31 <xsl:template match="gsf:template">
32 <xslt:template>
33 <xsl:copy-of select="@*"/>
34 <xsl:attribute name="priority">2</xsl:attribute>
35 <xsl:if test=".//gsf:link">
36 <xslt:param name="serviceName"/>
37 <xslt:param name="collName"/>
38 </xsl:if>
39 <xsl:apply-templates/>
40 </xslt:template>
41 </xsl:template>
42
43 <xsl:template match="gsf:variable">
44 <xslt:variable>
45 <xsl:copy-of select="@*"/>
46 <xsl:apply-templates/>
47 </xslt:variable>
48 <script type="text/javascript">
49 gs.variables.<xsl:value-of select="@name"/>
50 <xslt:text disable-output-escaping="yes"> = "</xslt:text>
51 <xsl:apply-templates/>
52 <xslt:text disable-output-escaping="yes">";</xslt:text>
53 </script>
54 </xsl:template>
55
56
57 <xsl:template match="gsf:variable2">
58 <xslt:variable>
59 <xsl:copy-of select="@*"/>
60 <xsl:apply-templates/>
61 </xslt:variable>
62 <script type="text/javascript">
63 gs.variables.<xsl:value-of select="@name"/>
64 <xslt:text disable-output-escaping="yes"> = '</xslt:text>
65 <xsl:apply-templates/>
66 <xslt:text disable-output-escaping="yes">';</xslt:text>
67 </script>
68 </xsl:template>
69
70 <xsl:template match="gsf:defaultClassifierNode">
71 <xslt:call-template name="defaultClassifierNode"/>
72 </xsl:template>
73
74
75 <xsl:template match="gsf:script[@src]">
76 <script>
77 <xsl:attribute name='src'>
78 <xsl:value-of select="@src"/>
79 </xsl:attribute>
80 <xslt:attribute name='type'>text/javascript</xslt:attribute>
81 <xslt:comment/>
82 <!-- comment used to ensure script tag is not collapsed -->
83 </script>
84 </xsl:template>
85
86
87 <xsl:template match="gsf:script">
88 <script type="text/javascript">
89 <xslt:text disable-output-escaping="yes">
90 <xsl:apply-templates/>
91 </xslt:text>
92 </script>
93 </xsl:template>
94
95 <xsl:template match="gsf:style[@src]">
96 <link rel="stylesheet" type="text/css">
97 <xsl:attribute name='href'>
98 <xsl:value-of select="@src"/>
99 </xsl:attribute>
100 </link>
101 </xsl:template>
102
103 <xsl:template match="gsf:style">
104 <style type="text/css">
105 <xsl:apply-templates/>
106 </style>
107 </xsl:template>
108
109 <!-- a template for 'div' that doesn't trigger the
110 self-closing problem when being rendered as HTML by using
111 xslt:value-of="''" to ensure element doesn't become empty
112 when the XSLT processes it (which would then result in it
113 being changed into a self-closing element, which then is
114 incorrectly rendered as HTML). Doing this with the
115 value-of is better then injecting an xsl:comment in
116 (another approach we have used in the past) as the
117 comment approach then actually turns up in the final
118 HTML. This can lead to further complications if
119 Javascript using the 'empty' div truely expects it to
120 have no content of any form.
121 -->
122
123 <xsl:template match="gsf:div">
124 <div>
125 <xsl:for-each select="@*">
126 <xsl:attribute name="{name()}">
127 <xsl:value-of select="."/>
128 </xsl:attribute>
129 </xsl:for-each>
130 <xsl:apply-templates/>
131 <xslt:value-of select="''" /> <!-- to ensure that the div tag does not collapse into one of the form <div/> -->
132 </div>
133 </xsl:template>
134
135 <xsl:template match="gsf:dquote"><xslt:text disable-output-escaping="yes">"</xslt:text></xsl:template>
136 <!--
137 While double-quotes do map to entities in HTML, technically single quotes don't need to go through
138 this process: they can just be typed literally, and so this means there isn't strictly a need
139 for the following rule, but included for completeness. A long time ago it might have been that IE
140 did need the character to be entity-mapped -->
141 <xsl:template match="gsf:squote"><xslt:text disable-output-escaping="yes">'</xslt:text></xsl:template>
142
143 <xsl:template match="gsf:image">
144 <xslt:variable name="metaName">
145 <xsl:choose>
146 <xsl:when test="@type = 'thumb'">Thumb</xsl:when>
147 <xsl:when test="@type = 'screen'">Screen</xsl:when>
148 <xsl:when test="@type = 'source'">SourceFile</xsl:when>
149 <xsl:when test="@type = 'cover'">root_hascover</xsl:when>
150 </xsl:choose>
151 </xslt:variable>
152 <xslt:variable name="thisAssocfilepath">
153 <xslt:choose>
154 <xslt:when test="/page/pageResponse/document">
155 <xslt:choose>
156 <xslt:when test="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']">
157 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']" />
158 </xslt:when>
159 <xslt:otherwise>
160 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode[@nodeType='root']/metadataList/metadata[@name='assocfilepath']" />
161 </xslt:otherwise>
162 </xslt:choose>
163 </xslt:when>
164 <xslt:otherwise>
165 <xslt:choose>
166 <xslt:when test="(.//metadataList)[last()]/metadata[@name='assocfilepath']">
167 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='assocfilepath']" />
168 </xslt:when>
169 <xslt:otherwise>
170 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='root_assocfilepath']" />
171 </xslt:otherwise>
172 </xslt:choose>
173 </xslt:otherwise>
174 </xslt:choose>
175 </xslt:variable>
176 <xslt:if test="./metadataList/metadata[@name = $metaName]">
177 <img>
178 <xslt:attribute name='src'>
179 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
180 <xsl:text>/index/assoc/</xsl:text><xslt:value-of disable-output-escaping="yes" select="$thisAssocfilepath" /><xsl:text>/</xsl:text>
181 <xslt:choose>
182 <xslt:when test="$metaName = 'root_hascover'">cover.jpg</xslt:when>
183 <xslt:otherwise>
184 <xslt:value-of disable-output-escaping="yes" select="./metadataList/metadata[@name = $metaName]"/>
185 </xslt:otherwise>
186 </xslt:choose>
187 </xslt:attribute>
188 <!-- copy any other attributes apart from type-->
189 <xsl:for-each select="@*[name() != 'type']">
190 <xslt:attribute name="{name()}">
191 <xsl:value-of select="."/>
192 </xslt:attribute>
193 </xsl:for-each>
194
195 </img>
196 </xslt:if>
197 </xsl:template>
198
199 <!-- make this empty so we don't process the params element again inside the gsf:link type=query-->
200 <xsl:template match="params"></xsl:template>
201
202 <xsl:template match="gsf:link">
203
204 <xslt:variable name="collNameLocal" select="/page/pageResponse/collection/@name"/>
205 <xsl:variable name="opt-title">
206 <xsl:choose>
207 <xsl:when test="@title">
208 <xslt:attribute name="title">
209 <xsl:value-of select="@title"/>
210 </xslt:attribute>
211 </xsl:when>
212 <xsl:when test="@titlekey">
213 <xslt:attribute name="title">
214 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collNameLocal, $site_name, /page/@lang, '{@titlekey}')"/>
215 </xslt:attribute>
216 </xsl:when>
217 </xsl:choose>
218 </xsl:variable>
219
220 <xsl:choose>
221 <xsl:when test="@type='query'">
222 <a>
223 <xsl:if test="@target">
224 <xsl:attribute name='target'>
225 <xsl:value-of select='@target'/>
226 </xsl:attribute>
227 </xsl:if>
228
229 <xslt:attribute name='href'>
230 <xslt:value-of select='$library_name'/>
231 <xsl:text>/collection/</xsl:text>
232 <xslt:value-of select='/page/pageResponse/collection/@name'/>
233 <xsl:text>/search/</xsl:text>
234 <xsl:choose>
235 <xsl:when test="@name">
236 <xsl:value-of select="@name"/>
237 </xsl:when>
238 <xsl:otherwise>
239 <xsl:text>TextQuery</xsl:text>
240 </xsl:otherwise>
241 </xsl:choose>
242 <xsl:for-each select="params">?rt=rd&amp;<xsl:apply-templates/></xsl:for-each>
243
244 </xslt:attribute>
245 <xsl:copy-of select="$opt-title"/>
246 <xsl:apply-templates/>
247 </a>
248 </xsl:when>
249 <xsl:when test="@type='classifier'">
250 <a>
251 <xsl:if test="@target">
252 <xsl:attribute name='target'>
253 <xsl:value-of select='@target'/>
254 </xsl:attribute>
255 </xsl:if>
256
257 <xslt:attribute name='href'><xslt:call-template name="classifierNodeLink"><xsl:if test="@style"><xslt:with-param name="link-type"><xsl:value-of select="@style"/></xslt:with-param></xsl:if><xsl:if test="@nodeID"><xslt:with-param name="node-id"><xsl:value-of select="@nodeID"/></xslt:with-param></xsl:if></xslt:call-template>
258 </xslt:attribute>
259 <xsl:copy-of select="$opt-title"/>
260 <xsl:apply-templates/>
261 </a>
262 </xsl:when>
263 <xsl:when test="@type='source'">
264 <xslt:variable name="thisAssocfilepath">
265 <xslt:choose>
266 <xslt:when test="/page/pageResponse/document">
267 <xslt:choose>
268 <xslt:when test="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']">
269 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']" />
270 </xslt:when>
271 <xslt:otherwise>
272 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode[@nodeType='root']/metadataList/metadata[@name='assocfilepath']" />
273 </xslt:otherwise>
274 </xslt:choose>
275 </xslt:when>
276 <xslt:otherwise>
277 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='root_assocfilepath']" />
278 </xslt:otherwise>
279 </xslt:choose>
280 </xslt:variable>
281 <xsl:variable name="image_meta">
282 <xsl:choose>
283 <xsl:when test="@source_meta"><xsl:value-of select="@source_meta"/>
284 </xsl:when>
285 <xsl:otherwise>srclinkFile</xsl:otherwise>
286 </xsl:choose>
287 </xsl:variable>
288 <a>
289 <xsl:if test="@target">
290 <xsl:attribute name='target'>
291 <xsl:value-of select='@target'/>
292 </xsl:attribute>
293 </xsl:if>
294 <xsl:if test="@download">
295 <xsl:attribute name='download'>
296 <xsl:value-of select='@download'/>
297 </xsl:attribute>
298 </xsl:if>
299 <xslt:attribute name='href'>
300 <xslt:value-of
301 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
302 disable-output-escaping="yes" select="$thisAssocfilepath" />/<xslt:value-of
303 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='{$image_meta}']" />
304 </xslt:attribute>
305 <xsl:copy-of select="$opt-title"/>
306 <xsl:apply-templates/>
307 </a>
308 </xsl:when>
309 <xsl:when test="@type='web'">
310 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='weblink']"/>
311 <xsl:apply-templates/>
312 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='/weblink']"/>
313 </xsl:when>
314 <xsl:when test="@type='page'">
315 <a>
316 <xsl:if test="@target">
317 <xsl:attribute name='target'>
318 <xsl:value-of select='@target'/>
319 </xsl:attribute>
320 </xsl:if>
321
322 <xslt:attribute name='href'>
323 <xslt:value-of select='$library_name'/>
324 <xsl:text>/collection/</xsl:text>
325 <xslt:value-of select='/page/pageResponse/collection/@name'/>
326 <xsl:text>/page/</xsl:text>
327 <xsl:value-of select="@page"/>
328 </xslt:attribute>
329 <xsl:copy-of select="$opt-title"/>
330 <xsl:apply-templates/>
331 </a>
332 </xsl:when>
333 <xsl:when test="@type='equivdoc'">
334 <xsl:call-template name="gsf:equivlinkgs3"/>
335 </xsl:when>
336 <xsl:when test="@type='rss'">
337 <a>
338 <xslt:attribute name='href'>
339 <xslt:value-of select='$library_name'/>
340 <xsl:text>?a=rss&amp;l=en&amp;site=</xsl:text>
341 <xslt:value-of select="$site_name"/>
342 <xsl:text>&amp;c=</xsl:text>
343 <xslt:value-of select='/page/pageResponse/collection/@name'/>
344 </xslt:attribute>
345 <xsl:apply-templates/>
346 </a>
347 </xsl:when>
348 <xsl:otherwise>
349 <!-- a document link -->
350 <xslt:variable name="bookswitch">
351 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
352 </xslt:variable>
353
354 <a>
355 <xsl:if test="@target">
356 <xsl:attribute name='target'>
357 <xsl:value-of select='@target'/>
358 </xsl:attribute>
359 </xsl:if>
360
361 <xsl:copy-of select="$opt-title"/>
362 <xslt:attribute name="href">
363 <xslt:value-of select='$library_name'/>
364 <xsl:text>/collection/</xsl:text>
365 <xslt:value-of select='/page/pageResponse/collection/@name'/>
366 <xsl:text>/document/</xsl:text>
367 <xsl:choose>
368 <xsl:when test="@OID">
369 <xsl:value-of select="@OID"/>
370 </xsl:when>
371 <xsl:when test="@OIDmetadata">
372 <xsl:variable name="OIDmeta" select="@OIDmetadata"/>
373 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/>
374 </xsl:when>
375 <xsl:otherwise>
376 <xslt:value-of select='@nodeID'/>
377 </xsl:otherwise>
378 </xsl:choose>
379 <xslt:choose>
380 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
381 <xsl:text>?book=on</xsl:text>
382 </xslt:when>
383 <xslt:otherwise>
384 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
385 </xslt:if>
386 </xslt:otherwise>
387 </xslt:choose>
388 </xslt:attribute>
389 <xsl:apply-templates/>
390 </a>
391 </xsl:otherwise>
392 </xsl:choose>
393 </xsl:template>
394
395 <xsl:template match="gsf:OID">
396 <xslt:value-of select="@nodeID"/>
397 </xsl:template>
398 <xsl:template match="gsf:rank">
399 <xslt:value-of select="@rank"/>
400 </xsl:template>
401 <xsl:template match="gsf:icon">
402 <xsl:choose>
403 <xsl:when test="@type='classifier'">
404 <img style="border:0px">
405 <xsl:attribute name="src">
406 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/>
407 </xsl:attribute>
408 </img>
409 </xsl:when>
410 <xsl:when test="@type='web'">
411 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
412 </xsl:when>
413 <xsl:when test="@file">
414 <img>
415 <xslt:attribute name='src'>
416 <xsl:choose>
417 <xsl:when test="not(@select) or @select='site'">
418 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
419 </xsl:when>
420 <xsl:when test="@select='collection'">
421 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
422 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
423 </xsl:when>
424 </xsl:choose>
425 </xslt:attribute>
426 <xsl:if test="@alt">
427 <xslt:attribute name='alt'>
428 <xsl:value-of select="@alt" />
429 </xslt:attribute>
430 </xsl:if>
431 </img>
432 </xsl:when>
433 <xsl:when test="not(@type) or @type='document'">
434 <img style="border:0px">
435 <xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
436 </xslt:attribute>
437 <xslt:attribute name="src">
438 <xslt:choose>
439 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
440 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
441 </xslt:when>
442 <xslt:otherwise>
443 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
444 </xslt:otherwise>
445 </xslt:choose>
446 </xslt:attribute>
447 </img>
448 </xsl:when>
449 </xsl:choose>
450 </xsl:template>
451
452 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
453 <!--<xsl:template match="gsf:equivlinkgs3">
454 <xslt:call-template name="equivDocLinks">
455 <xslt:with-param name="count" select="0"/>
456 </xslt:call-template>
457 </xsl:template>-->
458
459 <!-- 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. -->
460 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
461 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
462 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
463 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
464
465 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
466 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
467 </xsl:template>
468
469 <!--
470In the collection's format statement, could have the following javascript+XSLT in place of
471the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
472<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
473</xsl:text>
474<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
475<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
476</xsl:text>
477<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
478<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
479</xsl:text>
480<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
481<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;
482</xsl:text>
483-->
484
485 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
486 <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> -->
487 <xsl:template match="gsf:cgi-param">
488 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
489 </xsl:template>
490
491 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
492 a string defined in either collectionConfig.xml or else the interface dictionaries.
493 If the requested string occurs in neither, the request string itself will be output. -->
494 <xsl:template match="gsf:displayText">
495 <xslt:variable name="displaytext">
496 <xsl:call-template name="gsf:displayItem"/>
497 </xslt:variable>
498
499 <xslt:choose>
500 <xslt:when test="$displaytext != ''">
501 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
502 </xslt:when>
503 <xslt:otherwise>
504 <xslt:variable name="interfacetxt">
505 <xsl:call-template name="gsf:interfaceText"/>
506 </xslt:variable>
507
508 <xslt:choose>
509 <xslt:when test="$interfacetxt != ''">
510 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
511 </xslt:when>
512 <xslt:otherwise>
513 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
514 </xslt:otherwise>
515 </xslt:choose>
516 </xslt:otherwise>
517 </xslt:choose>
518 </xsl:template>
519
520 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
521 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
522 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItemList/displayItem[@name='{@name}']"/>
523 </xsl:template>
524
525 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
526 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
527 <xsl:choose>
528 <xsl:when test="@propertyFile">
529 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, '{@propertyFile}', /page/@lang, '{@name}', '')"/>
530 </xsl:when>
531 <xsl:otherwise>
532 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
533 </xsl:otherwise>
534 </xsl:choose>
535 </xsl:template>
536
537 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
538 <xsl:template match="gsf:collectionText1" name="gsf:collectionText1">
539 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
540 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
541 </xsl:template>
542 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
543 <xsl:copy-of select="util:getCollectionText($collName, $site_name, $lang, @name, @args)/node()"/>
544 </xsl:template>
545
546
547 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
548 <xsl:template match="gsf:metadata">
549 <xsl:if test="not(@hidden = 'true')">
550 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
551 <xsl:variable name="meta_test"><xsl:call-template name="getMetadataTest"/></xsl:variable>
552 <xsl:variable name="separator">
553 <xsl:choose>
554 <xsl:when test="@separator">
555 <xsl:choose>
556 <xsl:when test="@separator = ' '">
557 <!-- http://stackoverflow.com/questions/1461649/how-to-insert-nbsp-in-xslt -->
558 <xsl:text>&#160;</xsl:text>
559 <!--<xsl:text> </xsl:text> only works in GLI's Format panel-->
560 <!--<xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>-->
561 </xsl:when>
562 <xsl:otherwise>
563 <xsl:value-of disable-output-escaping='yes' select="@separator"/>
564 </xsl:otherwise>
565 </xsl:choose>
566 </xsl:when>
567 <xsl:when test="separator">
568 <xsl:copy-of select="separator/node()"/>
569 </xsl:when>
570 <xsl:otherwise>
571 <xsl:text>, </xsl:text>
572 </xsl:otherwise>
573 </xsl:choose>
574 </xsl:variable>
575 <xsl:variable name="prefix">
576 <xsl:choose>
577 <xsl:when test="@prefix">
578 <xsl:value-of disable-output-escaping='yes' select="@prefix"/>
579 </xsl:when>
580 <xsl:when test="prefix">
581 <xsl:copy-of select="prefix/node()"/>
582 </xsl:when>
583 </xsl:choose>
584 </xsl:variable>
585 <xsl:variable name="suffix">
586 <xsl:choose>
587 <xsl:when test="@suffix">
588 <xsl:value-of disable-output-escaping='yes' select="@suffix"/>
589 </xsl:when>
590 <xsl:when test="suffix">
591 <xsl:copy-of select="suffix/node()"/>
592 </xsl:when>
593 </xsl:choose>
594 </xsl:variable>
595 <xsl:variable name="postest">
596 <xsl:choose>
597 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
598 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
599 <xsl:when test="@pos = 'classifiedBy'">position() = number(../../@mdoffset)+1</xsl:when>
600 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
601 </xsl:when>
602 <xsl:otherwise>true()</xsl:otherwise>
603 </xsl:choose>
604 </xsl:variable>
605 <xsl:variable name="multiple">
606 <xsl:choose>
607 <xsl:when test="@pos">false()</xsl:when>
608 <xsl:otherwise>true()</xsl:otherwise>
609 </xsl:choose>
610 </xsl:variable>
611 <xslt:for-each>
612 <xsl:attribute name="select">
613 (<xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>.//metadataList)[last()]/metadata[<xsl:value-of select="$meta_test"/><xsl:if test="@lang">
614 <xsl:text> and @lang=</xsl:text>
615 <xsl:value-of select="@lang"/>
616 </xsl:if>
617 <xsl:text>]</xsl:text>
618 </xsl:attribute>
619 <xslt:if test="{$postest}">
620 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
621 </xslt:if>
622 <xsl:copy-of select="$prefix"/>
623 <xsl:choose>
624 <xsl:when test="@format">
625 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
626 </xsl:when>
627 <xsl:when test="@highlight"><xslt:call-template name="displayMarkedUpTextAndAnnotations"/>
628 </xsl:when>
629 <xsl:otherwise>
630 <xslt:value-of disable-output-escaping='yes' select="."/>
631 </xsl:otherwise>
632 </xsl:choose>
633 </xslt:if>
634 <xsl:copy-of select="$suffix"/>
635 </xslt:for-each>
636 </xsl:if>
637 </xsl:template>
638
639
640 <xsl:template match="gsf:foreach-metadata">
641 <xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
642 <xslt:for-each>
643 <xsl:attribute name="select">
644 (<xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>.//metadataList)[last()]/metadata[@name='<xsl:value-of select="$meta_name"/>'<xsl:if test="@lang"><xsl:text> and @lang=</xsl:text><xsl:value-of select="@lang"/></xsl:if><xsl:text>]</xsl:text>
645 </xsl:attribute><xsl:choose><xsl:when test='@sort'><xslt:sort/></xsl:when><xsl:when test="gsf:sort"><xslt:sort><xsl:copy-of select="gsf:sort/@*"/></xslt:sort></xsl:when></xsl:choose><xsl:if test='@separator'><xslt:if test='position()>1'><xsl:value-of select='@separator'/></xslt:if></xsl:if>
646 <xsl:apply-templates/>
647 </xslt:for-each>
648 </xsl:template>
649
650 <xsl:template match="gsf:meta-value">
651 <xslt:value-of disable-output-escaping="yes" select="."/>
652 </xsl:template>
653
654 <xsl:template name="getMetadataName">
655 <xsl:if test='@select'>
656 <xsl:value-of select='@select'/>
657 <xsl:text>_</xsl:text>
658 </xsl:if>
659 <xsl:call-template name="stripEx"><xsl:with-param name="meta-name" select="@name"/></xsl:call-template>
660 </xsl:template>
661
662 <!-- we allow ex.Title in gsf:metadata. Need to strip off the ex. as the metadata in the database will be just Title. However, metadata like ex.dc.Title does keep its ex. in the database, so don't remove ex. if there is another . in the name -->
663 <xsl:template name="stripEx">
664 <xsl:param name="meta-name"/>
665 <xsl:choose><xsl:when test="starts-with($meta-name, 'ex.') and not(contains(substring($meta-name, 4), '.'))"><xsl:value-of select="substring($meta-name, 4)"/></xsl:when><xsl:otherwise><xsl:value-of select="$meta-name"/></xsl:otherwise></xsl:choose>
666 </xsl:template>
667
668 <!-- if we have metadata name="dc.Date,Date" will make a test like (@name = 'dc.Date' or @name = 'Date') -->
669 <xsl:template name="getMetadataTest">
670 <xsl:variable name="selectattr"><xsl:value-of select='@select'/></xsl:variable>
671 (<xsl:for-each select="xalan:tokenize(@name, ',')"><xsl:if test="position()!=1"> or </xsl:if>@name='<xsl:if test="$selectattr != ''"><xsl:value-of select="$selectattr"/><xsl:text>_</xsl:text></xsl:if><xsl:call-template name="stripEx"><xsl:with-param name="meta-name"><xsl:value-of select="."/></xsl:with-param></xsl:call-template>'</xsl:for-each>)
672 </xsl:template>
673
674 <xsl:template match="gsf:text">
675 <xsl:variable name="force">
676 <xsl:choose><xsl:when test="@force = 'true'">1</xsl:when><xsl:when test="@force = 'false'">0</xsl:when><xsl:otherwise>0</xsl:otherwise></xsl:choose>
677 </xsl:variable>
678 <xslt:call-template name="documentNodeText"><xslt:with-param name="force"><xsl:value-of select="$force"/></xslt:with-param></xslt:call-template>
679 </xsl:template>
680
681 <xsl:template match="gsf:if-metadata-exists">
682 <xsl:variable name="meta-path">
683 <xsl:for-each select="gsf:metadata">(./metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']<xsl:if test="@pos">[<xsl:value-of select="@pos"/>]</xsl:if></xsl:for-each>
684 </xsl:variable>
685 <xslt:choose>
686 <xslt:when test="{$meta-path}">
687 <xsl:apply-templates select="gsf:if/node()"/>
688 </xslt:when>
689 <xsl:if test="gsf:else">
690 <xslt:otherwise>
691 <xsl:apply-templates select="gsf:else/node()"/>
692 </xslt:otherwise>
693 </xsl:if>
694 </xslt:choose>
695 </xsl:template>
696
697 <xsl:template match="gsf:choose-metadata">
698 <xslt:choose>
699 <xsl:for-each select="gsf:metadata">
700 <xslt:when>
701 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
702 <xsl:apply-templates select="."/>
703 </xslt:when>
704 </xsl:for-each>
705 <xsl:if test="gsf:default">
706 <xslt:otherwise>
707 <xsl:apply-templates select="gsf:default/node()"/>
708 </xslt:otherwise>
709 </xsl:if>
710 </xslt:choose>
711 </xsl:template>
712
713 <xsl:template match="gsf:switch">
714 <xsl:variable name="meta-name">
715 <xsl:for-each select="gsf:metadata">
716 <xsl:call-template name="getMetadataName"/>
717 </xsl:for-each>
718 </xsl:variable>
719 <xslt:variable name="meta">
720 <xsl:choose>
721 <xsl:when test="@preprocess">
722 <xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/>
723 </xsl:when>
724 <xsl:otherwise>
725 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/>
726 </xsl:otherwise>
727 </xsl:choose>
728 </xslt:variable>
729 <xslt:choose>
730 <xsl:for-each select="gsf:when">
731 <xslt:when test="util:{@test}($meta, '{@test-value}')">
732 <xsl:apply-templates/>
733 </xslt:when>
734 </xsl:for-each>
735 <xsl:if test="gsf:otherwise">
736 <xslt:otherwise>
737 <xsl:apply-templates select="gsf:otherwise/node()"/>
738 </xslt:otherwise>
739 </xsl:if>
740 </xslt:choose>
741 </xsl:template>
742
743 <!--
744 <gsf:headMetaTags> exists for controlling the <meta name="x" content="y"> elements that appear in the HTML <head></head>
745 XPATH is used to select this item (in header.xsl). It does not need an explicit definition here in this file
746 -->
747 <!-- this template is used to avoid the user having to type
748 <xsl:text disable-output-escaping="yes">..</xsl:text> when they are trying to add unbalanced html tags into the xml (eg using suffix and prefix with metadata display -->
749 <xsl:template match="gsf:html">
750 <xslt:text disable-output-escaping="yes"><xsl:value-of select="."/></xslt:text>
751 </xsl:template>
752 <!-- use this if you want a space after an element in the output.
753 e.g. <strong>Title:><gsf:space/></strong -->
754 <xsl:template match="gsf:space">&#160;</xsl:template>
755 <xsl:template match="*">
756 <xsl:copy>
757 <xsl:copy-of select="@*"/>
758 <xsl:apply-templates/>
759 </xsl:copy>
760 </xsl:template>
761
762</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.