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

Last change on this file since 37960 was 37960, checked in by kjdon, 10 months ago

some mods for gsf:metadata-table. we need to apply-templates instead of copying gsf elements - otherwise it won't get resolved properly if this is used in an xsl file. It worked previously in collectionConfig format statement, as that gets a expand-gsf pass over it before getting added to the main xsl, which means it effectively gets two passes of expanding gsf.

File size: 31.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 name="gsf:assocfilepathVariable">
144 <xslt:variable name="thisAssocfilepath">
145 <xslt:choose>
146 <xslt:when test="/page/pageResponse/document">
147 <xslt:choose>
148 <xslt:when test="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']">
149 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/metadataList/metadata[@name='assocfilepath']" />
150 </xslt:when>
151 <xslt:otherwise>
152 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode[@nodeType='root']/metadataList/metadata[@name='assocfilepath']" />
153 </xslt:otherwise>
154 </xslt:choose>
155 </xslt:when>
156 <xslt:otherwise>
157 <xslt:choose>
158 <xslt:when test="metadataList/metadata[@name='assocfilepath']">
159 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='assocfilepath']" />
160 </xslt:when>
161 <xslt:otherwise>
162 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='root_assocfilepath']" />
163 </xslt:otherwise>
164 </xslt:choose>
165 </xslt:otherwise>
166 </xslt:choose>
167 </xslt:variable>
168
169 </xsl:template>
170
171 <xsl:template match="gsf:image">
172 <xslt:variable name="metaName">
173 <xsl:choose>
174 <xsl:when test="@type = 'thumb'">Thumb</xsl:when>
175 <xsl:when test="@type = 'screen'">Screen</xsl:when>
176 <xsl:when test="@type = 'source'">SourceFile</xsl:when>
177 <xsl:when test="@type = 'image'">Image</xsl:when>
178 <xsl:when test="@type = 'cover'">root_hascover</xsl:when>
179 </xsl:choose>
180 </xslt:variable>
181 <!-- output the $thisAssocfilepath variable definition-->
182 <xsl:call-template name="gsf:assocfilepathVariable"/>
183 <xslt:if test="./metadataList/metadata[@name = $metaName]">
184 <img>
185 <xslt:attribute name='src'>
186 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
187 <xsl:text>/index/assoc/</xsl:text><xslt:value-of disable-output-escaping="yes" select="$thisAssocfilepath" /><xsl:text>/</xsl:text>
188 <xslt:choose>
189 <xslt:when test="$metaName = 'root_hascover'">cover.jpg</xslt:when>
190 <xslt:otherwise>
191 <xslt:value-of disable-output-escaping="yes" select="./metadataList/metadata[@name = $metaName]"/>
192 </xslt:otherwise>
193 </xslt:choose>
194 </xslt:attribute>
195 <!-- copy any other attributes apart from type-->
196 <xsl:for-each select="@*[name() != 'type']">
197 <xslt:attribute name="{name()}">
198 <xsl:value-of select="."/>
199 </xslt:attribute>
200 </xsl:for-each>
201
202 </img>
203 </xslt:if>
204 </xsl:template>
205
206 <!-- make this empty so we don't process the params element again inside the gsf:link type=query-->
207 <xsl:template match="params"></xsl:template>
208
209 <xsl:template match="gsf:collectionPath">
210 <xslt:value-of select='$library_name'/>
211 <xsl:text>/collection/</xsl:text>
212 <xslt:value-of select='/page/pageResponse/collection/@name'/>
213 </xsl:template>
214
215 <xsl:template match="gsf:link">
216
217 <xslt:variable name="collNameLocal" select="/page/pageResponse/collection/@name"/>
218 <xsl:variable name="opt-title">
219 <xsl:choose>
220 <xsl:when test="@title">
221 <xslt:attribute name="title">
222 <xsl:value-of select="@title"/>
223 </xslt:attribute>
224 </xsl:when>
225 <xsl:when test="@titlekey">
226 <xslt:attribute name="title">
227 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collNameLocal, $site_name, /page/@lang, '{@titlekey}')"/>
228 </xslt:attribute>
229 </xsl:when>
230 </xsl:choose>
231 </xsl:variable>
232
233 <xsl:choose>
234 <xsl:when test="@type='query'">
235 <a>
236 <xsl:if test="@target">
237 <xsl:attribute name='target'>
238 <xsl:value-of select='@target'/>
239 </xsl:attribute>
240 </xsl:if>
241
242 <xslt:attribute name='href'>
243 <xslt:value-of select='$library_name'/>
244 <xsl:text>/collection/</xsl:text>
245 <xslt:value-of select='/page/pageResponse/collection/@name'/>
246 <xsl:text>/search/</xsl:text>
247 <xsl:choose>
248 <xsl:when test="@name">
249 <xsl:value-of select="@name"/>
250 </xsl:when>
251 <xsl:otherwise>
252 <xsl:text>TextQuery</xsl:text>
253 </xsl:otherwise>
254 </xsl:choose>
255 <xsl:for-each select="params">?rt=rd&amp;<xsl:apply-templates/></xsl:for-each>
256
257 </xslt:attribute>
258 <xsl:copy-of select="$opt-title"/>
259 <xsl:apply-templates/>
260 </a>
261 </xsl:when>
262 <xsl:when test="@type='classifier'">
263 <a>
264 <xsl:if test="@target">
265 <xsl:attribute name='target'>
266 <xsl:value-of select='@target'/>
267 </xsl:attribute>
268 </xsl:if>
269
270 <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>
271 </xslt:attribute>
272 <xsl:copy-of select="$opt-title"/>
273 <xsl:apply-templates/>
274 </a>
275 </xsl:when>
276 <xsl:when test="@type='source'">
277 <xsl:call-template name="gsf:assocfilepathVariable"/>
278 <xsl:variable name="image_meta">
279 <xsl:choose>
280 <xsl:when test="@source_meta"><xsl:value-of select="@source_meta"/>
281 </xsl:when>
282 <xsl:otherwise>srclinkFile</xsl:otherwise>
283 </xsl:choose>
284 </xsl:variable>
285 <a>
286 <xsl:if test="@target">
287 <xsl:attribute name='target'>
288 <xsl:value-of select='@target'/>
289 </xsl:attribute>
290 </xsl:if>
291 <xsl:if test="@download">
292 <xsl:attribute name='download'>
293 <xsl:value-of select='@download'/>
294 </xsl:attribute>
295 </xsl:if>
296 <xslt:attribute name='href'>
297 <xslt:value-of
298 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
299 disable-output-escaping="yes" select="$thisAssocfilepath" />/<xslt:value-of
300 disable-output-escaping="yes" select="metadataList/metadata[@name='{$image_meta}']" />
301 </xslt:attribute>
302 <xsl:copy-of select="$opt-title"/>
303 <xsl:apply-templates/>
304 </a>
305 </xsl:when>
306 <xsl:when test="@type='web'">
307 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='weblink']"/>
308 <xsl:apply-templates/>
309 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='/weblink']"/>
310 </xsl:when>
311 <xsl:when test="@type='page'">
312 <a>
313 <xsl:if test="@target">
314 <xsl:attribute name='target'>
315 <xsl:value-of select='@target'/>
316 </xsl:attribute>
317 </xsl:if>
318
319 <xslt:attribute name='href'>
320 <xslt:value-of select='$library_name'/>
321 <xsl:text>/collection/</xsl:text>
322 <xslt:value-of select='/page/pageResponse/collection/@name'/>
323 <xsl:text>/page/</xsl:text>
324 <xsl:value-of select="@page"/>
325 </xslt:attribute>
326 <xsl:copy-of select="$opt-title"/>
327 <xsl:apply-templates/>
328 </a>
329 </xsl:when>
330 <xsl:when test="@type='equivdoc'">
331 <xsl:call-template name="gsf:equivlinkgs3"/>
332 </xsl:when>
333 <xsl:when test="@type='rss'">
334 <a>
335 <xslt:attribute name='href'>
336 <xslt:value-of select='$library_name'/>
337 <xsl:text>?a=rss&amp;l=en&amp;site=</xsl:text>
338 <xslt:value-of select="$site_name"/>
339 <xsl:text>&amp;c=</xsl:text>
340 <xslt:value-of select='/page/pageResponse/collection/@name'/>
341 </xslt:attribute>
342 <xsl:apply-templates/>
343 </a>
344 </xsl:when>
345 <xsl:otherwise>
346 <!-- a document link -->
347 <xslt:variable name="bookswitch">
348 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
349 </xslt:variable>
350
351 <a>
352 <xsl:if test="@target">
353 <xsl:attribute name='target'>
354 <xsl:value-of select='@target'/>
355 </xsl:attribute>
356 </xsl:if>
357
358 <xsl:copy-of select="$opt-title"/>
359 <xslt:attribute name="href">
360 <xslt:value-of select='$library_name'/>
361 <xsl:text>/collection/</xsl:text>
362 <xslt:value-of select='/page/pageResponse/collection/@name'/>
363 <xsl:text>/document/</xsl:text>
364 <xsl:choose>
365 <xsl:when test="@OID">
366 <xsl:value-of select="@OID"/>
367 </xsl:when>
368 <xsl:when test="@OIDmetadata">
369 <xsl:variable name="OIDmeta" select="@OIDmetadata"/>
370 <xslt:value-of select="metadataList/metadata[@name='{$OIDmeta}']"/>
371 </xsl:when>
372 <xsl:otherwise>
373 <xslt:value-of select='@nodeID'/>
374 </xsl:otherwise>
375 </xsl:choose>
376 <xslt:choose>
377 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
378 <xsl:text>?book=on</xsl:text>
379 </xslt:when>
380 <xslt:otherwise>
381 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
382 </xslt:if>
383 </xslt:otherwise>
384 </xslt:choose>
385 </xslt:attribute>
386 <xsl:apply-templates/>
387 </a>
388 </xsl:otherwise>
389 </xsl:choose>
390 </xsl:template>
391
392 <xsl:template match="gsf:OID">
393 <xslt:value-of select="@nodeID"/>
394 </xsl:template>
395 <xsl:template match="gsf:rank">
396 <xslt:value-of select="@rank"/>
397 </xsl:template>
398 <xsl:template match="gsf:icon">
399 <xsl:choose>
400 <xsl:when test="@type='classifier'">
401 <img style="border:0px">
402 <xsl:attribute name="src">
403 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/>
404 </xsl:attribute>
405 </img>
406 </xsl:when>
407 <xsl:when test="@type='web'">
408 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
409 </xsl:when>
410 <xsl:when test="@file">
411 <img>
412 <xslt:attribute name='src'>
413 <xsl:choose>
414 <xsl:when test="not(@select) or @select='site'">
415 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
416 </xsl:when>
417 <xsl:when test="@select='collection'">
418 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
419 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
420 </xsl:when>
421 </xsl:choose>
422 </xslt:attribute>
423 <xsl:if test="@alt">
424 <xslt:attribute name='alt'>
425 <xsl:value-of select="@alt" />
426 </xslt:attribute>
427 </xsl:if>
428 </img>
429 </xsl:when>
430 <xsl:when test="not(@type) or @type='document'">
431 <img style="border:0px">
432 <xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
433 </xslt:attribute>
434 <xslt:attribute name="src">
435 <xslt:choose>
436 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
437 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
438 </xslt:when>
439 <xslt:when test="@docType='paged' 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/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/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:metadata-table">
675 <table class="metadataTable">
676 <tbody>
677 <xsl:for-each select="gsf:metadata">
678 <xsl:variable name="meta-path">(./metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']<xsl:if test="@pos">[<xsl:value-of select="@pos"/>]</xsl:if></xsl:variable>
679
680 <xslt:if><xsl:attribute name="test"><xsl:choose><xsl:when test="@show-if-empty='true'">true()</xsl:when><xsl:otherwise><xsl:value-of select="$meta-path"/></xsl:otherwise></xsl:choose></xsl:attribute>
681 <tr>
682 <td>
683 <xsl:choose>
684 <xsl:when test="./displayItem">
685 <xslt:variable name="di_list"><di_list><xsl:copy-of select="./displayItem"/></di_list></xslt:variable>
686 <xslt:value-of select="util:getCollectionDisplayItemText($di_list, /page/@lang, $site_name, $collName )"/>
687 </xsl:when>
688 <!-- just copy out the text content-->
689 <xsl:otherwise>
690 <xsl:apply-templates select="*[not(self::content)]|text()"/>
691 </xsl:otherwise>
692 </xsl:choose>
693 </td>
694 <td>
695 <xsl:choose>
696 <xsl:when test="./content"><xsl:apply-templates select="./content"/></xsl:when>
697 <xsl:otherwise>
698 <i><xsl:apply-templates select="."/></i>
699 </xsl:otherwise>
700 </xsl:choose>
701 </td>
702 </tr>
703 </xslt:if>
704 </xsl:for-each>
705
706 </tbody>
707 </table>
708 </xsl:template>
709
710
711 <xsl:template match="gsf:text">
712 <xsl:variable name="force">
713 <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>
714 </xsl:variable>
715 <xslt:call-template name="documentNodeText"><xslt:with-param name="force"><xsl:value-of select="$force"/></xslt:with-param></xslt:call-template>
716 </xsl:template>
717
718 <xsl:template match="gsf:if-metadata-exists">
719 <xsl:variable name="meta-path">
720 <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>
721 </xsl:variable>
722 <xslt:choose>
723 <xslt:when test="{$meta-path}">
724 <xsl:apply-templates select="gsf:if/node()"/>
725 </xslt:when>
726 <xsl:if test="gsf:else">
727 <xslt:otherwise>
728 <xsl:apply-templates select="gsf:else/node()"/>
729 </xslt:otherwise>
730 </xsl:if>
731 </xslt:choose>
732 </xsl:template>
733
734 <xsl:template match="gsf:choose-metadata">
735 <xslt:choose>
736 <xsl:for-each select="gsf:metadata">
737 <xslt:when>
738 <xsl:attribute name="test">metadataList/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
739 <xsl:apply-templates select="."/>
740 </xslt:when>
741 </xsl:for-each>
742 <xsl:if test="gsf:default">
743 <xslt:otherwise>
744 <xsl:apply-templates select="gsf:default/node()"/>
745 </xslt:otherwise>
746 </xsl:if>
747 </xslt:choose>
748 </xsl:template>
749
750 <xsl:template match="gsf:switch">
751 <xsl:variable name="meta-name">
752 <xsl:for-each select="gsf:metadata">
753 <xsl:call-template name="getMetadataName"/>
754 </xsl:for-each>
755 </xsl:variable>
756 <xslt:variable name="meta">
757 <xsl:choose>
758 <xsl:when test="@preprocess">
759 <xslt:value-of select="util:{@preprocess}(metadataList/metadata[@name='{$meta-name}'], /page/@lang )"/>
760 </xsl:when>
761 <xsl:otherwise>
762 <xslt:value-of select="metadataList/metadata[@name='{$meta-name}']"/>
763 </xsl:otherwise>
764 </xsl:choose>
765 </xslt:variable>
766 <xslt:choose>
767 <xsl:for-each select="gsf:when">
768 <xslt:when test="util:{@test}($meta, '{@test-value}')">
769 <xsl:apply-templates/>
770 </xslt:when>
771 </xsl:for-each>
772 <xsl:if test="gsf:otherwise">
773 <xslt:otherwise>
774 <xsl:apply-templates select="gsf:otherwise/node()"/>
775 </xslt:otherwise>
776 </xsl:if>
777 </xslt:choose>
778 </xsl:template>
779
780 <!--
781 <gsf:headMetaTags> exists for controlling the <meta name="x" content="y"> elements that appear in the HTML <head></head>
782 XPATH is used to select this item (in header.xsl). It does not need an explicit definition here in this file
783 -->
784 <!-- this template is used to avoid the user having to type
785 <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 -->
786 <xsl:template match="gsf:html">
787 <xslt:text disable-output-escaping="yes"><xsl:value-of select="."/></xslt:text>
788 </xsl:template>
789 <!-- use this if you want a space after an element in the output.
790 e.g. <strong>Title:><gsf:space/></strong -->
791 <xsl:template match="gsf:space">&#160;</xsl:template>
792 <xsl:template match="*">
793 <xsl:copy>
794 <xsl:copy-of select="@*"/>
795 <xsl:apply-templates/>
796 </xsl:copy>
797 </xsl:template>
798
799</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.