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

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

added gsf:collectionText template

File size: 15.5 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 <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>
109 <xslt:value-of select='@nodeID'/></xsl:otherwise></xsl:choose>
110 <xslt:choose>
111 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
112 <xsl:text>?book=on</xsl:text>
113 </xslt:when>
114 <xslt:otherwise>
115 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/></xslt:if>
116 </xslt:otherwise>
117 </xslt:choose>
118 </xslt:attribute>
119 <xsl:apply-templates/>
120 </a>
121 </xsl:otherwise>
122 </xsl:choose>
123 </xsl:template>
124
125 <xsl:template match="gsf:icon">
126 <xsl:choose>
127 <xsl:when test="@type='classifier'">
128 <img style="border:0px"><xsl:attribute name="src"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/></xsl:attribute></img>
129 </xsl:when>
130 <xsl:when test="@type='web'">
131 <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>
132 </xsl:when>
133 <xsl:when test="@file">
134 <img>
135 <xslt:attribute name='src'>
136 <xsl:choose>
137 <xsl:when test="not(@select) or @select='site'">
138 <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
139 </xsl:when>
140 <xsl:when test="@select='collection'">
141 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
142 <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
143 </xsl:when>
144 </xsl:choose>
145 </xslt:attribute>
146 </img>
147 </xsl:when>
148 <xsl:when test="not(@type) or @type='document'">
149 <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">
150 <xslt:choose>
151 <xslt:when test="@docType='hierarchy' and @nodeType='root'">
152 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
153 </xslt:when>
154 <xslt:otherwise>
155 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
156 </xslt:otherwise>
157 </xslt:choose>
158 </xslt:attribute></img>
159 </xsl:when>
160 </xsl:choose>
161 </xsl:template>
162
163 <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
164 <!--<xsl:template match="gsf:equivlinkgs3">
165 <xslt:call-template name="equivDocLinks">
166 <xslt:with-param name="count" select="0"/>
167 </xslt:call-template>
168 </xsl:template>-->
169
170 <!-- 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. -->
171 <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
172 <xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>
173 <xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>
174 <xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
175
176 <xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
177 <xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
178 </xsl:template>
179
180<!--
181In the collection's format statement, could have the following javascript+XSLT in place of
182the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
183<xsl:text disable-output-escaping="yes">&lt;script&gt;var equivDocIcon= [ &quot;
184</xsl:text>
185<gsf:metadata name="equivDocIcon" separator="&quot;, &quot;" multiple="true"/>
186<xsl:text disable-output-escaping="yes">&quot;];var equivDocStartLink= [ &quot;
187</xsl:text>
188<gsf:metadata name="equivDocLink" separator="&quot;,&quot;" multiple="true"/>
189<xsl:text disable-output-escaping="yes">&quot;];var equivDocEndLink= [ &quot;
190</xsl:text>
191<gsf:metadata name="/equivDocLink" separator="&quot;,&quot;" multiple="true"/>
192<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;
193</xsl:text>
194-->
195
196 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
197 <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> -->
198 <xsl:template match="gsf:cgi-param">
199 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
200 </xsl:template>
201
202 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
203 a string defined in either collectionConfig.xml or else the interface dictionaries.
204 If the requested string occurs in neither, the request string itself will be output. -->
205 <xsl:template match="gsf:displayText">
206 <xslt:variable name="displaytext">
207 <xsl:call-template name="gsf:displayItem"/>
208 </xslt:variable>
209
210 <xslt:choose>
211 <xslt:when test="$displaytext != ''">
212 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
213 </xslt:when>
214 <xslt:otherwise>
215 <xslt:variable name="interfacetxt">
216 <xsl:call-template name="gsf:interfaceText"/>
217 </xslt:variable>
218
219 <xslt:choose>
220 <xslt:when test="$interfacetxt != ''">
221 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
222 </xslt:when>
223 <xslt:otherwise>
224 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
225 </xslt:otherwise>
226 </xslt:choose>
227 </xslt:otherwise>
228 </xslt:choose>
229 </xsl:template>
230
231 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
232 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
233 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
234 </xsl:template>
235
236 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
237 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
238 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
239 </xsl:template>
240 <!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
241 <xsl:template match="gsf:collectionText" name="gsf:collectionText">
242 <!--<xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>-->
243 <xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}')"/>
244 </xsl:template>
245
246 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
247 <xsl:template match="gsf:metadata">
248 <xsl:if test="not(@hidden = 'true')">
249 <!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
250 <xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
251 <xsl:variable name="separator">
252 <xsl:choose>
253 <xsl:when test="@separator"><xsl:value-of disable-output-escaping='yes' select="@separator"/></xsl:when>
254 <xsl:when test="separator"><xsl:copy-of select="separator/node()"/></xsl:when>
255 <xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise>
256 </xsl:choose>
257 </xsl:variable>
258 <xsl:variable name="prefix">
259 <xsl:choose>
260 <xsl:when test="@prefix"><xsl:value-of disable-output-escaping='yes' select="@prefix"/></xsl:when>
261 <xsl:when test="prefix"><xsl:copy-of select="prefix/node()"/></xsl:when>
262 </xsl:choose>
263 </xsl:variable>
264 <xsl:variable name="suffix">
265 <xsl:choose>
266 <xsl:when test="@suffix"><xsl:value-of disable-output-escaping='yes' select="@suffix"/></xsl:when>
267 <xsl:when test="suffix"><xsl:copy-of select="suffix/node()"/></xsl:when>
268 </xsl:choose>
269 </xsl:variable>
270 <xsl:variable name="postest">
271 <xsl:choose>
272 <xsl:when test="@pos = 'first'">position()=1</xsl:when>
273 <xsl:when test="@pos = 'last'">position() = last()</xsl:when>
274 <xsl:when test="@pos">position() = <xsl:value-of select="@pos"/></xsl:when>
275 <xsl:otherwise>true()</xsl:otherwise>
276 </xsl:choose>
277 </xsl:variable>
278 <xsl:variable name="multiple">
279 <xsl:choose>
280 <xsl:when test="@pos">false()</xsl:when>
281 <xsl:otherwise>true()</xsl:otherwise>
282 </xsl:choose>
283 </xsl:variable>
284 <xslt:for-each>
285 <xsl:attribute name="select">
286 <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>
287 </xsl:attribute>
288 <xslt:if test="{$postest}">
289 <xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/></xslt:if>
290 <xsl:copy-of select="$prefix"/>
291 <xsl:choose>
292 <xsl:when test="@format">
293 <xslt:value-of disable-output-escaping='yes' select="util:{@format}(., /page/@lang )"/>
294 </xsl:when>
295 <xsl:otherwise>
296 <xslt:value-of disable-output-escaping='yes' select="."/>
297 </xsl:otherwise>
298 </xsl:choose>
299 </xslt:if>
300 <xsl:copy-of select="$suffix"/>
301 </xslt:for-each>
302 </xsl:if>
303 </xsl:template>
304
305 <xsl:template name="getMetadataName">
306 <xsl:if test='@select'>
307 <xsl:value-of select='@select'/>
308 <xsl:text>_</xsl:text>
309 </xsl:if>
310 <xsl:value-of select="@name"/>
311 </xsl:template>
312
313 <xsl:template match="gsf:text">
314 <xslt:call-template name="documentNodeText"/>
315 </xsl:template>
316
317 <xsl:template match="gsf:choose-metadata">
318 <xslt:choose>
319 <xsl:for-each select="gsf:metadata">
320 <xslt:when>
321 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:attribute>
322 <xsl:apply-templates select="."/>
323 </xslt:when>
324 </xsl:for-each>
325 <xsl:if test="gsf:default">
326 <xslt:otherwise><xsl:apply-templates select="gsf:default"/></xslt:otherwise>
327 </xsl:if>
328 </xslt:choose>
329 </xsl:template>
330
331 <xsl:template match="gsf:switch">
332 <xsl:variable name="meta-name"><xsl:for-each select="gsf:metadata"><xsl:call-template name="getMetadataName"/></xsl:for-each></xsl:variable>
333 <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>
334 <xslt:choose>
335 <xsl:for-each select="gsf:when">
336 <xslt:when test="util:{@test}($meta, '{@test-value}')">
337 <xsl:apply-templates/>
338 </xslt:when>
339 </xsl:for-each>
340 <xsl:if test="gsf:otherwise">
341 <xslt:otherwise>
342 <xsl:apply-templates select="gsf:otherwise/node()"/>
343 </xslt:otherwise>
344 </xsl:if>
345 </xslt:choose>
346 </xsl:template>
347
348 <xsl:template match="*">
349 <xsl:copy>
350 <xsl:copy-of select="@*"/>
351 <xsl:apply-templates/>
352 </xsl:copy>
353 </xsl:template>
354
355</xsl:stylesheet>
356
357
Note: See TracBrowser for help on using the repository browser.