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

Last change on this file since 26336 was 26336, checked in by sjm84, 12 years ago

Readded the args argument that was accidentally deleted. Also making the language a parameter to the text_fragment_format.xsl

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