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

Last change on this file since 33639 was 33639, checked in by kjdon, 4 years ago

need to select child nodes, otherwise the gsf:default node ends up in the output

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