Bug 15140: Display $i when ind2==8
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / UNIMARCslimUtils.xsl
1 <?xml version='1.0'?>
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:template name="datafield">
12     <xsl:param name="tag"/>
13     <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
14     <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
15     <xsl:param name="subfields"/>
16     <xsl:element name="datafield">
17       <xsl:attribute name="tag">
18         <xsl:value-of select="$tag"/>
19       </xsl:attribute>
20       <xsl:attribute name="ind1">
21         <xsl:value-of select="$ind1"/>
22       </xsl:attribute>
23       <xsl:attribute name="ind2">
24        <xsl:value-of select="$ind2"/>
25          </xsl:attribute>
26        <xsl:copy-of select="$subfields"/>
27     </xsl:element>
28   </xsl:template>
29
30   <xsl:template name="subfieldSelect">
31     <xsl:param name="codes"/>
32     <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
33     <xsl:param name="subdivCodes"/>
34     <xsl:param name="subdivDelimiter"/>
35     <xsl:variable name="str">
36       <xsl:for-each select="marc:subfield">
37         <xsl:if test="contains($codes, @code)">
38           <xsl:if test="contains($subdivCodes, @code)">
39             <xsl:value-of select="$subdivDelimiter"/>
40           </xsl:if>
41           <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
42         </xsl:if>
43       </xsl:for-each>
44     </xsl:variable>
45     <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
46   </xsl:template>
47
48   <xsl:template name="buildSpaces">
49     <xsl:param name="spaces"/>
50     <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
51     <xsl:if test="$spaces>0">
52       <xsl:value-of select="$char"/>
53       <xsl:call-template name="buildSpaces">
54         <xsl:with-param name="spaces" select="$spaces - 1"/>
55         <xsl:with-param name="char" select="$char"/>
56       </xsl:call-template>
57     </xsl:if>
58   </xsl:template>
59
60   <xsl:template name="buildBiblioDefaultViewURL">
61     <xsl:param name="BiblioDefaultView"/>
62     <xsl:choose>
63         <xsl:when test="$BiblioDefaultView='normal'">
64             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
65         </xsl:when>
66         <xsl:when test="$BiblioDefaultView='isbd'">
67             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
68         </xsl:when>
69         <xsl:when test="$BiblioDefaultView='marc'">
70             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
71         </xsl:when>
72         <xsl:otherwise>
73             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
74         </xsl:otherwise>
75     </xsl:choose>
76   </xsl:template>
77
78
79   <xsl:template name="chopPunctuation">
80     <xsl:param name="chopString"/>
81     <xsl:variable name="length" select="string-length($chopString)"/>
82     <xsl:choose>
83       <xsl:when test="$length=0"/>
84       <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
85         <xsl:call-template name="chopPunctuation">
86           <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
87         </xsl:call-template>
88       </xsl:when>
89       <xsl:when test="not($chopString)"/>
90       <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
91     </xsl:choose>
92     <xsl:text> </xsl:text>
93   </xsl:template>
94
95   <xsl:template name="addClassRtl">
96     <xsl:variable name="lang" select="marc:subfield[@code='7']" />
97     <xsl:if test="$lang = 'ha' or $lang = 'Hebrew' or $lang = 'fa' or $lang = 'Arabe'">
98       <xsl:attribute name="class">rtl</xsl:attribute>
99     </xsl:if>
100   </xsl:template>
101
102   <xsl:template name="tag_title">
103     <xsl:param name="tag" />
104     <xsl:param name="label" />
105     <xsl:param name="spanclass" />
106     <xsl:if test="marc:datafield[@tag=$tag]">
107       <span class="results_summary {$spanclass}">
108         <span class="label">
109         <xsl:value-of select="$label"/>: </span>
110         <xsl:for-each select="marc:datafield[@tag=$tag]">
111           <xsl:call-template name="addClassRtl" />
112           <xsl:for-each select="marc:subfield">
113             <xsl:choose>
114               <xsl:when test="@code='a'">
115                 <xsl:variable name="title" select="."/>
116                 <xsl:variable name="ntitle"
117                  select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
118                 <xsl:value-of select="$ntitle" />
119               </xsl:when>
120               <xsl:when test="@code='b'">
121                 <xsl:text>[</xsl:text>
122                 <xsl:value-of select="."/>
123                 <xsl:text>]</xsl:text>
124               </xsl:when>
125               <xsl:when test="@code='d'">
126                 <xsl:text> = </xsl:text>
127                 <xsl:value-of select="."/>
128               </xsl:when>
129               <xsl:when test="@code='e'">
130                 <xsl:text> : </xsl:text>
131                 <xsl:value-of select="."/>
132               </xsl:when>
133               <xsl:when test="@code='f'">
134                 <xsl:text> / </xsl:text>
135                 <xsl:value-of select="."/>
136               </xsl:when>
137               <xsl:when test="@code='g'">
138                 <xsl:text> ; </xsl:text>
139                 <xsl:value-of select="."/>
140               </xsl:when>
141               <xsl:otherwise>
142                 <xsl:if test="position()>1">
143                   <xsl:text>, </xsl:text>
144                 </xsl:if>
145                 <xsl:value-of select="."/>
146               </xsl:otherwise>
147             </xsl:choose>
148           </xsl:for-each>
149           <xsl:if test="not (position() = last())">
150             <xsl:text> • </xsl:text>
151           </xsl:if>
152         </xsl:for-each>
153       </span>
154     </xsl:if>
155   </xsl:template>
156
157   <xsl:template name="tag_comma">
158     <xsl:param name="tag" />
159     <xsl:param name="label" />
160     <xsl:param name="spanclass" />
161     <xsl:if test="marc:datafield[@tag=$tag]">
162       <span class="results_summary {$spanclass}">
163         <span class="label">
164         <xsl:value-of select="$label"/>: </span>
165         <xsl:for-each select="marc:datafield[@tag=$tag]">
166           <xsl:call-template name="addClassRtl" />
167           <xsl:for-each select="marc:subfield">
168             <xsl:if test="position()>1">
169               <xsl:text>, </xsl:text>
170             </xsl:if>
171             <xsl:value-of select="."/>
172           </xsl:for-each>
173           <xsl:if test="not (position() = last())">
174             <xsl:text> • </xsl:text>
175           </xsl:if>
176         </xsl:for-each>
177       </span>
178     </xsl:if>
179   </xsl:template>
180
181   <xsl:template name="tag_210">
182     <span class="results_summary publication">
183       <span class="label">Publication: </span>
184       <xsl:for-each select="marc:datafield[@tag=210]">
185         <span>
186           <xsl:call-template name="addClassRtl" />
187           <xsl:for-each select="marc:subfield">
188             <xsl:choose>
189               <xsl:when test="@code='c' or @code='g'">
190                 <xsl:if test="position()>1">
191                   <xsl:text> : </xsl:text>
192                 </xsl:if>
193                 <xsl:value-of select="."/>
194               </xsl:when>
195               <xsl:otherwise>
196                 <xsl:if test="position()>1">
197                   <xsl:text>, </xsl:text>
198                 </xsl:if>
199                 <xsl:value-of select="."/>
200               </xsl:otherwise>
201             </xsl:choose>
202           </xsl:for-each>
203           <xsl:if test="not (position() = last())">
204             <xsl:text> • </xsl:text>
205           </xsl:if>
206         </span>
207       </xsl:for-each>
208     </span>
209   </xsl:template>
210
211   <xsl:template name="tag_215">
212     <xsl:for-each select="marc:datafield[@tag=215]">
213           <span class="results_summary description">
214         <span class="label">Description: </span>
215         <xsl:if test="marc:subfield[@code='a']">
216           <xsl:value-of select="marc:subfield[@code='a']"/>
217         </xsl:if>
218         <xsl:if test="marc:subfield[@code='c']"> :
219           <xsl:value-of select="marc:subfield[@code='c']"/>
220         </xsl:if>
221         <xsl:if test="marc:subfield[@code='d']"> ;
222           <xsl:value-of select="marc:subfield[@code='d']"/>
223         </xsl:if>
224         <xsl:if test="marc:subfield[@code='e']"> +
225           <xsl:value-of select="marc:subfield[@code='e']"/>
226         </xsl:if>
227       </span>
228     </xsl:for-each>
229   </xsl:template>
230
231   <xsl:template name="tag_onesubject">
232     <xsl:choose>
233       <xsl:when test="marc:subfield[@code=9]">
234         <xsl:for-each select="marc:subfield">
235           <xsl:if test="@code='9'">
236             <xsl:variable name="start" select="position()"/>
237             <xsl:variable name="ends">
238               <xsl:for-each select="../marc:subfield[position() &gt; $start]">
239                 <xsl:if test="@code=9">
240                   <xsl:variable name="end" select="position() + $start"/>
241                   <xsl:value-of select="$end"/>
242                   <xsl:text>,</xsl:text>
243                 </xsl:if>
244               </xsl:for-each>
245             </xsl:variable>
246             <xsl:variable name="end">
247               <xsl:choose>
248                 <xsl:when test="string-length($ends) > 0">
249                   <xsl:value-of select="substring-before($ends,',')"/>
250                 </xsl:when>
251                 <xsl:otherwise>
252                   <xsl:text>1000</xsl:text>
253                 </xsl:otherwise>
254               </xsl:choose>
255             </xsl:variable>
256             <xsl:variable name="display">
257               <xsl:for-each select="../marc:subfield[position() &gt; $start and position() &lt; $end and @code!=2 and @code!=3]">
258                 <xsl:value-of select="."/>
259                 <xsl:if test="not(position()=last())">
260                   <xsl:text>, </xsl:text>
261                 </xsl:if>
262               </xsl:for-each>
263             </xsl:variable>
264             <a>
265               <xsl:attribute name="href">
266                 <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
267                 <xsl:value-of select="."/>
268               </xsl:attribute>
269               <xsl:choose>
270                 <xsl:when test="string-length($display) &gt; 0">
271                   <xsl:call-template name="chopPunctuation">
272                     <xsl:with-param name="chopString">
273                       <xsl:value-of select="$display"/>
274                     </xsl:with-param>
275                   </xsl:call-template>
276                 </xsl:when>
277                 <xsl:otherwise>
278                   <xsl:value-of select="."/>
279                 </xsl:otherwise>
280               </xsl:choose>
281             </a>
282             <xsl:variable name="ncommas"
283                  select="string-length($ends) - string-length(translate($ends, ',', ''))" />
284             <xsl:if test="$ncommas &gt; 1">
285               <xsl:text> -- </xsl:text>
286             </xsl:if>
287           </xsl:if>
288         </xsl:for-each>
289       </xsl:when>
290       <xsl:when test="marc:subfield[@code='a']">
291         <a>
292           <xsl:attribute name="href">
293             <xsl:text>/cgi-bin/koha/opac-search.pl?q=su:</xsl:text>
294             <xsl:value-of select="marc:subfield[@code='a']"/>
295           </xsl:attribute>
296           <xsl:call-template name="chopPunctuation">
297             <xsl:with-param name="chopString">
298               <xsl:call-template name="subfieldSelect">
299                 <xsl:with-param name="codes">abcdfijkmnpvxyz</xsl:with-param>
300                 <xsl:with-param name="subdivCodes">ijknpxyz</xsl:with-param>
301                 <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
302               </xsl:call-template>
303             </xsl:with-param>
304           </xsl:call-template>
305         </a>
306       </xsl:when>
307       <xsl:otherwise/>
308     </xsl:choose>
309     <xsl:if test="not(position()=last())">
310       <xsl:text> | </xsl:text>
311     </xsl:if>
312   </xsl:template>
313
314   <xsl:template name="tag_subject">
315     <xsl:param name="tag" />
316     <xsl:param name="label" />
317     <xsl:param name="spanclass" />
318     <xsl:if test="marc:datafield[@tag=$tag]">
319       <span class="results_summary subjects {$spanclass}">
320         <span class="label">
321           <xsl:value-of select="$label"/>
322           <xsl:text>: </xsl:text>
323         </span>
324         <span class="value">
325           <xsl:for-each select="marc:datafield[@tag=$tag]">
326             <xsl:call-template name="tag_onesubject">
327             </xsl:call-template>
328           </xsl:for-each>
329         </span>
330       </span>
331     </xsl:if>
332   </xsl:template>
333
334   <xsl:template name="tag_7xx">
335     <xsl:param name="tag" />
336     <xsl:param name="label" />
337     <xsl:param name="spanclass" />
338     <xsl:variable name="IdRef" select="marc:sysprefs/marc:syspref[@name='IdRef']"/>
339     <xsl:if test="marc:datafield[@tag=$tag]">
340       <span class="results_summary author {$spanclass}">
341         <span class="label">
342           <xsl:value-of select="$label" />
343           <xsl:text>: </xsl:text>
344         </span>
345         <span class="value">
346           <xsl:for-each select="marc:datafield[@tag=$tag]">
347             <a>
348               <xsl:choose>
349                 <xsl:when test="marc:subfield[@code=9]">
350                   <xsl:attribute name="href">
351                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
352                     <xsl:value-of select="marc:subfield[@code=9]"/>
353                   </xsl:attribute>
354                 </xsl:when>
355                 <xsl:otherwise>
356                   <xsl:attribute name="href">
357                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=au:</xsl:text>
358                     <xsl:value-of select="marc:subfield[@code='a']"/>
359                     <xsl:text> </xsl:text>
360                     <xsl:value-of select="marc:subfield[@code='b']"/>
361                   </xsl:attribute>
362                 </xsl:otherwise>
363               </xsl:choose>
364               <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='4' or @code='c' or @code='d' or @code='f' or @code='g' or @code='p']">
365                 <xsl:choose>
366                   <xsl:when test="@code='9'">
367                   </xsl:when>
368                   <xsl:otherwise>
369                     <xsl:value-of select="."/>
370                   </xsl:otherwise>
371                 </xsl:choose>
372                 <xsl:if test="not(position() = last())">
373                   <xsl:text>, </xsl:text>
374                 </xsl:if>
375               </xsl:for-each>
376             </a>
377             <xsl:if test="$IdRef">
378               <xsl:if test="marc:subfield[@code=3]">
379                 <xsl:text> </xsl:text>
380                 <a>
381                   <xsl:attribute name="href">
382                     <xsl:text>/cgi-bin/koha/opac-idref.pl?unimarc3=</xsl:text>
383                     <xsl:value-of select="marc:subfield[@code=3]"/>
384                   </xsl:attribute>
385                   <xsl:attribute name="title">IdRef</xsl:attribute>
386                   <xsl:attribute name="rel">gb_page_center[600,500]</xsl:attribute>
387                   <xsl:text>Idref</xsl:text>
388                 </a>
389               </xsl:if>
390             </xsl:if>
391             <xsl:if test="not(position() = last())">
392               <span style="padding: 3px;">
393                 <xsl:text>;</xsl:text>
394               </span>
395             </xsl:if>
396           </xsl:for-each>
397         </span>
398       </span>
399     </xsl:if>
400   </xsl:template>
401
402 </xsl:stylesheet>