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

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

when we are in editing mode, we haven't got assocfilepath at teh top document level. rather than wastingtime in the java code adding it there, lets just look for it in the first documentNode as that will have it.

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