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

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

renamed config_format and text_fragment_format to better represent what they do

File size: 29.5 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 <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[contains(@name, 'weblink')]"/>
311 <xsl:apply-templates/>
312 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@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 </img>
427 </xsl:when>
428 <xsl:when test="not(@type) or @type='document'">
429 <img style="border:0px">
430 <xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
431 </xslt:attribute>
432 <xslt:attribute name="src">
433 <xslt:choose>
434 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
435 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
436 </xslt:when>
437 <xslt:otherwise>
438 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
439 </xslt:otherwise>
440 </xslt:choose>
441 </xslt:attribute>
442 </img>
443 </xsl:when>
444 </xsl:choose>
445 </xsl:template>
446
447 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
448 <!--<xsl:template match="gsf:equivlinkgs3">
449 <xslt:call-template name="equivDocLinks">
450 <xslt:with-param name="count" select="0"/>
451 </xslt:call-template>
452 </xsl:template>-->
453
454 <!-- 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. -->
455 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
456 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
457 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
458 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
459
460 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
461 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
462 </xsl:template>
463
464 <!--
465In the collection's format statement, could have the following javascript+XSLT in place of
466the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
467<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
468</xsl:text>
469<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
470<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
471</xsl:text>
472<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
473<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
474</xsl:text>
475<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
476<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;
477</xsl:text>
478-->
479
480 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
481 <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> -->
482 <xsl:template match="gsf:cgi-param">
483 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
484 </xsl:template>
485
486 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
487 a string defined in either collectionConfig.xml or else the interface dictionaries.
488 If the requested string occurs in neither, the request string itself will be output. -->
489 <xsl:template match="gsf:displayText">
490 <xslt:variable name="displaytext">
491 <xsl:call-template name="gsf:displayItem"/>
492 </xslt:variable>
493
494 <xslt:choose>
495 <xslt:when test="$displaytext != ''">
496 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
497 </xslt:when>
498 <xslt:otherwise>
499 <xslt:variable name="interfacetxt">
500 <xsl:call-template name="gsf:interfaceText"/>
501 </xslt:variable>
502
503 <xslt:choose>
504 <xslt:when test="$interfacetxt != ''">
505 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
506 </xslt:when>
507 <xslt:otherwise>
508 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
509 </xslt:otherwise>
510 </xslt:choose>
511 </xslt:otherwise>
512 </xslt:choose>
513 </xsl:template>
514
515 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
516 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
517 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItemList/displayItem[@name='{@name}']"/>
518 </xsl:template>
519
520 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
521 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
522 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
523 </xsl:template>
524 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
525 <xsl:template match="gsf:collectionText1" name="gsf:collectionText1">
526 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
527 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
528 </xsl:template>
529 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
530 <xsl:copy-of select="util:getCollectionText($collName, $site_name, $lang, @name, @args)/node()"/>
531 </xsl:template>
532
533
534 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
535 <xsl:template match="gsf:metadata">
536 <xsl:if test="not(@hidden = 'true')">
537 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
538 <xsl:variable name="meta_test"><xsl:call-template name="getMetadataTest"/></xsl:variable>
539 <xsl:variable name="separator">
540 <xsl:choose>
541 <xsl:when test="@separator">
542 <xsl:choose>
543 <xsl:when test="@separator = ' '">
544 <!-- http://stackoverflow.com/questions/1461649/how-to-insert-nbsp-in-xslt -->
545 <xsl:text>&#160;</xsl:text>
546 <!--<xsl:text> </xsl:text> only works in GLI's Format panel-->
547 <!--<xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>-->
548 </xsl:when>
549 <xsl:otherwise>
550 <xsl:value-of disable-output-escaping='yes' select="@separator"/>
551 </xsl:otherwise>
552 </xsl:choose>
553 </xsl:when>
554 <xsl:when test="separator">
555 <xsl:copy-of select="separator/node()"/>
556 </xsl:when>
557 <xsl:otherwise>
558 <xsl:text>, </xsl:text>
559 </xsl:otherwise>
560 </xsl:choose>
561 </xsl:variable>
562 <xsl:variable name="prefix">
563 <xsl:choose>
564 <xsl:when test="@prefix">
565 <xsl:value-of disable-output-escaping='yes' select="@prefix"/>
566 </xsl:when>
567 <xsl:when test="prefix">
568 <xsl:copy-of select="prefix/node()"/>
569 </xsl:when>
570 </xsl:choose>
571 </xsl:variable>
572 <xsl:variable name="suffix">
573 <xsl:choose>
574 <xsl:when test="@suffix">
575 <xsl:value-of disable-output-escaping='yes' select="@suffix"/>
576 </xsl:when>
577 <xsl:when test="suffix">
578 <xsl:copy-of select="suffix/node()"/>
579 </xsl:when>
580 </xsl:choose>
581 </xsl:variable>
582 <xsl:variable name="postest">
583 <xsl:choose>
584 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
585 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
586 <xsl:when test="@pos = 'classifiedBy'">position() = number(../../@mdoffset)+1</xsl:when>
587 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
588 </xsl:when>
589 <xsl:otherwise>true()</xsl:otherwise>
590 </xsl:choose>
591 </xsl:variable>
592 <xsl:variable name="multiple">
593 <xsl:choose>
594 <xsl:when test="@pos">false()</xsl:when>
595 <xsl:otherwise>true()</xsl:otherwise>
596 </xsl:choose>
597 </xsl:variable>
598 <xslt:for-each>
599 <xsl:attribute name="select">
600 (<xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>.//metadataList)[last()]/metadata[<xsl:value-of select="$meta_test"/><xsl:if test="@lang">
601 <xsl:text> and @lang=</xsl:text>
602 <xsl:value-of select="@lang"/>
603 </xsl:if>
604 <xsl:text>]</xsl:text>
605 </xsl:attribute>
606 <xslt:if test="{$postest}">
607 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
608 </xslt:if>
609 <xsl:copy-of select="$prefix"/>
610 <xsl:choose>
611 <xsl:when test="@format">
612 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
613 </xsl:when>
614 <xsl:when test="@highlight"><xslt:call-template name="displayMarkedUpTextAndAnnotations"/>
615 </xsl:when>
616 <xsl:otherwise>
617 <xslt:value-of disable-output-escaping='yes' select="."/>
618 </xsl:otherwise>
619 </xsl:choose>
620 </xslt:if>
621 <xsl:copy-of select="$suffix"/>
622 </xslt:for-each>
623 </xsl:if>
624 </xsl:template>
625
626
627 <xsl:template match="gsf:foreach-metadata">
628 <xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
629 <xslt:for-each>
630 <xsl:attribute name="select">
631 (<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>
632 </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>
633 <xsl:apply-templates/>
634 </xslt:for-each>
635 </xsl:template>
636
637 <xsl:template match="gsf:meta-value">
638 <xslt:value-of select="."/>
639 </xsl:template>
640
641 <xsl:template name="getMetadataName">
642 <xsl:if test='@select'>
643 <xsl:value-of select='@select'/>
644 <xsl:text>_</xsl:text>
645 </xsl:if>
646 <xsl:call-template name="stripEx"><xsl:with-param name="meta-name" select="@name"/></xsl:call-template>
647 </xsl:template>
648
649 <!-- 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 -->
650 <xsl:template name="stripEx">
651 <xsl:param name="meta-name"/>
652 <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>
653 </xsl:template>
654
655 <!-- if we have metadata name="dc.Date,Date" will make a test like (@name = 'dc.Date' or @name = 'Date') -->
656 <xsl:template name="getMetadataTest">
657 <xsl:variable name="selectattr"><xsl:value-of select='@select'/></xsl:variable>
658 (<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>)
659 </xsl:template>
660
661 <xsl:template match="gsf:text">
662 <xsl:variable name="force">
663 <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>
664 </xsl:variable>
665 <xslt:call-template name="documentNodeText"><xslt:with-param name="force"><xsl:value-of select="$force"/></xslt:with-param></xslt:call-template>
666 </xsl:template>
667
668 <xsl:template match="gsf:if-metadata-exists">
669 <xsl:variable name="meta-path">
670 <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>
671 </xsl:variable>
672 <xslt:choose>
673 <xslt:when test="{$meta-path}">
674 <xsl:apply-templates select="gsf:if/node()"/>
675 </xslt:when>
676 <xsl:if test="gsf:else">
677 <xslt:otherwise>
678 <xsl:apply-templates select="gsf:else/node()"/>
679 </xslt:otherwise>
680 </xsl:if>
681 </xslt:choose>
682 </xsl:template>
683
684 <xsl:template match="gsf:choose-metadata">
685 <xslt:choose>
686 <xsl:for-each select="gsf:metadata">
687 <xslt:when>
688 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
689 <xsl:apply-templates select="."/>
690 </xslt:when>
691 </xsl:for-each>
692 <xsl:if test="gsf:default">
693 <xslt:otherwise>
694 <xsl:apply-templates select="gsf:default/node()"/>
695 </xslt:otherwise>
696 </xsl:if>
697 </xslt:choose>
698 </xsl:template>
699
700 <xsl:template match="gsf:switch">
701 <xsl:variable name="meta-name">
702 <xsl:for-each select="gsf:metadata">
703 <xsl:call-template name="getMetadataName"/>
704 </xsl:for-each>
705 </xsl:variable>
706 <xslt:variable name="meta">
707 <xsl:choose>
708 <xsl:when test="@preprocess">
709 <xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/>
710 </xsl:when>
711 <xsl:otherwise>
712 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/>
713 </xsl:otherwise>
714 </xsl:choose>
715 </xslt:variable>
716 <xslt:choose>
717 <xsl:for-each select="gsf:when">
718 <xslt:when test="util:{@test}($meta, '{@test-value}')">
719 <xsl:apply-templates/>
720 </xslt:when>
721 </xsl:for-each>
722 <xsl:if test="gsf:otherwise">
723 <xslt:otherwise>
724 <xsl:apply-templates select="gsf:otherwise/node()"/>
725 </xslt:otherwise>
726 </xsl:if>
727 </xslt:choose>
728 </xsl:template>
729
730 <!--
731 <gsf:headMetaTags> exists for controlling the <meta name="x" content="y"> elements that appear in the HTML <head></head>
732 XPATH is used to select this item (in header.xsl). It does not need an explicit definition here in this file
733 -->
734 <!-- this template is used to avoid the user having to type
735 <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 -->
736 <xsl:template match="gsf:html">
737 <xslt:text disable-output-escaping="yes"><xsl:value-of select="."/></xslt:text>
738 </xsl:template>
739 <!-- use this if you want a space after an element in the output.
740 e.g. <strong>Title:><gsf:space/></strong -->
741 <xsl:template match="gsf:space">&#160;</xsl:template>
742 <xsl:template match="*">
743 <xsl:copy>
744 <xsl:copy-of select="@*"/>
745 <xsl:apply-templates/>
746 </xsl:copy>
747 </xsl:template>
748
749</xsl:stylesheet>
750
751
Note: See TracBrowser for help on using the repository browser.