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

Last change on this file since 33213 was 33199, checked in by davidb, 5 years ago

Introduction of @download attribute to gsf:link

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