root/main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl @ 26317

Revision 26317, 16.2 KB (checked in by kjdon, 8 years ago)

more modes to get niupepa collection working

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