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

Last change on this file since 26092 was 26092, checked in by kjdon, 12 years ago

working on handling separator, position etc in the xslt not in java

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