Bug 21887: (For OPAC) 856 link problem in XSLT result lists and detail page
[srvgit] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / UNIMARCslim2OPACResults.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE stylesheet [<!ENTITY nbsp "&#160;" >]>
4
5 <xsl:stylesheet version="1.0"
6   xmlns:marc="http://www.loc.gov/MARC21/slim"
7   xmlns:items="http://www.koha-community.org/items"
8   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9   xmlns:str="http://exslt.org/strings"
10   exclude-result-prefixes="marc items str">
11
12 <xsl:import href="UNIMARCslimUtils.xsl"/>
13 <xsl:output method = "html" indent="yes" omit-xml-declaration = "yes" encoding="UTF-8"/>
14 <xsl:key name="item-by-status" match="items:item" use="items:status"/>
15 <xsl:key name="item-by-status-and-branch-home" match="items:item" use="concat(items:status, ' ', items:homebranch)"/>
16 <xsl:key name="item-by-status-and-branch-holding" match="items:item" use="concat(items:status, ' ', items:holdingbranch)"/>
17
18 <xsl:template match="/">
19   <xsl:apply-templates/>
20 </xsl:template>
21
22 <xsl:template match="marc:record">
23   <xsl:variable name="leader" select="marc:leader"/>
24   <xsl:variable name="leader6" select="substring($leader,7,1)"/>
25   <xsl:variable name="leader7" select="substring($leader,8,1)"/>
26   <xsl:variable name="biblionumber"
27    select="marc:datafield[@tag=090]/marc:subfield[@code='a']"/>
28   <xsl:variable name="isbn"
29    select="marc:datafield[@tag=010]/marc:subfield[@code='a']"/>
30   <xsl:variable name="OPACResultsLibrary" select="marc:sysprefs/marc:syspref[@name='OPACResultsLibrary']"/>
31   <xsl:variable name="BiblioDefaultView" select="marc:sysprefs/marc:syspref[@name='BiblioDefaultView']"/>
32   <xsl:variable name="hidelostitems" select="marc:sysprefs/marc:syspref[@name='hidelostitems']"/>
33   <xsl:variable name="singleBranchMode" select="marc:sysprefs/marc:syspref[@name='singleBranchMode']"/>
34   <xsl:variable name="OPACURLOpenInNewWindow" select="marc:sysprefs/marc:syspref[@name='OPACURLOpenInNewWindow']"/>
35
36   <xsl:if test="marc:datafield[@tag=200]">
37     <xsl:for-each select="marc:datafield[@tag=200]">
38         <xsl:call-template name="addClassRtl" />
39         <xsl:for-each select="marc:subfield">
40           <xsl:choose>
41             <xsl:when test="@code='a'">
42               <xsl:variable name="title" select="."/>
43               <xsl:variable name="ntitle"
44                 select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
45               <a>
46                 <xsl:attribute name="href">
47                   <xsl:call-template name="buildBiblioDefaultViewURL">
48                       <xsl:with-param name="BiblioDefaultView">
49                           <xsl:value-of select="$BiblioDefaultView"/>
50                       </xsl:with-param>
51                   </xsl:call-template>
52                   <xsl:value-of select="str:encode-uri($biblionumber, true())"/>
53                 </xsl:attribute>
54                 <xsl:attribute name="class">title</xsl:attribute>
55                 <xsl:value-of select="$ntitle" />
56               </a>
57             </xsl:when>
58             <xsl:when test="@code='b'">
59               <xsl:text> [</xsl:text>
60               <xsl:value-of select="."/>
61               <xsl:text>]</xsl:text>
62             </xsl:when>
63             <xsl:when test="@code='d'">
64               <xsl:text> = </xsl:text>
65               <xsl:value-of select="."/>
66             </xsl:when>
67             <xsl:when test="@code='e'">
68               <xsl:text> : </xsl:text>
69               <xsl:value-of select="."/>
70             </xsl:when>
71             <xsl:when test="@code='f'">
72               <xsl:text> / </xsl:text>
73               <xsl:value-of select="."/>
74             </xsl:when>
75             <xsl:when test="@code='g'">
76               <xsl:text> ; </xsl:text>
77               <xsl:value-of select="."/>
78             </xsl:when>
79             <xsl:otherwise>
80               <xsl:text>, </xsl:text>
81               <xsl:value-of select="."/>
82             </xsl:otherwise>
83           </xsl:choose>
84         </xsl:for-each>
85     </xsl:for-each>
86   </xsl:if>
87
88   <!-- OpenURL -->
89   <xsl:variable name="OPACShowOpenURL" select="marc:sysprefs/marc:syspref[@name='OPACShowOpenURL']" />
90   <xsl:variable name="OpenURLImageLocation" select="marc:sysprefs/marc:syspref[@name='OpenURLImageLocation']" />
91   <xsl:variable name="OpenURLText" select="marc:sysprefs/marc:syspref[@name='OpenURLText']" />
92   <xsl:variable name="OpenURLResolverURL" select="marc:variables/marc:variable[@name='OpenURLResolverURL']" />
93
94   <xsl:if test="$OPACShowOpenURL = 1 and $OpenURLResolverURL != ''">
95     <xsl:variable name="openurltext">
96       <xsl:choose>
97         <xsl:when test="$OpenURLText != ''">
98           <xsl:value-of select="$OpenURLText" />
99         </xsl:when>
100         <xsl:otherwise>
101           <xsl:text>OpenURL</xsl:text>
102         </xsl:otherwise>
103       </xsl:choose>
104     </xsl:variable>
105
106     <span class="results_summary"><a>
107       <xsl:attribute name="href">
108         <xsl:value-of select="$OpenURLResolverURL" />
109       </xsl:attribute>
110       <xsl:attribute name="title">
111         <xsl:value-of select="$openurltext" />
112       </xsl:attribute>
113       <xsl:attribute name="class">
114         <xsl:text>OpenURL</xsl:text>
115       </xsl:attribute>
116       <xsl:if test="$OPACURLOpenInNewWindow='1'">
117         <xsl:attribute name="target">
118           <xsl:text>_blank</xsl:text>
119         </xsl:attribute>
120       </xsl:if>
121       <xsl:choose>
122         <xsl:when test="$OpenURLImageLocation != ''">
123           <img>
124             <xsl:attribute name="src">
125               <xsl:value-of select="$OpenURLImageLocation" />
126             </xsl:attribute>
127           </img>
128         </xsl:when>
129         <xsl:otherwise>
130           <xsl:value-of select="$openurltext" />
131         </xsl:otherwise>
132       </xsl:choose>
133     </a></span>
134   </xsl:if>
135   <!-- End of OpenURL -->
136
137   <xsl:call-template name="tag_title">
138     <xsl:with-param name="tag">454</xsl:with-param>
139     <xsl:with-param name="label">Translation of</xsl:with-param>
140     <xsl:with-param name="spanclass">original_title</xsl:with-param>
141   </xsl:call-template>
142
143   <xsl:call-template name="tag_title">
144     <xsl:with-param name="tag">461</xsl:with-param>
145     <xsl:with-param name="label">Set Level</xsl:with-param>
146     <xsl:with-param name="spanclass">set_level</xsl:with-param>
147   </xsl:call-template>
148
149   <xsl:call-template name="tag_title">
150     <xsl:with-param name="tag">464</xsl:with-param>
151     <xsl:with-param name="label">Piece-Analytic Level</xsl:with-param>
152     <xsl:with-param name="spanclass">piece_analytic_level</xsl:with-param>
153   </xsl:call-template>
154
155   <xsl:call-template name="tag_210" />
156
157   <xsl:call-template name="tag_215" />
158
159   <span class="results_summary availability">
160     <span class="label">Availability: </span>
161     <xsl:choose>
162       <xsl:when test="marc:datafield[@tag=856]">
163         <xsl:for-each select="marc:datafield[@tag=856]">
164           <xsl:choose>
165             <xsl:when test="@ind2=0">
166               <a>
167                 <xsl:attribute name="href">
168                   <xsl:value-of select="marc:subfield[@code='u']"/>
169                 </xsl:attribute>
170                 <xsl:if test="$OPACURLOpenInNewWindow='1'">
171                     <xsl:attribute name="target">_blank</xsl:attribute>
172                 </xsl:if>
173                 <xsl:choose>
174                   <xsl:when test="marc:subfield[@code='y' or @code='3' or @code='z']">
175                     <xsl:call-template name="subfieldSelect">
176                       <xsl:with-param name="codes">y3z</xsl:with-param>
177                     </xsl:call-template>
178                   </xsl:when>
179                   <xsl:when test="not(marc:subfield[@code='y']) and not(marc:subfield[@code='3']) and not(marc:subfield[@code='z'])">
180                     Click here to access online
181                   </xsl:when>
182                 </xsl:choose>
183               </a>
184               <xsl:choose>
185                 <xsl:when test="position()=last()"></xsl:when>
186                 <xsl:otherwise> | </xsl:otherwise>
187               </xsl:choose>
188             </xsl:when>
189           </xsl:choose>
190         </xsl:for-each>
191       </xsl:when>
192       <xsl:when test="count(key('item-by-status', 'available'))=0 and count(key('item-by-status', 'reference'))=0">
193         No items available
194       </xsl:when>
195       <xsl:when test="count(key('item-by-status', 'available'))>0">
196         <span class="available">
197           <b><xsl:text>Items available for loan: </xsl:text></b>
198           <xsl:variable name="available_items" select="key('item-by-status', 'available')"/>
199       <xsl:choose>
200       <xsl:when test="$singleBranchMode=1">
201       <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
202         <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
203           <xsl:text> (</xsl:text>
204           <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
205           <xsl:text>)</xsl:text>
206           <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
207       </xsl:for-each>
208       </xsl:when>
209       <xsl:otherwise>
210           <xsl:choose>
211               <xsl:when test="$OPACResultsLibrary='homebranch'">
212                   <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
213                     <xsl:value-of select="items:homebranch"/>
214                         <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]
215                         </xsl:if>
216                     <xsl:text> (</xsl:text>
217                     <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
218                     <xsl:text>)</xsl:text>
219                     <xsl:choose>
220                       <xsl:when test="position()=last()">
221                         <xsl:text>. </xsl:text>
222                       </xsl:when>
223                       <xsl:otherwise>
224                         <xsl:text>, </xsl:text>
225                       </xsl:otherwise>
226                     </xsl:choose>
227                   </xsl:for-each>
228               </xsl:when>
229               <xsl:otherwise>
230                   <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch))[1])]">
231                     <xsl:value-of select="items:holdingbranch"/>
232                         <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]
233                         </xsl:if>
234                     <xsl:text> (</xsl:text>
235                     <xsl:value-of select="count(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch)))"/>
236                     <xsl:text>)</xsl:text>
237                     <xsl:choose>
238                       <xsl:when test="position()=last()">
239                         <xsl:text>. </xsl:text>
240                       </xsl:when>
241                       <xsl:otherwise>
242                         <xsl:text>, </xsl:text>
243                       </xsl:otherwise>
244                     </xsl:choose>
245                   </xsl:for-each>
246               </xsl:otherwise>
247             </xsl:choose>
248       </xsl:otherwise>
249       </xsl:choose>
250         </span>
251       </xsl:when>
252     </xsl:choose>
253     <xsl:choose>
254       <xsl:when test="count(key('item-by-status', 'reference'))>0">
255         <span class="available">
256           <b><xsl:text>Items available for reference: </xsl:text></b>
257           <xsl:variable name="reference_items"
258                         select="key('item-by-status', 'reference')"/>
259           <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
260             <xsl:if test="$singleBranchMode=0">
261                 <xsl:value-of select="items:homebranch"/>
262             </xsl:if>
263             <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
264             <xsl:text> (</xsl:text>
265             <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
266             <xsl:text>)</xsl:text>
267             <xsl:choose>
268               <xsl:when test="position()=last()">
269                 <xsl:text>. </xsl:text>
270               </xsl:when>
271               <xsl:otherwise>
272                 <xsl:text>, </xsl:text>
273               </xsl:otherwise>
274             </xsl:choose>
275           </xsl:for-each>
276         </span>
277       </xsl:when>
278     </xsl:choose>
279     <xsl:if test="count(key('item-by-status', 'Checked out'))>0">
280       <span class="unavailable">
281         <xsl:text>Checked out (</xsl:text>
282         <xsl:value-of select="count(key('item-by-status', 'Checked out'))"/>
283         <xsl:text>). </xsl:text>
284       </span>
285     </xsl:if>
286     <xsl:if test="count(key('item-by-status', 'Withdrawn'))>0">
287       <span class="unavailable">
288         <xsl:text>Withdrawn (</xsl:text>
289         <xsl:value-of select="count(key('item-by-status', 'Withdrawn'))"/>
290         <xsl:text>). </xsl:text>
291       </span>
292     </xsl:if>
293     <xsl:if test="$hidelostitems='0' and count(key('item-by-status', 'Lost'))>0">
294       <span class="unavailable">
295         <xsl:text>Lost (</xsl:text>
296         <xsl:value-of select="count(key('item-by-status', 'Lost'))"/>
297         <xsl:text>). </xsl:text>
298       </span>
299     </xsl:if>
300     <xsl:if test="count(key('item-by-status', 'Damaged'))>0">
301       <span class="unavailable">
302         <xsl:text>Damaged (</xsl:text>
303         <xsl:value-of select="count(key('item-by-status', 'Damaged'))"/>
304         <xsl:text>). </xsl:text>
305       </span>
306     </xsl:if>
307     <xsl:if test="count(key('item-by-status', 'On order'))>0">
308       <span class="unavailable">
309         <xsl:text>On order (</xsl:text>
310         <xsl:value-of select="count(key('item-by-status', 'On order'))"/>
311         <xsl:text>). </xsl:text>
312       </span>
313     </xsl:if>
314     <xsl:if test="count(key('item-by-status', 'In transit'))>0">
315       <span class="unavailable">
316         <xsl:text>In transit (</xsl:text>
317         <xsl:value-of select="count(key('item-by-status', 'In transit'))"/>
318         <xsl:text>). </xsl:text>
319       </span>
320     </xsl:if>
321     <xsl:if test="count(key('item-by-status', 'Waiting'))>0">
322       <span class="unavailable">
323         <xsl:text>On hold (</xsl:text>
324         <xsl:value-of select="count(key('item-by-status', 'Waiting'))"/>
325         <xsl:text>). </xsl:text>
326       </span>
327     </xsl:if>
328   </span>
329
330 </xsl:template>
331
332 </xsl:stylesheet>