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

Last change on this file since 26439 was 26439, checked in by davidb, 8 years ago

Some additional useful gsf:xx templates. One for including scripts, the other for CSS style

File size: 18.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:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
8 extension-element-prefixes="java">
9 <xsl:param name="interface_name"/>
10 <xsl:param name="library_name"/>
11 <xsl:param name="site_name"/>
12 <xsl:param name="collName"/>
13
14 <xsl:output method="xml"/>
15 <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
16
17 <xsl:template match="format">
18 <format>
19 <xsl:apply-templates/>
20 </format>
21 </xsl:template>
22
23 <xsl:template match="gsf:template">
24 <xslt:template>
25 <xsl:copy-of select="@*"/>
26 <xsl:attribute name="priority">2</xsl:attribute>
27 <xsl:if test=".//gsf:link">
28 <xslt:param name="serviceName"/>
29 <xslt:param name="collName"/>
30 </xsl:if>
31 <xsl:apply-templates/>
32 </xslt:template>
33 </xsl:template>
34
35 <xsl:template match="gsf:variable">
36 <xslt:variable>
37 <xsl:copy-of select="@*"/>
38 <xsl:apply-templates/>
39 </xslt:variable>
40 <script type="text/javascript">
41 gs.variables.<xsl:value-of select="@name"/><xslt:text disable-output-escaping="yes"> = "</xslt:text><xsl:apply-templates/><xslt:text disable-output-escaping="yes">";</xslt:text>
42 </script>
43 </xsl:template>
44
45 <xsl:template match="gsf:defaultClassifierNode">
46 <xslt:call-template name="defaultClassifierNode"/>
47 </xsl:template>
48
49
50 <xsl:template match="gsf:script[@src]">
51 <script>
52 <xsl:attribute name='src'>
53 <xsl:value-of select="@src"/>
54 </xsl:attribute>
55 <xslt:attribute name='type'>text/javascript</xslt:attribute>
56 <xslt:comment></xslt:comment><!-- comment used to ensure script tag is not collapsed -->
57 </script>
58 </xsl:template>
59
60
61 <xsl:template match="gsf:script">
62 <script type="text/javascript">
63 <xslt:text disable-output-escaping="yes">
64 <xsl:apply-templates/>
65 </xslt:text>
66 </script>
67 </xsl:template>
68
69
70 <xsl:template match="gsf:style[@src]">
71 <link rel="stylesheet" type="text/css">
72 <xsl:attribute name='href'>
73 <xsl:value-of select="@src"/>
74 </xsl:attribute>
75 </link>
76 </xsl:template>
77
78 <xsl:template match="gsf:style">
79 <style type="text/css">
80 <xsl:apply-templates/>
81 </style>
82 </xsl:template>
83
84
85 <xsl:template match="gsf:image">
86 <xslt:variable name="metaName">
87 <xsl:choose>
88 <xsl:when test="@type = 'thumb'">Thumb</xsl:when>
89 <xsl:when test="@type = 'screen'">Screen</xsl:when>
90 <xsl:when test="@type = 'source'">SourceFile</xsl:when>
91 </xsl:choose>
92 </xslt:variable>
93 <xslt:if test="(.//metadataList)[last()]/metadata[@name = $metaName]">
94 <img>
95 <xslt:attribute name='src'>
96 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']"/>
97 <xsl:text>/index/assoc/</xsl:text>
98 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/document/metadataList/metadata[@name = 'assocfilepath']"/>
99 <xsl:text>/</xsl:text>
100 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name = $metaName]"/>
101 </xslt:attribute>
102 </img>
103 </xslt:if>
104 </xsl:template>
105
106 <xsl:template match="gsf:link">
107 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
108 <xsl:variable name="opt-title">
109 <xsl:choose>
110 <xsl:when test="@title"><xslt:attribute name="title"><xsl:value-of select="@title"/></xslt:attribute></xsl:when>
111 <xsl:when test="@titlekey"><xslt:attribute name="title"><xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collName, $site_name, /page/@lang, '{@titlekey}')"/></xslt:attribute></xsl:when>
112 </xsl:choose>
113 </xsl:variable>
114 <xsl:choose>
115 <xsl:when test="@type='query'">
116 <a>
117 <xslt:attribute name='href'>
118 <xslt:value-of select='$library_name'/>
119 <xsl:text>/collection/</xsl:text>
120 <xslt:value-of select='/page/pageResponse/collection/@name'/>
121 <xsl:text>/search/</xsl:text>
122 <xsl:choose>
123 <xsl:when test="@name">
124 <xsl:value-of select="@name"/>
125 </xsl:when>
126 <xsl:otherwise>
127 <xsl:text>TextQuery</xsl:text>
128 </xsl:otherwise>
129 </xsl:choose>
130 </xslt:attribute>
131 <xsl:copy-of select="$opt-title"/>
132 <xsl:apply-templates/>
133 </a>
134 </xsl:when>
135 <xsl:when test="@type='classifier'">
136 <a>
137 <xslt:attribute name='href'>
138 <xslt:value-of select='$library_name'/>
139 <xsl:text>/collection/</xsl:text>
140 <xslt:value-of select='/page/pageResponse/collection/@name'/>
141 <xsl:text>/browse/</xsl:text>
142 <xsl:choose>
143 <xsl:when test="@nodeID">
144 <xsl:value-of select="@nodeID"/>
145 </xsl:when>
146 <xsl:otherwise>
147 <xslt:value-of select='util:replace(@nodeID, ".", "/")'/>
148 </xsl:otherwise>
149 </xsl:choose>
150 </xslt:attribute>
151 <xsl:copy-of select="$opt-title"/>
152 <xsl:apply-templates/>
153 </a>
154 </xsl:when>
155 <xsl:when test="@type='source'">
156 <a><xslt:attribute name='href'><xslt:value-of
157 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
158 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='assocfilepath']" />/<xslt:value-of
159 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='srclinkFile']" /></xslt:attribute>
160 <xsl:copy-of select="$opt-title"/>
161 <xsl:apply-templates/>
162 </a>
163 </xsl:when>
164 <xsl:when test="@type='web'">
165 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'weblink')]"/>
166 <xsl:apply-templates/>
167 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, '/weblink')]"/>
168 </xsl:when>
169 <xsl:when test="@type='page'">
170 <a>
171 <xslt:attribute name='href'>
172 <xslt:value-of select='$library_name'/>
173 <xsl:text>/collection/</xsl:text>
174 <xslt:value-of select='/page/pageResponse/collection/@name'/>
175 <xsl:text>/page/</xsl:text>
176 <xsl:value-of select="@page"/>
177 </xslt:attribute>
178 <xsl:copy-of select="$opt-title"/>
179 <xsl:apply-templates/>
180 </a>
181 </xsl:when>
182 <xsl:when test="@type='equivdoc'">
183 <xsl:call-template name="gsf:equivlinkgs3"/>
184 </xsl:when>
185 <xsl:otherwise> <!-- a document link -->
186 <xslt:variable name="bookswitch">
187 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
188 </xslt:variable>
189 <a>
190 <xsl:copy-of select="$opt-title"/>
191 <xslt:attribute name="href">
192 <xslt:value-of select='$library_name'/>
193 <xsl:text>/collection/</xsl:text>
194 <xslt:value-of select='/page/pageResponse/collection/@name'/>
195 <xsl:text>/document/</xsl:text>
196 <xsl:choose><xsl:when test="@OID"><xsl:value-of select="@OID"/></xsl:when><xsl:when test="@OIDmetadata"><xsl:variable name="OIDmeta" select="@OIDmetadata"/><xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/></xsl:when><xsl:otherwise>
197 <xslt:value-of select='@nodeID'/></xsl:otherwise></xsl:choose>
198 <xslt:choose>
199 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
200 <xsl:text>?book=on</xsl:text>
201 </xslt:when>
202 <xslt:otherwise>
203 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/></xslt:if>
204 </xslt:otherwise>
205 </xslt:choose>
206 </xslt:attribute>
207 <xsl:apply-templates/>
208 </a>
209 </xsl:otherwise>
210 </xsl:choose>
211 </xsl:template>
212
213 <xsl:template match="gsf:icon">
214 <xsl:choose>
215 <xsl:when test="@type='classifier'">
216 <img style="border:0px"><xsl:attribute name="src"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/></xsl:attribute></img>
217 </xsl:when>
218 <xsl:when test="@type='web'">
219 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
220 </xsl:when>
221 <xsl:when test="@file">
222 <img>
223 <xslt:attribute name='src'>
224 <xsl:choose>
225 <xsl:when test="not(@select) or @select='site'">
226 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
227 </xsl:when>
228 <xsl:when test="@select='collection'">
229 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
230 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
231 </xsl:when>
232 </xsl:choose>
233 </xslt:attribute>
234 </img>
235 </xsl:when>
236 <xsl:when test="not(@type) or @type='document'">
237 <img style="border:0px"><xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/></xslt:attribute><xslt:attribute name="src">
238 <xslt:choose>
239 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
240 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
241 </xslt:when>
242 <xslt:otherwise>
243 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
244 </xslt:otherwise>
245 </xslt:choose>
246 </xslt:attribute></img>
247 </xsl:when>
248 </xsl:choose>
249 </xsl:template>
250
251 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
252 <!--<xsl:template match="gsf:equivlinkgs3">
253 <xslt:call-template name="equivDocLinks">
254 <xslt:with-param name="count" select="0"/>
255 </xslt:call-template>
256 </xsl:template>-->
257
258 <!-- 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. -->
259 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
260 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
261 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
262 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
263
264 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
265 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
266 </xsl:template>
267
268<!--
269In the collection's format statement, could have the following javascript+XSLT in place of
270the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
271<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
272</xsl:text>
273<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
274<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
275</xsl:text>
276<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
277<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
278</xsl:text>
279<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
280<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;
281</xsl:text>
282-->
283
284 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
285 <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> -->
286 <xsl:template match="gsf:cgi-param">
287 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
288 </xsl:template>
289
290 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
291 a string defined in either collectionConfig.xml or else the interface dictionaries.
292 If the requested string occurs in neither, the request string itself will be output. -->
293 <xsl:template match="gsf:displayText">
294 <xslt:variable name="displaytext">
295 <xsl:call-template name="gsf:displayItem"/>
296 </xslt:variable>
297
298 <xslt:choose>
299 <xslt:when test="$displaytext != ''">
300 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
301 </xslt:when>
302 <xslt:otherwise>
303 <xslt:variable name="interfacetxt">
304 <xsl:call-template name="gsf:interfaceText"/>
305 </xslt:variable>
306
307 <xslt:choose>
308 <xslt:when test="$interfacetxt != ''">
309 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
310 </xslt:when>
311 <xslt:otherwise>
312 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
313 </xslt:otherwise>
314 </xslt:choose>
315 </xslt:otherwise>
316 </xslt:choose>
317 </xsl:template>
318
319 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
320 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
321 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
322 </xsl:template>
323
324 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
325 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
326 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
327 </xsl:template>
328 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
329 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
330 <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
331 <xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
332 </xsl:template>
333
334 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
335 <xsl:template match="gsf:metadata">
336 <xsl:if test="not(@hidden = 'true')">
337 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
338 <xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
339 <xsl:variable name="separator">
340 <xsl:choose>
341 <xsl:when test="@separator"><xsl:value-of disable-output-escaping='yes' select="@separator"/></xsl:when>
342 <xsl:when test="separator"><xsl:copy-of select="separator/node()"/></xsl:when>
343 <xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise>
344 </xsl:choose>
345 </xsl:variable>
346 <xsl:variable name="prefix">
347 <xsl:choose>
348 <xsl:when test="@prefix"><xsl:value-of disable-output-escaping='yes' select="@prefix"/></xsl:when>
349 <xsl:when test="prefix"><xsl:copy-of select="prefix/node()"/></xsl:when>
350 </xsl:choose>
351 </xsl:variable>
352 <xsl:variable name="suffix">
353 <xsl:choose>
354 <xsl:when test="@suffix"><xsl:value-of disable-output-escaping='yes' select="@suffix"/></xsl:when>
355 <xsl:when test="suffix"><xsl:copy-of select="suffix/node()"/></xsl:when>
356 </xsl:choose>
357 </xsl:variable>
358 <xsl:variable name="postest">
359 <xsl:choose>
360 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
361 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
362 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/></xsl:when>
363 <xsl:otherwise>true()</xsl:otherwise>
364 </xsl:choose>
365 </xsl:variable>
366 <xsl:variable name="multiple">
367 <xsl:choose>
368 <xsl:when test="@pos">false()</xsl:when>
369 <xsl:otherwise>true()</xsl:otherwise>
370 </xsl:choose>
371 </xsl:variable>
372 <xslt:for-each>
373 <xsl:attribute name="select">
374 <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>
375 </xsl:attribute>
376 <xslt:if test="{$postest}">
377 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/></xslt:if>
378 <xsl:copy-of select="$prefix"/>
379 <xsl:choose>
380 <xsl:when test="@format">
381 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
382 </xsl:when>
383 <xsl:otherwise>
384 <xslt:value-of disable-output-escaping='yes' select="."/>
385 </xsl:otherwise>
386 </xsl:choose>
387 </xslt:if>
388 <xsl:copy-of select="$suffix"/>
389 </xslt:for-each>
390 </xsl:if>
391 </xsl:template>
392
393 <xsl:template name="getMetadataName">
394 <xsl:if test='@select'>
395 <xsl:value-of select='@select'/>
396 <xsl:text>_</xsl:text>
397 </xsl:if>
398 <xsl:value-of select="@name"/>
399 </xsl:template>
400
401 <xsl:template match="gsf:text">
402 <xslt:call-template name="documentNodeText"/>
403 </xsl:template>
404
405 <xsl:template match="gsf:if-metadata-exists">
406 <xsl:variable name="meta-path"><xsl:for-each select="gsf:metadata">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:for-each></xsl:variable>
407 <xslt:choose>
408 <xslt:when test="{$meta-path}">
409 <xsl:apply-templates select="gsf:if/node()"/>
410 </xslt:when>
411 <xsl:if test="gsf:else">
412 <xslt:otherwise><xsl:apply-templates select="gsf:else/node()"/>
413 </xslt:otherwise>
414 </xsl:if>
415 </xslt:choose>
416 </xsl:template>
417
418 <xsl:template match="gsf:choose-metadata">
419 <xslt:choose>
420 <xsl:for-each select="gsf:metadata">
421 <xslt:when>
422 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
423 <xsl:apply-templates select="."/>
424 </xslt:when>
425 </xsl:for-each>
426 <xsl:if test="gsf:default">
427 <xslt:otherwise><xsl:apply-templates select="gsf:default"/></xslt:otherwise>
428 </xsl:if>
429 </xslt:choose>
430 </xsl:template>
431
432 <xsl:template match="gsf:switch">
433 <xsl:variable name="meta-name"><xsl:for-each select="gsf:metadata"><xsl:call-template name="getMetadataName"/></xsl:for-each></xsl:variable>
434 <xslt:variable name="meta"><xsl:choose><xsl:when test="@preprocess"><xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/></xsl:when><xsl:otherwise><xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/></xsl:otherwise></xsl:choose></xslt:variable>
435 <xslt:choose>
436 <xsl:for-each select="gsf:when">
437 <xslt:when test="util:{@test}($meta, '{@test-value}')">
438 <xsl:apply-templates/>
439 </xslt:when>
440 </xsl:for-each>
441 <xsl:if test="gsf:otherwise">
442 <xslt:otherwise>
443 <xsl:apply-templates select="gsf:otherwise/node()"/>
444 </xslt:otherwise>
445 </xsl:if>
446 </xslt:choose>
447 </xsl:template>
448
449 <xsl:template match="*">
450 <xsl:copy>
451 <xsl:copy-of select="@*"/>
452 <xsl:apply-templates/>
453 </xsl:copy>
454 </xsl:template>
455
456</xsl:stylesheet>
457
458
Note: See TracBrowser for help on using the repository browser.