Bug 5738 Display 856u As Image
[wip/koha-chris_n.git] / koha-tmpl / opac-tmpl / prog / 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   exclude-result-prefixes="marc items">
10
11 <xsl:import href="UNIMARCslimUtils.xsl"/>
12 <xsl:output method = "xml" indent="yes" omit-xml-declaration = "yes" />
13 <xsl:key name="item-by-status" match="items:item" use="items:status"/>
14 <xsl:key name="item-by-status-and-branch" match="items:item" use="concat(items:status, ' ', items:homebranch)"/>
15
16 <xsl:template match="/">
17   <xsl:apply-templates/>
18 </xsl:template>
19
20 <xsl:template match="marc:record">
21   <xsl:variable name="Show856uAsImage" select="marc:sysprefs/marc:syspref[@name='OPACDisplay856uAsImage']"/>
22   <xsl:variable name="leader" select="marc:leader"/>
23   <xsl:variable name="leader6" select="substring($leader,7,1)"/>
24   <xsl:variable name="leader7" select="substring($leader,8,1)"/>
25   <xsl:variable name="biblionumber"
26    select="marc:datafield[@tag=090]/marc:subfield[@code='a']"/>
27   <xsl:variable name="isbn"
28    select="marc:datafield[@tag=010]/marc:subfield[@code='a']"/>
29
30   <xsl:variable name="hidelostitems" select="marc:sysprefs/marc:syspref[@name='hidelostitems']"/>
31
32   <xsl:if test="marc:datafield[@tag=200]">
33     <xsl:for-each select="marc:datafield[@tag=200]">
34       <xsl:variable name="title" select="marc:subfield[@code='a']"/>
35       <xsl:variable name="ntitle"
36        select="translate($title, '&#x0098;&#x009C;','')"/>
37       <div>
38         <xsl:call-template name="addClassRtl" />
39         <span class="results_summary">
40           <span class="label"/>
41           <a>
42             <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of select="$biblionumber"/></xsl:attribute>
43             <xsl:value-of select="$ntitle" />
44           </a>
45           <xsl:if test="marc:subfield[@code='e']">
46             <xsl:text> : </xsl:text>
47             <xsl:for-each select="marc:subfield[@code='e']">
48               <xsl:value-of select="."/>
49             </xsl:for-each>
50           </xsl:if>
51           <xsl:if test="marc:subfield[@code='b']">
52             <xsl:text> [</xsl:text>
53             <xsl:value-of select="marc:subfield[@code='b']"/>
54             <xsl:text>]</xsl:text>
55           </xsl:if>
56           <xsl:if test="marc:subfield[@code='f']">
57             <xsl:text> / </xsl:text>
58             <xsl:value-of select="marc:subfield[@code='f']"/>
59           </xsl:if>
60           <xsl:if test="marc:subfield[@code='g']">
61             <xsl:text> ; </xsl:text>
62             <xsl:value-of select="marc:subfield[@code='g']"/>
63           </xsl:if>
64         </span>
65       </div>
66     </xsl:for-each>
67   </xsl:if>
68
69   <xsl:call-template name="tag_4xx" />
70
71   <xsl:call-template name="tag_210" />
72
73   <xsl:call-template name="tag_215" />
74
75   <span class="results_summary">
76     <span class="label">Availability: </span>
77     <xsl:choose>
78       <xsl:when test="marc:datafield[@tag=856]">
79         <xsl:for-each select="marc:datafield[@tag=856]">
80         <xsl:variable name="SubqText"><xsl:value-of select="marc:subfield[@code='q']"/></xsl:variable>
81           <xsl:choose>
82             <xsl:when test="@ind2=0">
83               <a>
84                 <xsl:attribute name="href">
85                   <xsl:value-of select="marc:subfield[@code='u']"/>
86                 </xsl:attribute>
87                 <xsl:choose>
88                   <xsl:when test="($Show856uAsImage='Results' or $Show856uAsImage='Both') and (substring($SubqText,1,6)='image/' or $SubqText='img' or $SubqText='bmp' or $SubqText='cod' or $SubqText='gif' or $SubqText='ief' or $SubqText='jpe' or $SubqText='jpeg' or $SubqText='jpg' or $SubqText='jfif' or $SubqText='png' or $SubqText='svg' or $SubqText='tif' or $SubqText='tiff' or $SubqText='ras' or $SubqText='cmx' or $SubqText='ico' or $SubqText='pnm' or $SubqText='pbm' or $SubqText='pgm' or $SubqText='ppm' or $SubqText='rgb' or $SubqText='xbm' or $SubqText='xpm' or $SubqText='xwd')">
89                      <xsl:element name="img"><xsl:attribute name="src"><xsl:value-of select="marc:subfield[@code='u']"/></xsl:attribute><xsl:attribute name="alt"><xsl:value-of select="marc:subfield[@code='y']"/></xsl:attribute><xsl:attribute name="height">100</xsl:attribute></xsl:element><xsl:text></xsl:text>
90                   </xsl:when>
91                   <xsl:when test="marc:subfield[@code='y' or @code='3' or @code='z']">
92                     <xsl:call-template name="subfieldSelect">                        
93                       <xsl:with-param name="codes">y3z</xsl:with-param>                    
94                     </xsl:call-template>
95                   </xsl:when>
96                   <xsl:when test="not(marc:subfield[@code='y']) and not(marc:subfield[@code='3']) and not(marc:subfield[@code='z'])">
97                     Click here to access online
98                   </xsl:when>
99                 </xsl:choose>
100               </a>
101               <xsl:choose>
102                 <xsl:when test="position()=last()"></xsl:when>
103                 <xsl:otherwise> | </xsl:otherwise>
104               </xsl:choose>
105             </xsl:when> 
106           </xsl:choose>
107         </xsl:for-each>
108       </xsl:when>
109       <xsl:when test="count(key('item-by-status', 'available'))=0 and count(key('item-by-status', 'reference'))=0">
110         No copies available
111       </xsl:when>
112       <xsl:when test="count(key('item-by-status', 'available'))>0">
113         <span class="available">
114           <b><xsl:text>Copies available for loan: </xsl:text></b>
115           <xsl:variable name="available_items" select="key('item-by-status', 'available')"/>
116           <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
117             <xsl:value-of select="items:homebranch"/>
118                             <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]
119                             </xsl:if>
120             <xsl:text> (</xsl:text>
121             <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
122             <xsl:text>)</xsl:text>
123             <xsl:choose>
124               <xsl:when test="position()=last()">
125                 <xsl:text>. </xsl:text>
126               </xsl:when>
127               <xsl:otherwise>
128                 <xsl:text>, </xsl:text>
129               </xsl:otherwise>
130             </xsl:choose>
131           </xsl:for-each>
132         </span>
133       </xsl:when>
134     </xsl:choose>
135     <xsl:choose>
136       <xsl:when test="count(key('item-by-status', 'reference'))>0">
137         <span class="available">
138           <b><xsl:text>Copies available for reference: </xsl:text></b>
139           <xsl:variable name="reference_items"
140                         select="key('item-by-status', 'reference')"/>
141           <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
142             <xsl:value-of select="items:homebranch"/>
143             <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
144             <xsl:text> (</xsl:text>
145             <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
146             <xsl:text>)</xsl:text>
147             <xsl:choose>
148               <xsl:when test="position()=last()">
149                 <xsl:text>. </xsl:text>
150               </xsl:when>
151               <xsl:otherwise>
152                 <xsl:text>, </xsl:text>
153               </xsl:otherwise>
154             </xsl:choose>
155           </xsl:for-each>
156         </span>
157       </xsl:when>
158     </xsl:choose>
159     <xsl:if test="count(key('item-by-status', 'Checked out'))>0">
160       <span class="unavailable">
161         <xsl:text>Checked out (</xsl:text>
162         <xsl:value-of select="count(key('item-by-status', 'Checked out'))"/>
163         <xsl:text>). </xsl:text>
164       </span>
165     </xsl:if>
166     <xsl:if test="count(key('item-by-status', 'Withdrawn'))>0">
167       <span class="unavailable">
168         <xsl:text>Withdrawn (</xsl:text>
169         <xsl:value-of select="count(key('item-by-status', 'Withdrawn'))"/>
170         <xsl:text>). </xsl:text>
171       </span>
172     </xsl:if>
173     <xsl:if test="$hidelostitems='0' and count(key('item-by-status', 'Lost'))>0">
174       <span class="unavailable">
175         <xsl:text>Lost (</xsl:text>
176         <xsl:value-of select="count(key('item-by-status', 'Lost'))"/>
177         <xsl:text>). </xsl:text>
178       </span>
179     </xsl:if>
180     <xsl:if test="count(key('item-by-status', 'Damaged'))>0">
181       <span class="unavailable">
182         <xsl:text>Damaged (</xsl:text>
183         <xsl:value-of select="count(key('item-by-status', 'Damaged'))"/>
184         <xsl:text>). </xsl:text>
185       </span>
186     </xsl:if>
187     <xsl:if test="count(key('item-by-status', 'On Orangemanr'))>0">
188       <span class="unavailable">
189         <xsl:text>On order (</xsl:text>
190         <xsl:value-of select="count(key('item-by-status', 'On order'))"/>
191         <xsl:text>). </xsl:text>
192       </span>
193     </xsl:if>
194     <xsl:if test="count(key('item-by-status', 'In transit'))>0">
195       <span class="unavailable">
196         <xsl:text>In transit (</xsl:text>
197         <xsl:value-of select="count(key('item-by-status', 'In transit'))"/>
198         <xsl:text>). </xsl:text>
199       </span>
200     </xsl:if>
201     <xsl:if test="count(key('item-by-status', 'Waiting'))>0">
202       <span class="unavailable">
203         <xsl:text>On hold (</xsl:text>
204         <xsl:value-of select="count(key('item-by-status', 'Waiting'))"/>
205         <xsl:text>). </xsl:text>
206       </span>
207     </xsl:if>
208   </span>
209
210 </xsl:template>
211
212 </xsl:stylesheet>