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

Last change on this file since 36880 was 36880, checked in by kjdon, 18 months ago

factored out some code for setting up thisAssocfilepath, as its used in two places. all the places where we want to get something from metadataList, the code was doing (.metadataList)[last()]/metadata - this finds all the descendent metadatalists and chooses the last one. I don't know why this was done. as far as I am aware, we generally want the metadatalist of the current node. the downside of the former strategy is that it is order dependent. for example, when viewing a document, the toplevel metadata list is put after all the subsections, but when document editing, the subsections come after the metadata list. this means that the wrong metadatalist is chosen. I have changed these all back to just using the metadataList of the current node. this assumes that 1. there is only one metadataList, and 2. we are always calling these from hte node where the metadatalist is. there may be cases where we want a child nodes metadatalist - I think this should be handled explicitly, so we always know wheat we are getting, and the tree order doesn't matter.

File size: 30.7 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 = 'cover'">root_hascover</xsl:when>
178 </xsl:choose>
179 </xslt:variable>
180 <!-- output the $thisAssocfilepath variable definition-->
181 <xsl:call-template name="gsf:assocfilepathVariable"/>
182 <xslt:if test="./metadataList/metadata[@name = $metaName]">
183 <img>
184 <xslt:attribute name='src'>
185 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
186 <xsl:text>/index/assoc/</xsl:text><xslt:value-of disable-output-escaping="yes" select="$thisAssocfilepath" /><xsl:text>/</xsl:text>
187 <xslt:choose>
188 <xslt:when test="$metaName = 'root_hascover'">cover.jpg</xslt:when>
189 <xslt:otherwise>
190 <xslt:value-of disable-output-escaping="yes" select="./metadataList/metadata[@name = $metaName]"/>
191 </xslt:otherwise>
192 </xslt:choose>
193 </xslt:attribute>
194 <!-- copy any other attributes apart from type-->
195 <xsl:for-each select="@*[name() != 'type']">
196 <xslt:attribute name="{name()}">
197 <xsl:value-of select="."/>
198 </xslt:attribute>
199 </xsl:for-each>
200
201 </img>
202 </xslt:if>
203 </xsl:template>
204
205 <!-- make this empty so we don't process the params element again inside the gsf:link type=query-->
206 <xsl:template match="params"></xsl:template>
207
208 <xsl:template match="gsf:collectionPath">
209 <xslt:value-of select='$library_name'/>
210 <xsl:text>/collection/</xsl:text>
211 <xslt:value-of select='/page/pageResponse/collection/@name'/>
212 </xsl:template>
213
214 <xsl:template match="gsf:link">
215
216 <xslt:variable name="collNameLocal" select="/page/pageResponse/collection/@name"/>
217 <xsl:variable name="opt-title">
218 <xsl:choose>
219 <xsl:when test="@title">
220 <xslt:attribute name="title">
221 <xsl:value-of select="@title"/>
222 </xslt:attribute>
223 </xsl:when>
224 <xsl:when test="@titlekey">
225 <xslt:attribute name="title">
226 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collNameLocal, $site_name, /page/@lang, '{@titlekey}')"/>
227 </xslt:attribute>
228 </xsl:when>
229 </xsl:choose>
230 </xsl:variable>
231
232 <xsl:choose>
233 <xsl:when test="@type='query'">
234 <a>
235 <xsl:if test="@target">
236 <xsl:attribute name='target'>
237 <xsl:value-of select='@target'/>
238 </xsl:attribute>
239 </xsl:if>
240
241 <xslt:attribute name='href'>
242 <xslt:value-of select='$library_name'/>
243 <xsl:text>/collection/</xsl:text>
244 <xslt:value-of select='/page/pageResponse/collection/@name'/>
245 <xsl:text>/search/</xsl:text>
246 <xsl:choose>
247 <xsl:when test="@name">
248 <xsl:value-of select="@name"/>
249 </xsl:when>
250 <xsl:otherwise>
251 <xsl:text>TextQuery</xsl:text>
252 </xsl:otherwise>
253 </xsl:choose>
254 <xsl:for-each select="params">?rt=rd&amp;<xsl:apply-templates/></xsl:for-each>
255
256 </xslt:attribute>
257 <xsl:copy-of select="$opt-title"/>
258 <xsl:apply-templates/>
259 </a>
260 </xsl:when>
261 <xsl:when test="@type='classifier'">
262 <a>
263 <xsl:if test="@target">
264 <xsl:attribute name='target'>
265 <xsl:value-of select='@target'/>
266 </xsl:attribute>
267 </xsl:if>
268
269 <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>
270 </xslt:attribute>
271 <xsl:copy-of select="$opt-title"/>
272 <xsl:apply-templates/>
273 </a>
274 </xsl:when>
275 <xsl:when test="@type='source'">
276 <xsl:call-template name="gsf:assocfilepathVariable"/>
277 <xsl:variable name="image_meta">
278 <xsl:choose>
279 <xsl:when test="@source_meta"><xsl:value-of select="@source_meta"/>
280 </xsl:when>
281 <xsl:otherwise>srclinkFile</xsl:otherwise>
282 </xsl:choose>
283 </xsl:variable>
284 <a>
285 <xsl:if test="@target">
286 <xsl:attribute name='target'>
287 <xsl:value-of select='@target'/>
288 </xsl:attribute>
289 </xsl:if>
290 <xsl:if test="@download">
291 <xsl:attribute name='download'>
292 <xsl:value-of select='@download'/>
293 </xsl:attribute>
294 </xsl:if>
295 <xslt:attribute name='href'>
296 <xslt:value-of
297 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
298 disable-output-escaping="yes" select="$thisAssocfilepath" />/<xslt:value-of
299 disable-output-escaping="yes" select="metadataList/metadata[@name='{$image_meta}']" />
300 </xslt:attribute>
301 <xsl:copy-of select="$opt-title"/>
302 <xsl:apply-templates/>
303 </a>
304 </xsl:when>
305 <xsl:when test="@type='web'">
306 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='weblink']"/>
307 <xsl:apply-templates/>
308 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[@name='/weblink']"/>
309 </xsl:when>
310 <xsl:when test="@type='page'">
311 <a>
312 <xsl:if test="@target">
313 <xsl:attribute name='target'>
314 <xsl:value-of select='@target'/>
315 </xsl:attribute>
316 </xsl:if>
317
318 <xslt:attribute name='href'>
319 <xslt:value-of select='$library_name'/>
320 <xsl:text>/collection/</xsl:text>
321 <xslt:value-of select='/page/pageResponse/collection/@name'/>
322 <xsl:text>/page/</xsl:text>
323 <xsl:value-of select="@page"/>
324 </xslt:attribute>
325 <xsl:copy-of select="$opt-title"/>
326 <xsl:apply-templates/>
327 </a>
328 </xsl:when>
329 <xsl:when test="@type='equivdoc'">
330 <xsl:call-template name="gsf:equivlinkgs3"/>
331 </xsl:when>
332 <xsl:when test="@type='rss'">
333 <a>
334 <xslt:attribute name='href'>
335 <xslt:value-of select='$library_name'/>
336 <xsl:text>?a=rss&amp;l=en&amp;site=</xsl:text>
337 <xslt:value-of select="$site_name"/>
338 <xsl:text>&amp;c=</xsl:text>
339 <xslt:value-of select='/page/pageResponse/collection/@name'/>
340 </xslt:attribute>
341 <xsl:apply-templates/>
342 </a>
343 </xsl:when>
344 <xsl:otherwise>
345 <!-- a document link -->
346 <xslt:variable name="bookswitch">
347 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
348 </xslt:variable>
349
350 <a>
351 <xsl:if test="@target">
352 <xsl:attribute name='target'>
353 <xsl:value-of select='@target'/>
354 </xsl:attribute>
355 </xsl:if>
356
357 <xsl:copy-of select="$opt-title"/>
358 <xslt:attribute name="href">
359 <xslt:value-of select='$library_name'/>
360 <xsl:text>/collection/</xsl:text>
361 <xslt:value-of select='/page/pageResponse/collection/@name'/>
362 <xsl:text>/document/</xsl:text>
363 <xsl:choose>
364 <xsl:when test="@OID">
365 <xsl:value-of select="@OID"/>
366 </xsl:when>
367 <xsl:when test="@OIDmetadata">
368 <xsl:variable name="OIDmeta" select="@OIDmetadata"/>
369 <xslt:value-of select="metadataList/metadata[@name='{$OIDmeta}']"/>
370 </xsl:when>
371 <xsl:otherwise>
372 <xslt:value-of select='@nodeID'/>
373 </xsl:otherwise>
374 </xsl:choose>
375 <xslt:choose>
376 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
377 <xsl:text>?book=on</xsl:text>
378 </xslt:when>
379 <xslt:otherwise>
380 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
381 </xslt:if>
382 </xslt:otherwise>
383 </xslt:choose>
384 </xslt:attribute>
385 <xsl:apply-templates/>
386 </a>
387 </xsl:otherwise>
388 </xsl:choose>
389 </xsl:template>
390
391 <xsl:template match="gsf:OID">
392 <xslt:value-of select="@nodeID"/>
393 </xsl:template>
394 <xsl:template match="gsf:rank">
395 <xslt:value-of select="@rank"/>
396 </xsl:template>
397 <xsl:template match="gsf:icon">
398 <xsl:choose>
399 <xsl:when test="@type='classifier'">
400 <img style="border:0px">
401 <xsl:attribute name="src">
402 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/>
403 </xsl:attribute>
404 </img>
405 </xsl:when>
406 <xsl:when test="@type='web'">
407 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
408 </xsl:when>
409 <xsl:when test="@file">
410 <img>
411 <xslt:attribute name='src'>
412 <xsl:choose>
413 <xsl:when test="not(@select) or @select='site'">
414 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
415 </xsl:when>
416 <xsl:when test="@select='collection'">
417 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
418 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
419 </xsl:when>
420 </xsl:choose>
421 </xslt:attribute>
422 <xsl:if test="@alt">
423 <xslt:attribute name='alt'>
424 <xsl:value-of select="@alt" />
425 </xslt:attribute>
426 </xsl:if>
427 </img>
428 </xsl:when>
429 <xsl:when test="not(@type) or @type='document'">
430 <img style="border:0px">
431 <xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
432 </xslt:attribute>
433 <xslt:attribute name="src">
434 <xslt:choose>
435 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
436 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
437 </xslt:when>
438 <xslt:otherwise>
439 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
440 </xslt:otherwise>
441 </xslt:choose>
442 </xslt:attribute>
443 </img>
444 </xsl:when>
445 </xsl:choose>
446 </xsl:template>
447
448 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
449 <!--<xsl:template match="gsf:equivlinkgs3">
450 <xslt:call-template name="equivDocLinks">
451 <xslt:with-param name="count" select="0"/>
452 </xslt:call-template>
453 </xsl:template>-->
454
455 <!-- 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. -->
456 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
457 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
458 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
459 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
460
461 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
462 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
463 </xsl:template>
464
465 <!--
466In the collection's format statement, could have the following javascript+XSLT in place of
467the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
468<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
469</xsl:text>
470<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
471<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
472</xsl:text>
473<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
474<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
475</xsl:text>
476<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
477<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;
478</xsl:text>
479-->
480
481 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
482 <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> -->
483 <xsl:template match="gsf:cgi-param">
484 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
485 </xsl:template>
486
487 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
488 a string defined in either collectionConfig.xml or else the interface dictionaries.
489 If the requested string occurs in neither, the request string itself will be output. -->
490 <xsl:template match="gsf:displayText">
491 <xslt:variable name="displaytext">
492 <xsl:call-template name="gsf:displayItem"/>
493 </xslt:variable>
494
495 <xslt:choose>
496 <xslt:when test="$displaytext != ''">
497 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
498 </xslt:when>
499 <xslt:otherwise>
500 <xslt:variable name="interfacetxt">
501 <xsl:call-template name="gsf:interfaceText"/>
502 </xslt:variable>
503
504 <xslt:choose>
505 <xslt:when test="$interfacetxt != ''">
506 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
507 </xslt:when>
508 <xslt:otherwise>
509 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
510 </xslt:otherwise>
511 </xslt:choose>
512 </xslt:otherwise>
513 </xslt:choose>
514 </xsl:template>
515
516 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
517 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
518 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItemList/displayItem[@name='{@name}']"/>
519 </xsl:template>
520
521 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
522 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
523 <xsl:choose>
524 <xsl:when test="@propertyFile">
525 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, '{@propertyFile}', /page/@lang, '{@name}', '')"/>
526 </xsl:when>
527 <xsl:otherwise>
528 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
529 </xsl:otherwise>
530 </xsl:choose>
531 </xsl:template>
532
533 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
534 <xsl:template match="gsf:collectionText1" name="gsf:collectionText1">
535 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
536 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
537 </xsl:template>
538 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
539 <xsl:copy-of select="util:getCollectionText($collName, $site_name, $lang, @name, @args)/node()"/>
540 </xsl:template>
541
542
543 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
544 <xsl:template match="gsf:metadata">
545 <xsl:if test="not(@hidden = 'true')">
546 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
547 <xsl:variable name="meta_test"><xsl:call-template name="getMetadataTest"/></xsl:variable>
548 <xsl:variable name="separator">
549 <xsl:choose>
550 <xsl:when test="@separator">
551 <xsl:choose>
552 <xsl:when test="@separator = ' '">
553 <!-- http://stackoverflow.com/questions/1461649/how-to-insert-nbsp-in-xslt -->
554 <xsl:text>&#160;</xsl:text>
555 <!--<xsl:text> </xsl:text> only works in GLI's Format panel-->
556 <!--<xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>-->
557 </xsl:when>
558 <xsl:otherwise>
559 <xsl:value-of disable-output-escaping='yes' select="@separator"/>
560 </xsl:otherwise>
561 </xsl:choose>
562 </xsl:when>
563 <xsl:when test="separator">
564 <xsl:copy-of select="separator/node()"/>
565 </xsl:when>
566 <xsl:otherwise>
567 <xsl:text>, </xsl:text>
568 </xsl:otherwise>
569 </xsl:choose>
570 </xsl:variable>
571 <xsl:variable name="prefix">
572 <xsl:choose>
573 <xsl:when test="@prefix">
574 <xsl:value-of disable-output-escaping='yes' select="@prefix"/>
575 </xsl:when>
576 <xsl:when test="prefix">
577 <xsl:copy-of select="prefix/node()"/>
578 </xsl:when>
579 </xsl:choose>
580 </xsl:variable>
581 <xsl:variable name="suffix">
582 <xsl:choose>
583 <xsl:when test="@suffix">
584 <xsl:value-of disable-output-escaping='yes' select="@suffix"/>
585 </xsl:when>
586 <xsl:when test="suffix">
587 <xsl:copy-of select="suffix/node()"/>
588 </xsl:when>
589 </xsl:choose>
590 </xsl:variable>
591 <xsl:variable name="postest">
592 <xsl:choose>
593 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
594 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
595 <xsl:when test="@pos = 'classifiedBy'">position() = number(../../@mdoffset)+1</xsl:when>
596 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
597 </xsl:when>
598 <xsl:otherwise>true()</xsl:otherwise>
599 </xsl:choose>
600 </xsl:variable>
601 <xsl:variable name="multiple">
602 <xsl:choose>
603 <xsl:when test="@pos">false()</xsl:when>
604 <xsl:otherwise>true()</xsl:otherwise>
605 </xsl:choose>
606 </xsl:variable>
607 <xslt:for-each>
608 <xsl:attribute name="select">
609 <xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>metadataList/metadata[<xsl:value-of select="$meta_test"/><xsl:if test="@lang">
610 <xsl:text> and @lang=</xsl:text>
611 <xsl:value-of select="@lang"/>
612 </xsl:if>
613 <xsl:text>]</xsl:text>
614 </xsl:attribute>
615 <xslt:if test="{$postest}">
616 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
617 </xslt:if>
618 <xsl:copy-of select="$prefix"/>
619 <xsl:choose>
620 <xsl:when test="@format">
621 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
622 </xsl:when>
623 <xsl:when test="@highlight"><xslt:call-template name="displayMarkedUpTextAndAnnotations"/>
624 </xsl:when>
625 <xsl:otherwise>
626 <xslt:value-of disable-output-escaping='yes' select="."/>
627 </xsl:otherwise>
628 </xsl:choose>
629 </xslt:if>
630 <xsl:copy-of select="$suffix"/>
631 </xslt:for-each>
632 </xsl:if>
633 </xsl:template>
634
635
636 <xsl:template match="gsf:foreach-metadata">
637 <xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
638 <xslt:for-each>
639 <xsl:attribute name="select">
640 (<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>
641 </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>
642 <xsl:apply-templates/>
643 </xslt:for-each>
644 </xsl:template>
645
646 <xsl:template match="gsf:meta-value">
647 <xslt:value-of disable-output-escaping="yes" select="."/>
648 </xsl:template>
649
650 <xsl:template name="getMetadataName">
651 <xsl:if test='@select'>
652 <xsl:value-of select='@select'/>
653 <xsl:text>_</xsl:text>
654 </xsl:if>
655 <xsl:call-template name="stripEx"><xsl:with-param name="meta-name" select="@name"/></xsl:call-template>
656 </xsl:template>
657
658 <!-- 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 -->
659 <xsl:template name="stripEx">
660 <xsl:param name="meta-name"/>
661 <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>
662 </xsl:template>
663
664 <!-- if we have metadata name="dc.Date,Date" will make a test like (@name = 'dc.Date' or @name = 'Date') -->
665 <xsl:template name="getMetadataTest">
666 <xsl:variable name="selectattr"><xsl:value-of select='@select'/></xsl:variable>
667 (<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>)
668 </xsl:template>
669
670 <xsl:template match="gsf:metadata-table">
671 <table class="metadataTable">
672 <tbody>
673 <xsl:for-each select="gsf:metadata">
674
675 <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>
676
677 <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>
678 <tr>
679 <td>
680 <xsl:choose>
681 <xsl:when test="./displayItem">
682 <xslt:variable name="di_list"><di_list><xsl:copy-of select="./displayItem"/></di_list></xslt:variable>
683 <xslt:value-of select="util:getCollectionDisplayItemText($di_list, /page/@lang, $site_name, $collName )"/>
684 </xsl:when>
685 <!-- just copy out the text content-->
686 <xsl:otherwise>
687 <xsl:value-of select="."/>
688 </xsl:otherwise>
689 </xsl:choose>
690 </td>
691 <td>
692 <xsl:choose>
693 <xsl:when test="./content"><xsl:copy-of select="./content"/></xsl:when>
694 <xsl:otherwise>
695 <i><xsl:copy-of select="."/></i>
696 </xsl:otherwise>
697 </xsl:choose>
698 </td>
699 </tr>
700 </xslt:if>
701 </xsl:for-each>
702
703 </tbody>
704 </table>
705 </xsl:template>
706
707 <xsl:template match="gsf:text">
708 <xsl:variable name="force">
709 <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>
710 </xsl:variable>
711 <xslt:call-template name="documentNodeText"><xslt:with-param name="force"><xsl:value-of select="$force"/></xslt:with-param></xslt:call-template>
712 </xsl:template>
713
714 <xsl:template match="gsf:if-metadata-exists">
715 <xsl:variable name="meta-path">
716 <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>
717 </xsl:variable>
718 <xslt:choose>
719 <xslt:when test="{$meta-path}">
720 <xsl:apply-templates select="gsf:if/node()"/>
721 </xslt:when>
722 <xsl:if test="gsf:else">
723 <xslt:otherwise>
724 <xsl:apply-templates select="gsf:else/node()"/>
725 </xslt:otherwise>
726 </xsl:if>
727 </xslt:choose>
728 </xsl:template>
729
730 <xsl:template match="gsf:choose-metadata">
731 <xslt:choose>
732 <xsl:for-each select="gsf:metadata">
733 <xslt:when>
734 <xsl:attribute name="test">metadataList/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
735 <xsl:apply-templates select="."/>
736 </xslt:when>
737 </xsl:for-each>
738 <xsl:if test="gsf:default">
739 <xslt:otherwise>
740 <xsl:apply-templates select="gsf:default/node()"/>
741 </xslt:otherwise>
742 </xsl:if>
743 </xslt:choose>
744 </xsl:template>
745
746 <xsl:template match="gsf:switch">
747 <xsl:variable name="meta-name">
748 <xsl:for-each select="gsf:metadata">
749 <xsl:call-template name="getMetadataName"/>
750 </xsl:for-each>
751 </xsl:variable>
752 <xslt:variable name="meta">
753 <xsl:choose>
754 <xsl:when test="@preprocess">
755 <xslt:value-of select="util:{@preprocess}(metadataList/metadata[@name='{$meta-name}'], /page/@lang )"/>
756 </xsl:when>
757 <xsl:otherwise>
758 <xslt:value-of select="metadataList/metadata[@name='{$meta-name}']"/>
759 </xsl:otherwise>
760 </xsl:choose>
761 </xslt:variable>
762 <xslt:choose>
763 <xsl:for-each select="gsf:when">
764 <xslt:when test="util:{@test}($meta, '{@test-value}')">
765 <xsl:apply-templates/>
766 </xslt:when>
767 </xsl:for-each>
768 <xsl:if test="gsf:otherwise">
769 <xslt:otherwise>
770 <xsl:apply-templates select="gsf:otherwise/node()"/>
771 </xslt:otherwise>
772 </xsl:if>
773 </xslt:choose>
774 </xsl:template>
775
776 <!--
777 <gsf:headMetaTags> exists for controlling the <meta name="x" content="y"> elements that appear in the HTML <head></head>
778 XPATH is used to select this item (in header.xsl). It does not need an explicit definition here in this file
779 -->
780 <!-- this template is used to avoid the user having to type
781 <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 -->
782 <xsl:template match="gsf:html">
783 <xslt:text disable-output-escaping="yes"><xsl:value-of select="."/></xslt:text>
784 </xsl:template>
785 <!-- use this if you want a space after an element in the output.
786 e.g. <strong>Title:><gsf:space/></strong -->
787 <xsl:template match="gsf:space">&#160;</xsl:template>
788 <xsl:template match="*">
789 <xsl:copy>
790 <xsl:copy-of select="@*"/>
791 <xsl:apply-templates/>
792 </xsl:copy>
793 </xsl:template>
794
795</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.