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

Last change on this file since 33140 was 32601, checked in by davidb, 5 years ago

Introduction of double-quote gsf element to make writing JS within XSLT less cumbersome to write

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