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

Last change on this file since 26127 was 26127, checked in by ak19, 9 years ago

A custom icon can be selected from collection or site level.

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