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

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

A major rework of document templates so that the display templates are easier to modify

File size: 11.9 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 <xsl: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 </xsl:variable>
55 <xsl: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 <xsl:choose>
63 <xsl:when test="@type = 'thumb'">
64 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name = 'Thumb']"/>
65 </xsl:when>
66 <xsl:when test="@type = 'screen'">
67 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name = 'Screen']"/>
68 </xsl:when>
69 <xsl:when test="@type = 'source'">
70 <xslt:value-of disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name = 'SourceFile']"/>
71 </xsl:when>
72 </xsl:choose>
73 </xslt:attribute>
74 </img>
75 </xsl:if>
76 </xsl:template>
77
78 <xsl:template match="gsf:link">
79 <xsl:choose>
80 <xsl:when test="@type='classifier'">
81 <a>
82 <xslt:attribute name='href'>
83 <xslt:value-of select='$library_name'/>
84 <xsl:text>/collection/</xsl:text>
85 <xslt:value-of select='/page/pageResponse/collection/@name'/>
86 <xsl:text>/browse/</xsl:text>
87 <xslt:value-of select='util:replace(@nodeID, ".", "/")'/>
88 </xslt:attribute>
89 <xsl:apply-templates/>
90 </a>
91 </xsl:when>
92 <xsl:when test="@type='source'">
93 <a><xslt:attribute name='href'><xslt:value-of
94 disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of
95 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='assocfilepath']" />/<xslt:value-of
96 disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='srclinkFile']" /></xslt:attribute>
97 <xsl:apply-templates/>
98 </a>
99 </xsl:when>
100 <xsl:otherwise> <!-- a document link -->
101 <xslt:variable name="bookswitch">
102 <xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
103 </xslt:variable>
104 <a>
105 <xslt:attribute name="href">
106 <xslt:value-of select='$library_name'/>
107 <xsl:text>/collection/</xsl:text>
108 <xslt:value-of select='/page/pageResponse/collection/@name'/>
109 <xsl:text>/document/</xsl:text>
110 <xslt:value-of select='@nodeID'/>
111 <xslt:choose>
112 <xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
113 <xsl:text>?book=on</xsl:text>
114 </xslt:when>
115 <xslt:otherwise>
116 <xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/></xslt:if>
117 </xslt:otherwise>
118 </xslt:choose>
119 </xslt:attribute>
120 <xsl:apply-templates/>
121 </a>
122 </xsl:otherwise>
123 </xsl:choose>
124 </xsl:template>
125
126 <xsl:template match="gsf:icon">
127 <xsl:choose>
128 <xsl:when test="@type='classifier'">
129 <img style="border:0px"><xsl:attribute name="src"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/></xsl:attribute></img>
130 </xsl:when>
131 <xsl:when test="not(@type) or @type='document'">
132 <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>
133 </xsl:when>
134 </xsl:choose>
135 </xsl:template>
136
137 <!-- gsf:cgiparam example, as used by the Enhanced PDF tutorial:
138 <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> -->
139 <xsl:template match="gsf:cgi-param">
140 <xslt:value-of disable-output-escaping="yes" select="/page/pageRequest/paramList/param[@name='s1.{@name}']/@value"/>
141 </xsl:template>
142
143 <!-- A GLI user can use a gsf:displayText element in GS3's Format Features to retrieve
144 a string defined in either collectionConfig.xml or else the interface dictionaries.
145 If the requested string occurs in neither, the request string itself will be output. -->
146 <xsl:template match="gsf:displayText">
147 <xslt:variable name="displaytext">
148 <xsl:call-template name="gsf:displayItem"/>
149 </xslt:variable>
150
151 <xslt:choose>
152 <xslt:when test="$displaytext != ''">
153 <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>
154 </xslt:when>
155 <xslt:otherwise>
156 <xslt:variable name="interfacetxt">
157 <xsl:call-template name="gsf:interfaceText"/>
158 </xslt:variable>
159
160 <xslt:choose>
161 <xslt:when test="$interfacetxt != ''">
162 <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
163 </xslt:when>
164 <xslt:otherwise>
165 <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
166 </xslt:otherwise>
167 </xslt:choose>
168 </xslt:otherwise>
169 </xslt:choose>
170 </xsl:template>
171
172 <!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
173 <xsl:template match="gsf:displayItem" name="gsf:displayItem">
174 <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
175 </xsl:template>
176
177 <!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
178 <xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
179 <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
180 </xsl:template>
181
182 <!-- if this gsf:metadata is a child of a document node then we want to get the metadata for that node -->
183 <xsl:template match="gsf:metadata">
184 <xslt:variable name="langAtt"><xsl:value-of select="@lang"/></xslt:variable>
185 <xslt:if test="not(@hidden = 'true')">
186 <xslt:value-of disable-output-escaping="yes">
187 <xsl:attribute name="select">
188 <xsl:if test="@format">
189 <xsl:text>java:org.greenstone.gsdl3.util.XSLTUtil.</xsl:text>
190 <xsl:value-of select="@format"/>
191 <xsl:text>(</xsl:text>
192 </xsl:if>
193 <xsl:choose>
194 <xsl:when test="@type = 'collection'">
195 <xsl:text>/page/pageResponse/collection/metadataList/metadata[@name='</xsl:text>
196 </xsl:when>
197 <xsl:otherwise>
198 <xsl:text>(.//metadataList)[last()]/metadata[@name='</xsl:text>
199 </xsl:otherwise>
200 </xsl:choose>
201 <xsl:apply-templates select="." mode="get-metadata-name"/>
202 <xsl:text>'</xsl:text>
203 <xsl:if test="@lang">
204 <xsl:text> and @lang=$langAtt</xsl:text>
205 </xsl:if>
206 <xsl:text>]</xsl:text>
207 <xsl:if test="@format">
208 <xsl:text>, /page/@lang )</xsl:text>
209 </xsl:if>
210 </xsl:attribute>
211 </xslt:value-of>
212 </xslt:if>
213 </xsl:template>
214
215 <xsl:template match="gsf:metadata" mode="get-metadata-name">
216 <xsl:if test="@pos">
217 <xsl:text>pos</xsl:text>
218 <xsl:value-of select='@pos'/>
219 <xsl:text>_</xsl:text>
220 </xsl:if>
221 <xsl:if test='@select'>
222 <xsl:value-of select='@select'/>
223 <xsl:text>_</xsl:text>
224 </xsl:if>
225 <xsl:if test="@separator">
226 <xsl:text>*</xsl:text>
227 <xsl:value-of select='@separator'/>
228 <xsl:text>*_</xsl:text>
229 </xsl:if>
230 <xsl:value-of select="@name"/>
231 </xsl:template>
232
233 <xsl:template match="gsf:metadata-old" mode="get-metadata-name">
234 <xsl:if test="@multiple='true'">
235 <xsl:text>all_</xsl:text>
236 </xsl:if>
237 <xsl:if test='@select'>
238 <xsl:value-of select='@select'/>
239 <xsl:text>_</xsl:text>
240 </xsl:if>
241 <xsl:if test="@separator">
242 <xsl:text>*</xsl:text>
243 <xsl:value-of select='@separator'/>
244 <xsl:text>*_</xsl:text>
245 </xsl:if>
246 <xsl:value-of select="@name"/>
247 </xsl:template>
248
249 <xsl:template match="gsf:metadata-older">
250 <xslt:value-of disable-output-escaping="yes">
251 <xsl:attribute name="select">
252 <xsl:text>(.//metadataList)[last()]/metadata[@name="</xsl:text>
253 <xsl:choose>
254 <xsl:when test="@select='parent'">
255 <xsl:text>parent_</xsl:text>
256 </xsl:when>
257 <xsl:when test="@select='root'">
258 <xsl:text>root_</xsl:text>
259 </xsl:when>
260 <xsl:when test="@select='ancestors'">
261 <xsl:text>ancestors'</xsl:text>
262 <xsl:value-of select='@separator'/>
263 <xsl:text>'_</xsl:text>
264 </xsl:when>
265 <xsl:when test="@select='siblings'">
266 <xsl:text>siblings_'</xsl:text>
267 <xsl:value-of select='@separator'/>
268 <xsl:text>'_</xsl:text>
269 </xsl:when>
270 </xsl:choose>
271 <xsl:value-of select="@name"/>
272 <xsl:text>"]</xsl:text>
273 </xsl:attribute>
274 </xslt:value-of>
275 </xsl:template>
276
277 <xsl:template match="gsf:text">
278 <xslt:call-template name="documentNodeText"/>
279 </xsl:template>
280
281 <xsl:template match="gsf:choose-metadata">
282 <xslt:choose>
283 <xsl:for-each select="gsf:metadata">
284 <xslt:when>
285 <xsl:attribute name="test">(.//metadataList)[last()]/metadata[@name='<xsl:apply-templates select="." mode="get-metadata-name"/>']</xsl:attribute>
286 <xsl:apply-templates select="."/>
287 </xslt:when>
288 </xsl:for-each>
289 <xsl:if test="gsf:default">
290 <xslt:otherwise><xsl:apply-templates select="gsf:default"/></xslt:otherwise>
291 </xsl:if>
292 </xslt:choose>
293 </xsl:template>
294
295 <xsl:template match="gsf:switch">
296 <xsl:variable name="meta-name"><xsl:apply-templates select="gsf:metadata" mode="get-metadata-name"/></xsl:variable>
297 <xslt:variable name="meta"><xsl:choose><xsl:when test="@preprocess"><xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'])"/></xsl:when><xsl:otherwise><xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/></xsl:otherwise></xsl:choose></xslt:variable>
298 <xslt:choose>
299 <xsl:for-each select="gsf:when">
300 <xslt:when test="util:{@test}($meta, '{@test-value}')">
301 <xsl:apply-templates/>
302 </xslt:when>
303 </xsl:for-each>
304 <xsl:if test="gsf:otherwise">
305 <xslt:otherwise>
306 <xsl:apply-templates select="gsf:otherwise/node()"/>
307 </xslt:otherwise>
308 </xsl:if>
309 </xslt:choose>
310 </xsl:template>
311
312 <xsl:template match="*">
313 <xsl:copy>
314 <xsl:copy-of select="@*"/>
315 <xsl:apply-templates/>
316 </xsl:copy>
317 </xsl:template>
318
319</xsl:stylesheet>
320
321
Note: See TracBrowser for help on using the repository browser.