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

Last change on this file since 31942 was 31942, checked in by kjdon, 3 years ago

added the ability to change the file to be used in a source link through the source_meta attribute to gsf:link

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