Bug 6314 XSL UNIMARC Improvments
[koha.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="leader" select="marc:leader"/>
22   <xsl:variable name="leader6" select="substring($leader,7,1)"/>
23   <xsl:variable name="leader7" select="substring($leader,8,1)"/>
24   <xsl:variable name="biblionumber"
25    select="marc:datafield[@tag=090]/marc:subfield[@code='a']"/>
26   <xsl:variable name="isbn"
27    select="marc:datafield[@tag=010]/marc:subfield[@code='a']"/>
28
29   <xsl:variable name="hidelostitems" select="marc:sysprefs/marc:syspref[@name='hidelostitems']"/>
30
31   <xsl:if test="marc:datafield[@tag=200]">
32     <xsl:for-each select="marc:datafield[@tag=200]">
33         <xsl:call-template name="addClassRtl" />
34         <xsl:for-each select="marc:subfield">
35           <xsl:choose>
36             <xsl:when test="@code='a'">
37               <xsl:variable name="title" select="."/>
38               <xsl:variable name="ntitle"
39                 select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
40               <a>
41                 <xsl:attribute name="href">
42                   <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
43                   <xsl:value-of select="$biblionumber"/>
44                 </xsl:attribute>
45                 <xsl:value-of select="$ntitle" />
46               </a>
47             </xsl:when>
48             <xsl:when test="@code='b'">
49               <xsl:text> [</xsl:text>
50               <xsl:value-of select="."/>
51               <xsl:text>]</xsl:text>
52             </xsl:when>
53             <xsl:when test="@code='d'">
54               <xsl:text> = </xsl:text>
55               <xsl:value-of select="."/>
56             </xsl:when>
57             <xsl:when test="@code='e'">
58               <xsl:text> : </xsl:text>
59               <xsl:value-of select="."/>
60             </xsl:when>
61             <xsl:when test="@code='f'">
62               <xsl:text> / </xsl:text>
63               <xsl:value-of select="."/>
64             </xsl:when>
65             <xsl:when test="@code='g'">
66               <xsl:text> ; </xsl:text>
67               <xsl:value-of select="."/>
68             </xsl:when>
69             <xsl:otherwise>
70               <xsl:text>, </xsl:text>
71               <xsl:value-of select="."/>
72             </xsl:otherwise>
73           </xsl:choose>
74         </xsl:for-each>
75     </xsl:for-each>
76   </xsl:if>
77
78   <xsl:call-template name="tag_title">
79     <xsl:with-param name="tag">454</xsl:with-param>
80     <xsl:with-param name="label">Translation of</xsl:with-param>
81   </xsl:call-template>
82
83   <xsl:call-template name="tag_title">
84     <xsl:with-param name="tag">461</xsl:with-param>
85     <xsl:with-param name="label">Set Level</xsl:with-param>
86   </xsl:call-template>
87
88   <xsl:call-template name="tag_title">
89     <xsl:with-param name="tag">464</xsl:with-param>
90     <xsl:with-param name="label">Piece-Analytic Level</xsl:with-param>
91   </xsl:call-template>
92
93   <xsl:call-template name="tag_210" />
94
95   <xsl:call-template name="tag_215" />
96
97   <span class="results_summary">
98     <span class="label">Availability: </span>
99     <xsl:choose>
100       <xsl:when test="marc:datafield[@tag=856]">
101         <xsl:for-each select="marc:datafield[@tag=856]">
102           <xsl:choose>
103             <xsl:when test="@ind2=0">
104               <a>
105                 <xsl:attribute name="href">
106                   <xsl:value-of select="marc:subfield[@code='u']"/>
107                 </xsl:attribute>
108                 <xsl:choose>
109                   <xsl:when test="marc:subfield[@code='y' or @code='3' or @code='z']">
110                     <xsl:call-template name="subfieldSelect">                        
111                       <xsl:with-param name="codes">y3z</xsl:with-param>                    
112                     </xsl:call-template>
113                   </xsl:when>
114                   <xsl:when test="not(marc:subfield[@code='y']) and not(marc:subfield[@code='3']) and not(marc:subfield[@code='z'])">
115                     Click here to access online
116                   </xsl:when>
117                 </xsl:choose>
118               </a>
119               <xsl:choose>
120                 <xsl:when test="position()=last()"></xsl:when>
121                 <xsl:otherwise> | </xsl:otherwise>
122               </xsl:choose>
123             </xsl:when> 
124           </xsl:choose>
125         </xsl:for-each>
126       </xsl:when>
127       <xsl:when test="count(key('item-by-status', 'available'))=0 and count(key('item-by-status', 'reference'))=0">
128         No copies available
129       </xsl:when>
130       <xsl:when test="count(key('item-by-status', 'available'))>0">
131         <span class="available">
132           <b><xsl:text>Copies available for loan: </xsl:text></b>
133           <xsl:variable name="available_items" select="key('item-by-status', 'available')"/>
134           <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
135             <xsl:value-of select="items:homebranch"/>
136                             <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]
137                             </xsl:if>
138             <xsl:text> (</xsl:text>
139             <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
140             <xsl:text>)</xsl:text>
141             <xsl:choose>
142               <xsl:when test="position()=last()">
143                 <xsl:text>. </xsl:text>
144               </xsl:when>
145               <xsl:otherwise>
146                 <xsl:text>, </xsl:text>
147               </xsl:otherwise>
148             </xsl:choose>
149           </xsl:for-each>
150         </span>
151       </xsl:when>
152     </xsl:choose>
153     <xsl:choose>
154       <xsl:when test="count(key('item-by-status', 'reference'))>0">
155         <span class="available">
156           <b><xsl:text>Copies available for reference: </xsl:text></b>
157           <xsl:variable name="reference_items"
158                         select="key('item-by-status', 'reference')"/>
159           <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
160             <xsl:value-of select="items:homebranch"/>
161             <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
162             <xsl:text> (</xsl:text>
163             <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
164             <xsl:text>)</xsl:text>
165             <xsl:choose>
166               <xsl:when test="position()=last()">
167                 <xsl:text>. </xsl:text>
168               </xsl:when>
169               <xsl:otherwise>
170                 <xsl:text>, </xsl:text>
171               </xsl:otherwise>
172             </xsl:choose>
173           </xsl:for-each>
174         </span>
175       </xsl:when>
176     </xsl:choose>
177     <xsl:if test="count(key('item-by-status', 'Checked out'))>0">
178       <span class="unavailable">
179         <xsl:text>Checked out (</xsl:text>
180         <xsl:value-of select="count(key('item-by-status', 'Checked out'))"/>
181         <xsl:text>). </xsl:text>
182       </span>
183     </xsl:if>
184     <xsl:if test="count(key('item-by-status', 'Withdrawn'))>0">
185       <span class="unavailable">
186         <xsl:text>Withdrawn (</xsl:text>
187         <xsl:value-of select="count(key('item-by-status', 'Withdrawn'))"/>
188         <xsl:text>). </xsl:text>
189       </span>
190     </xsl:if>
191     <xsl:if test="$hidelostitems='0' and count(key('item-by-status', 'Lost'))>0">
192       <span class="unavailable">
193         <xsl:text>Lost (</xsl:text>
194         <xsl:value-of select="count(key('item-by-status', 'Lost'))"/>
195         <xsl:text>). </xsl:text>
196       </span>
197     </xsl:if>
198     <xsl:if test="count(key('item-by-status', 'Damaged'))>0">
199       <span class="unavailable">
200         <xsl:text>Damaged (</xsl:text>
201         <xsl:value-of select="count(key('item-by-status', 'Damaged'))"/>
202         <xsl:text>). </xsl:text>
203       </span>
204     </xsl:if>
205     <xsl:if test="count(key('item-by-status', 'On Orangemanr'))>0">
206       <span class="unavailable">
207         <xsl:text>On order (</xsl:text>
208         <xsl:value-of select="count(key('item-by-status', 'On order'))"/>
209         <xsl:text>). </xsl:text>
210       </span>
211     </xsl:if>
212     <xsl:if test="count(key('item-by-status', 'In transit'))>0">
213       <span class="unavailable">
214         <xsl:text>In transit (</xsl:text>
215         <xsl:value-of select="count(key('item-by-status', 'In transit'))"/>
216         <xsl:text>). </xsl:text>
217       </span>
218     </xsl:if>
219     <xsl:if test="count(key('item-by-status', 'Waiting'))>0">
220       <span class="unavailable">
221         <xsl:text>On hold (</xsl:text>
222         <xsl:value-of select="count(key('item-by-status', 'Waiting'))"/>
223         <xsl:text>). </xsl:text>
224       </span>
225     </xsl:if>
226   </span>
227
228 </xsl:template>
229
230 </xsl:stylesheet>