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, 7 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
RevLine 
[19860]1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet version="1.0"
[24115]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"
[29093]7 xmlns:xalan="http://xml.apache.org/xalan"
[24115]8 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
[29093]9 extension-element-prefixes="java xalan">
[24458]10 <xsl:param name="interface_name"/>
11 <xsl:param name="library_name"/>
[26326]12 <xsl:param name="site_name"/>
[30478]13 <xsl:param name="use_client_side_xslt"/>
[26326]14 <xsl:param name="collName"/>
[26460]15
[24115]16 <xsl:output method="xml"/>
17 <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
[19860]18
[29035]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
[24115]23 <xsl:template match="format">
24 <format>
25 <xsl:apply-templates/>
26 </format>
27 </xsl:template>
[26460]28
[24115]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>
[26460]40
[24458]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">
[26500]47 gs.variables.<xsl:value-of select="@name"/>
48 <xslt:text disable-output-escaping="yes"> = "</xslt:text>
49 <xsl:apply-templates/>
[26460]50 <xslt:text disable-output-escaping="yes">";</xslt:text>
[24458]51 </script>
52 </xsl:template>
[26460]53
[28749]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
[24792]68 <xsl:template match="gsf:defaultClassifierNode">
69 <xslt:call-template name="defaultClassifierNode"/>
70 </xsl:template>
[25002]71
[26439]72
73 <xsl:template match="gsf:script[@src]">
[26460]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>
[30868]79 <xslt:comment/>
[26460]80 <!-- comment used to ensure script tag is not collapsed -->
81 </script>
[26439]82 </xsl:template>
83
84
85 <xsl:template match="gsf:script">
[26460]86 <script type="text/javascript">
87 <xslt:text disable-output-escaping="yes">
88 <xsl:apply-templates/>
89 </xslt:text>
90 </script>
[26439]91 </xsl:template>
92
93 <xsl:template match="gsf:style[@src]">
[26460]94 <link rel="stylesheet" type="text/css">
95 <xsl:attribute name='href'>
96 <xsl:value-of select="@src"/>
97 </xsl:attribute>
98 </link>
[26439]99 </xsl:template>
100
101 <xsl:template match="gsf:style">
[26460]102 <style type="text/css">
103 <xsl:apply-templates/>
104 </style>
[26439]105 </xsl:template>
106
[29936]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
[31537]112 incorrectly rendered as HTML). Doing this with the
[29936]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
[31537]118 have no content of any form.
[29936]119 -->
[26439]120
[29936]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
[25002]133 <xsl:template match="gsf:image">
[26022]134 <xslt:variable name="metaName">
[26020]135 <xsl:choose>
[29936]136 <xsl:when test="@type = 'thumb'">Thumb</xsl:when>
[26020]137 <xsl:when test="@type = 'screen'">Screen</xsl:when>
138 <xsl:when test="@type = 'source'">SourceFile</xsl:when>
[30689]139 <xsl:when test="@type = 'cover'">hascover</xsl:when>
[26020]140 </xsl:choose>
[26022]141 </xslt:variable>
[30727]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>
[30689]152 <xslt:if test="./metadataList/metadata[@name = $metaName]">
[26020]153 <img>
154 <xslt:attribute name='src'>
155 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
[30727]156 <xsl:text>/index/assoc/</xsl:text><xslt:value-of disable-output-escaping="yes" select="$thisAssocfilepath" /><xsl:text>/</xsl:text>
[30689]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>
[26020]163 </xslt:attribute>
[30689]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
[26020]171 </img>
[26022]172 </xslt:if>
[25002]173 </xsl:template>
174
[30535]175 <!-- make this empty so we don't process the params element again inside the gsf:link type=query-->
[26500]176 <xsl:template match="params"></xsl:template>
177
[24115]178 <xsl:template match="gsf:link">
[26467]179
[30478]180 <xslt:variable name="collNameLocal" select="/page/pageResponse/collection/@name"/>
[26460]181 <xsl:variable name="opt-title">
182 <xsl:choose>
[26467]183 <xsl:when test="@title">
184 <xslt:attribute name="title">
185 <xsl:value-of select="@title"/>
186 </xslt:attribute>
[26460]187 </xsl:when>
[26467]188 <xsl:when test="@titlekey">
189 <xslt:attribute name="title">
[30478]190 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collNameLocal, $site_name, /page/@lang, '{@titlekey}')"/>
[26467]191 </xslt:attribute>
[26460]192 </xsl:when>
193 </xsl:choose>
194 </xsl:variable>
[26467]195
[24115]196 <xsl:choose>
[26326]197 <xsl:when test="@type='query'">
198 <a>
[26504]199 <xsl:if test="@target">
200 <xsl:attribute name='target'>
201 <xsl:value-of select='@target'/>
202 </xsl:attribute>
203 </xsl:if>
[31942]204
[26326]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>
[30535]218 <xsl:for-each select="params">?rt=rd&amp;<xsl:apply-templates/></xsl:for-each>
219
[26326]220 </xslt:attribute>
[26460]221 <xsl:copy-of select="$opt-title"/>
[26326]222 <xsl:apply-templates/>
223 </a>
224 </xsl:when>
[24115]225 <xsl:when test="@type='classifier'">
226 <a>
[26504]227 <xsl:if test="@target">
228 <xsl:attribute name='target'>
229 <xsl:value-of select='@target'/>
230 </xsl:attribute>
231 </xsl:if>
232
[31656]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>
[24115]234 </xslt:attribute>
[26460]235 <xsl:copy-of select="$opt-title"/>
[24115]236 <xsl:apply-templates/>
237 </a>
238 </xsl:when>
[24127]239 <xsl:when test="@type='source'">
[29234]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>
[30727]246 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='root_assocfilepath']" />
[29234]247 </xslt:otherwise>
248 </xslt:choose>
249 </xslt:variable>
[31942]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>
[26504]257 <a>
[29234]258 <xsl:if test="@target">
[26504]259 <xsl:attribute name='target'>
260 <xsl:value-of select='@target'/>
261 </xsl:attribute>
262 </xsl:if>
[30868]263 <xslt:attribute name='href'>
[26460]264 <xslt:value-of
[24127]265 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
[29234]266 disable-output-escaping="yes" select="$thisAssocfilepath" />/<xslt:value-of
[31942]267 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='{$image_meta}']" />
[26460]268 </xslt:attribute>
269 <xsl:copy-of select="$opt-title"/>
270 <xsl:apply-templates/>
[24127]271 </a>
272 </xsl:when>
[26043]273 <xsl:when test="@type='web'">
[26460]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')]"/>
[26043]277 </xsl:when>
[26326]278 <xsl:when test="@type='page'">
[26317]279 <a>
[26504]280 <xsl:if test="@target">
281 <xsl:attribute name='target'>
282 <xsl:value-of select='@target'/>
283 </xsl:attribute>
284 </xsl:if>
285
[26317]286 <xslt:attribute name='href'>
287 <xslt:value-of select='$library_name'/>
288 <xsl:text>/collection/</xsl:text>
[26326]289 <xslt:value-of select='/page/pageResponse/collection/@name'/>
290 <xsl:text>/page/</xsl:text>
291 <xsl:value-of select="@page"/>
292 </xslt:attribute>
[26460]293 <xsl:copy-of select="$opt-title"/>
294 <xsl:apply-templates/>
[26317]295 </a>
[26326]296 </xsl:when>
[26043]297 <xsl:when test="@type='equivdoc'">
[26460]298 <xsl:call-template name="gsf:equivlinkgs3"/>
[26043]299 </xsl:when>
[27101]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>
[30868]312 <xsl:otherwise>
[26460]313 <!-- a document link -->
[24115]314 <xslt:variable name="bookswitch">
315 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
316 </xslt:variable>
[25361]317 <a>
[26504]318 <xsl:if test="@target">
319 <xsl:attribute name='target'>
320 <xsl:value-of select='@target'/>
321 </xsl:attribute>
322 </xsl:if>
323
[26460]324 <xsl:copy-of select="$opt-title"/>
[25361]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>
[26460]330 <xsl:choose>
[30868]331 <xsl:when test="@OID">
332 <xsl:value-of select="@OID"/>
[26460]333 </xsl:when>
[30868]334 <xsl:when test="@OIDmetadata">
335 <xsl:variable name="OIDmeta" select="@OIDmetadata"/>
336 <xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/>
[26460]337 </xsl:when>
[30868]338 <xsl:otherwise>
339 <xslt:value-of select='@nodeID'/>
[26460]340 </xsl:otherwise>
341 </xsl:choose>
[25919]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>
[30868]347 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
[26460]348 </xslt:if>
[25919]349 </xslt:otherwise>
350 </xslt:choose>
[25361]351 </xslt:attribute>
352 <xsl:apply-templates/>
353 </a>
[24115]354 </xsl:otherwise>
355 </xsl:choose>
356 </xsl:template>
[28036]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>
[24115]364 <xsl:template match="gsf:icon">
365 <xsl:choose>
366 <xsl:when test="@type='classifier'">
[30868]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>
[26460]371 </img>
[24115]372 </xsl:when>
[26043]373 <xsl:when test="@type='web'">
[26460]374 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
[26043]375 </xsl:when>
[26121]376 <xsl:when test="@file">
[26460]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>
[26121]390 </xsl:when>
[25361]391 <xsl:when test="not(@type) or @type='document'">
[30868]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>
[26460]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>
[30868]404 </xslt:attribute>
[26460]405 </img>
[24115]406 </xsl:when>
407 </xsl:choose>
408 </xsl:template>
[26460]409
410 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
411 <!--<xsl:template match="gsf:equivlinkgs3">
[26023]412 <xslt:call-template name="equivDocLinks">
413 <xslt:with-param name="count" select="0"/>
414 </xslt:call-template>
[26031]415 </xsl:template>-->
[26023]416
[26460]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')]"/>
[26023]422
[26460]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>
[26023]426
[26460]427 <!--
[26023]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
[25941]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>
[24359]448
[25752]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. -->
[25732]452 <xsl:template match="gsf:displayText">
[26460]453 <xslt:variable name="displaytext">
454 <xsl:call-template name="gsf:displayItem"/>
455 </xslt:variable>
[25752]456
[26460]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>
[25752]465
[26460]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>
[25752]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">
[31066]480 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItemList/displayItem[@name='{@name}']"/>
[25732]481 </xsl:template>
482
[25752]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">
[26460]485 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
[25732]486 </xsl:template>
[26250]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">
[26460]489 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
[26387]490 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
[26250]491 </xsl:template>
[25732]492
[24792]493 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
[26176]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 -->
[29245]497 <xsl:variable name="meta_test"><xsl:call-template name="getMetadataTest"/></xsl:variable>
[26176]498 <xsl:variable name="separator">
499 <xsl:choose>
[30868]500 <xsl:when test="@separator">
[29271]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>
[30868]509 <xsl:value-of disable-output-escaping='yes' select="@separator"/>
[29271]510 </xsl:otherwise>
511 </xsl:choose>
[26460]512 </xsl:when>
[30868]513 <xsl:when test="separator">
514 <xsl:copy-of select="separator/node()"/>
[26460]515 </xsl:when>
[30868]516 <xsl:otherwise>
517 <xsl:text>, </xsl:text>
[26460]518 </xsl:otherwise>
[26176]519 </xsl:choose>
520 </xsl:variable>
521 <xsl:variable name="prefix">
522 <xsl:choose>
[30868]523 <xsl:when test="@prefix">
524 <xsl:value-of disable-output-escaping='yes' select="@prefix"/>
[26460]525 </xsl:when>
[30868]526 <xsl:when test="prefix">
527 <xsl:copy-of select="prefix/node()"/>
[26460]528 </xsl:when>
[26176]529 </xsl:choose>
530 </xsl:variable>
531 <xsl:variable name="suffix">
532 <xsl:choose>
[30868]533 <xsl:when test="@suffix">
534 <xsl:value-of disable-output-escaping='yes' select="@suffix"/>
[26460]535 </xsl:when>
[30868]536 <xsl:when test="suffix">
537 <xsl:copy-of select="suffix/node()"/>
[26460]538 </xsl:when>
[26176]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>
[29091]545 <xsl:when test="@pos = 'classifiedBy'">position() = number(../../@mdoffset)+1</xsl:when>
[30868]546 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
[26460]547 </xsl:when>
[26176]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">
[30868]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>
[26460]563 <xsl:text>]</xsl:text>
[26176]564 </xsl:attribute>
565 <xslt:if test="{$postest}">
[30868]566 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
[26460]567 </xslt:if>
[26176]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>
[26092]582
[26500]583
[26467]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">
[28307]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>
[29769]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>
[26467]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>
[26092]597
[26500]598 <xsl:template name="getMetadataName">
599 <xsl:if test='@select'>
600 <xsl:value-of select='@select'/>
601 <xsl:text>_</xsl:text>
602 </xsl:if>
[29834]603 <xsl:call-template name="stripEx"><xsl:with-param name="meta-name" select="@name"/></xsl:call-template>
[26500]604 </xsl:template>
[26467]605
[29834]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
[29111]612 <!-- if we have metadata name="dc.Date,Date" will make a test like (@name = 'dc.Date' or @name = 'Date') -->
[29093]613 <xsl:template name="getMetadataTest">
[29245]614 <xsl:variable name="selectattr"><xsl:value-of select='@select'/></xsl:variable>
[29834]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>)
[29093]616 </xsl:template>
[26500]617
[24115]618 <xsl:template match="gsf:text">
[26020]619 <xslt:call-template name="documentNodeText"/>
[24115]620 </xsl:template>
[26387]621
[26460]622 <xsl:template match="gsf:if-metadata-exists">
[30868]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>
[26460]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">
[30868]631 <xslt:otherwise>
[26460]632 <xsl:apply-templates select="gsf:else/node()"/>
633 </xslt:otherwise>
634 </xsl:if>
635 </xslt:choose>
636 </xsl:template>
637
[24792]638 <xsl:template match="gsf:choose-metadata">
639 <xslt:choose>
640 <xsl:for-each select="gsf:metadata">
641 <xslt:when>
[26093]642 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
[24792]643 <xsl:apply-templates select="."/>
644 </xslt:when>
645 </xsl:for-each>
646 <xsl:if test="gsf:default">
[30868]647 <xslt:otherwise>
648 <xsl:apply-templates select="gsf:default"/>
[26460]649 </xslt:otherwise>
[24792]650 </xsl:if>
651 </xslt:choose>
652 </xsl:template>
[26460]653
[24115]654 <xsl:template match="gsf:switch">
[30868]655 <xsl:variable name="meta-name">
656 <xsl:for-each select="gsf:metadata">
657 <xsl:call-template name="getMetadataName"/>
658 </xsl:for-each>
[26460]659 </xsl:variable>
[30868]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>
[26460]669 </xslt:variable>
[24115]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>
[26460]683
[26500]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 -->
[30544]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>
[31179]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>
[24115]696 <xsl:template match="*">
697 <xsl:copy>
[26460]698 <xsl:copy-of select="@*"/>
[24115]699 <xsl:apply-templates/>
700 </xsl:copy>
701 </xsl:template>
[19860]702
703</xsl:stylesheet>
704
705
Note: See TracBrowser for help on using the repository browser.