Bug 33902: Move modal inside HTML body
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / UNIMARCslimUtils.xsl
1 <?xml version='1.0'?>
2
3 <!DOCTYPE stylesheet>
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:template name="datafield">
13     <xsl:param name="tag"/>
14     <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
15     <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
16     <xsl:param name="subfields"/>
17     <xsl:element name="datafield">
18       <xsl:attribute name="tag">
19         <xsl:value-of select="$tag"/>
20       </xsl:attribute>
21       <xsl:attribute name="ind1">
22         <xsl:value-of select="$ind1"/>
23       </xsl:attribute>
24       <xsl:attribute name="ind2">
25        <xsl:value-of select="$ind2"/>
26          </xsl:attribute>
27        <xsl:copy-of select="$subfields"/>
28     </xsl:element>
29   </xsl:template>
30
31   <xsl:template name="subfieldSelect">
32     <xsl:param name="codes"/>
33     <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
34     <xsl:param name="subdivCodes"/>
35     <xsl:param name="subdivDelimiter"/>
36     <xsl:param name="urlencode"/>
37     <xsl:variable name="str">
38       <xsl:for-each select="marc:subfield">
39         <xsl:if test="contains($codes, @code)">
40           <xsl:if test="contains($subdivCodes, @code)">
41             <xsl:value-of select="$subdivDelimiter"/>
42           </xsl:if>
43           <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
44         </xsl:if>
45       </xsl:for-each>
46     </xsl:variable>
47     <xsl:choose>
48       <xsl:when test="$urlencode=1">
49         <xsl:value-of select="str:encode-uri(substring($str,1,string-length($str)-string-length($delimeter)), true())"/>
50       </xsl:when>
51       <xsl:otherwise>
52         <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
53       </xsl:otherwise>
54     </xsl:choose>
55   </xsl:template>
56
57   <xsl:template name="buildSpaces">
58     <xsl:param name="spaces"/>
59     <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
60     <xsl:if test="$spaces>0">
61       <xsl:value-of select="$char"/>
62       <xsl:call-template name="buildSpaces">
63         <xsl:with-param name="spaces" select="$spaces - 1"/>
64         <xsl:with-param name="char" select="$char"/>
65       </xsl:call-template>
66     </xsl:if>
67   </xsl:template>
68
69   <xsl:template name="buildBiblioDefaultViewURL">
70     <xsl:param name="BiblioDefaultView"/>
71     <xsl:choose>
72         <xsl:when test="$BiblioDefaultView='normal'">
73             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
74         </xsl:when>
75         <xsl:when test="$BiblioDefaultView='isbd'">
76             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
77         </xsl:when>
78         <xsl:when test="$BiblioDefaultView='marc'">
79             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
80         </xsl:when>
81         <xsl:otherwise>
82             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
83         </xsl:otherwise>
84     </xsl:choose>
85   </xsl:template>
86
87
88   <xsl:template name="chopPunctuation">
89     <xsl:param name="chopString"/>
90     <xsl:variable name="length" select="string-length($chopString)"/>
91     <xsl:choose>
92       <xsl:when test="$length=0"/>
93       <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
94         <xsl:call-template name="chopPunctuation">
95           <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
96         </xsl:call-template>
97       </xsl:when>
98       <xsl:when test="not($chopString)"/>
99       <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
100     </xsl:choose>
101     <xsl:text> </xsl:text>
102   </xsl:template>
103
104   <xsl:template name="addClassRtl">
105     <xsl:variable name="lang" select="marc:subfield[@code='7']" />
106     <xsl:if test="$lang = 'ha' or $lang = 'Hebrew' or $lang = 'fa' or $lang = 'Arabe'">
107       <xsl:attribute name="class">rtl</xsl:attribute>
108     </xsl:if>
109   </xsl:template>
110
111   <xsl:template name="tag_title">
112     <xsl:param name="tag" />
113     <xsl:param name="label" />
114     <xsl:param name="spanclass" />
115     <xsl:if test="marc:datafield[@tag=$tag]">
116       <span class="results_summary {$spanclass}">
117         <span class="label">
118           <xsl:value-of select="$label"/>
119           <xsl:text>: </xsl:text>
120         </span>
121         <xsl:for-each select="marc:datafield[@tag=$tag]">
122           <xsl:call-template name="addClassRtl" />
123           <xsl:for-each select="marc:subfield">
124             <xsl:choose>
125               <xsl:when test="@code='a'">
126                 <xsl:variable name="title" select="."/>
127                 <xsl:variable name="ntitle"
128                  select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
129                 <xsl:value-of select="$ntitle" />
130               </xsl:when>
131               <xsl:when test="@code='b'">
132                 <xsl:text>[</xsl:text>
133                 <xsl:value-of select="."/>
134                 <xsl:text>]</xsl:text>
135               </xsl:when>
136               <xsl:when test="@code='d'">
137                 <xsl:text> = </xsl:text>
138                 <xsl:value-of select="."/>
139               </xsl:when>
140               <xsl:when test="@code='e'">
141                 <xsl:text> : </xsl:text>
142                 <xsl:value-of select="."/>
143               </xsl:when>
144               <xsl:when test="@code='f'">
145                 <xsl:text> / </xsl:text>
146                 <xsl:value-of select="."/>
147               </xsl:when>
148               <xsl:when test="@code='g'">
149                 <xsl:text> ; </xsl:text>
150                 <xsl:value-of select="."/>
151               </xsl:when>
152               <xsl:otherwise>
153                 <xsl:if test="position()>1">
154                   <xsl:text>, </xsl:text>
155                 </xsl:if>
156                 <xsl:value-of select="."/>
157               </xsl:otherwise>
158             </xsl:choose>
159           </xsl:for-each>
160           <xsl:if test="not (position() = last())">
161             <xsl:text> • </xsl:text>
162           </xsl:if>
163         </xsl:for-each>
164       </span>
165     </xsl:if>
166   </xsl:template>
167
168   <xsl:template name="tag_comma">
169     <xsl:param name="tag" />
170     <xsl:param name="label" />
171     <xsl:param name="spanclass" />
172     <xsl:if test="marc:datafield[@tag=$tag]">
173       <span class="results_summary {$spanclass}">
174         <span class="label">
175         <xsl:value-of select="$label"/>: </span>
176         <xsl:for-each select="marc:datafield[@tag=$tag]">
177           <xsl:call-template name="addClassRtl" />
178           <xsl:for-each select="marc:subfield">
179             <xsl:if test="position()>1">
180               <xsl:text>, </xsl:text>
181             </xsl:if>
182             <xsl:value-of select="."/>
183           </xsl:for-each>
184           <xsl:if test="not (position() = last())">
185             <xsl:text> • </xsl:text>
186           </xsl:if>
187         </xsl:for-each>
188       </span>
189     </xsl:if>
190   </xsl:template>
191
192   <xsl:template name="tag_210-214">
193     <xsl:choose>
194       <xsl:when test="marc:datafield[@tag=210] and marc:datafield[@tag=214]">
195         <xsl:call-template name="tag_214" />
196       </xsl:when>
197       <xsl:when test="marc:datafield[@tag=214]">
198         <xsl:call-template name="tag_214" />
199       </xsl:when>
200       <xsl:when test="marc:datafield[@tag=210]">
201         <xsl:call-template name="tag_210" />
202       </xsl:when>
203     </xsl:choose>
204   </xsl:template>
205
206   <xsl:template name="tag_210">
207     <span class="results_summary publication">
208       <span class="label">Publication: </span>
209       <xsl:for-each select="marc:datafield[@tag=210]">
210         <xsl:if test="not(position() = 1)">
211           <br/>
212         </xsl:if>
213         <span class="value">
214           <xsl:call-template name="addClassRtl" />
215           <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c' or @code='d' or @code='g']">
216             <xsl:choose>
217               <xsl:when test="@code='a'">
218                 <xsl:value-of select="."/>
219                 <xsl:if test="position() != last()">
220                   <xsl:text> : </xsl:text>
221                 </xsl:if>
222               </xsl:when>
223               <xsl:when test="@code='b'">
224                 <xsl:value-of select="."/>
225                 <xsl:if test="position() != last()">
226                   <xsl:text>, </xsl:text>
227                 </xsl:if>
228               </xsl:when>
229               <xsl:when test="@code='c' or @code='g'">
230                 <a>
231                   <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=pb:<xsl:value-of select="str:encode-uri(., true())"/></xsl:attribute>
232                   <xsl:attribute name="title">Search for publisher</xsl:attribute>
233                   <xsl:value-of select="."/>
234                 </a>
235                 <xsl:if test="position() != last()">
236                   <xsl:text>, </xsl:text>
237                 </xsl:if>
238               </xsl:when>
239               <xsl:when test="@code='d'">
240                 <xsl:value-of select="."/>
241                 <xsl:if test="position() != last()">
242                   <xsl:text>, </xsl:text>
243                 </xsl:if>
244               </xsl:when>
245             </xsl:choose>
246           </xsl:for-each>
247         </span>
248       </xsl:for-each>
249     </span>
250   </xsl:template>
251
252   <xsl:template name="tag_214">
253     <xsl:for-each select="marc:datafield[@tag=214]">
254       <xsl:sort select="@ind2" data-type="number" />
255       <span class="results_summary publication">
256         <span class="label">
257           <xsl:choose>
258             <xsl:when test="@ind2=1">Production: </xsl:when>
259             <xsl:when test="@ind2=2">Distribution: </xsl:when>
260             <xsl:when test="@ind2=3">Manufacture: </xsl:when>
261             <xsl:when test="@ind2=4">
262               <xsl:choose>
263                 <xsl:when test="substring(marc:subfield[@code='d'],1,1)='C'">Copyright date: </xsl:when>
264                 <xsl:when test="substring(marc:subfield[@code='d'],1,1)='P'">Protection date: </xsl:when>
265                 <xsl:otherwise>Copyright date / protection date: </xsl:otherwise>
266               </xsl:choose>
267             </xsl:when>
268             <xsl:otherwise>Publication: </xsl:otherwise>
269           </xsl:choose>
270         </span>
271         <span>
272           <xsl:call-template name="addClassRtl" />
273           <xsl:for-each select="marc:subfield">
274             <xsl:choose>
275               <xsl:when test="@code='a'">
276                 <xsl:value-of select="."/>
277                 <xsl:if test="position() != last()">
278                   <xsl:text> : </xsl:text>
279                 </xsl:if>
280               </xsl:when>
281               <xsl:when test="@code='b'">
282                 <xsl:value-of select="."/>
283                 <xsl:if test="position() != last()">
284                   <xsl:text>, </xsl:text>
285                 </xsl:if>
286               </xsl:when>
287               <xsl:when test="@code='c'">
288                 <a>
289                   <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=pb:<xsl:value-of select="str:encode-uri(., true())"/></xsl:attribute>
290                   <xsl:attribute name="title">Search for publisher</xsl:attribute>
291                   <xsl:value-of select="."/>
292                 </a>
293               </xsl:when>
294               <xsl:when test="@code='d'">
295                 <xsl:if test="not(position()=1)">
296                   <xsl:text>, </xsl:text>
297                 </xsl:if>
298                 <xsl:choose>
299                   <xsl:when test="substring(.,1,1)='C'">
300                     <xsl:value-of select="substring(.,2)"/>
301                   </xsl:when>
302                   <xsl:when test="substring(.,1,1)='P'">
303                     <xsl:value-of select="substring(.,2)"/>
304                   </xsl:when>
305                   <xsl:otherwise>
306                     <xsl:value-of select="."/>
307                   </xsl:otherwise>
308                 </xsl:choose>
309               </xsl:when>
310             </xsl:choose>
311           </xsl:for-each>
312         </span>
313       </span>
314     </xsl:for-each>
315     <xsl:call-template name="tag_214_r" />
316     <xsl:call-template name="tag_214_s" />
317   </xsl:template>
318
319   <xsl:template name="tag_214_s">
320     <xsl:if test="marc:datafield[@tag=214]/marc:subfield[@code='s']">
321       <span class="results_summary tag_214_s">
322         <span class="label">Printing and/or Publishing Information Transcribed as Found in the Colophon: </span>
323         <xsl:for-each select="marc:datafield[@tag=214]/marc:subfield[@code='s']">
324           <xsl:value-of select="."/>
325           <xsl:choose>
326             <xsl:when test="position()=last()">
327               <xsl:text>.</xsl:text>
328             </xsl:when>
329             <xsl:otherwise>
330               <xsl:text>, </xsl:text>
331             </xsl:otherwise>
332           </xsl:choose>
333         </xsl:for-each>
334       </span>
335     </xsl:if>
336   </xsl:template>
337
338   <xsl:template name="tag_214_r">
339     <xsl:if test="marc:datafield[@tag=214]/marc:subfield[@code='r']">
340       <span class="results_summary tag_214_r">
341         <span class="label">Printing and/or Publishing Information Transcribed as Found in the Main Source of Information: </span>
342         <xsl:for-each select="marc:datafield[@tag=214]/marc:subfield[@code='r']">
343           <xsl:value-of select="."/>
344           <xsl:choose>
345             <xsl:when test="position()=last()">
346               <xsl:text>.</xsl:text>
347             </xsl:when>
348             <xsl:otherwise>
349               <xsl:text>, </xsl:text>
350             </xsl:otherwise>
351           </xsl:choose>
352         </xsl:for-each>
353       </span>
354     </xsl:if>
355   </xsl:template>
356
357   <xsl:template name="tag_215">
358     <xsl:for-each select="marc:datafield[@tag=215]">
359       <span class="results_summary description">
360         <span class="label">Description: </span>
361         <xsl:if test="marc:subfield[@code='a']">
362           <xsl:value-of select="marc:subfield[@code='a']"/>
363         </xsl:if>
364         <xsl:if test="marc:subfield[@code='c']"> :
365           <xsl:value-of select="marc:subfield[@code='c']"/>
366         </xsl:if>
367         <xsl:if test="marc:subfield[@code='d']"> ;
368           <xsl:value-of select="marc:subfield[@code='d']"/>
369         </xsl:if>
370         <xsl:if test="marc:subfield[@code='e']"> +
371           <xsl:value-of select="marc:subfield[@code='e']"/>
372         </xsl:if>
373       </span>
374     </xsl:for-each>
375   </xsl:template>
376
377   <xsl:template name="tag_onesubject">
378     <xsl:choose>
379       <xsl:when test="marc:subfield[@code=9]">
380         <xsl:for-each select="marc:subfield">
381           <xsl:if test="@code='9'">
382             <xsl:variable name="start" select="position()"/>
383             <xsl:variable name="ends">
384               <xsl:for-each select="../marc:subfield[position() &gt; $start]">
385                 <xsl:if test="@code=9">
386                   <xsl:variable name="end" select="position() + $start"/>
387                   <xsl:value-of select="$end"/>
388                   <xsl:text>,</xsl:text>
389                 </xsl:if>
390               </xsl:for-each>
391             </xsl:variable>
392             <xsl:variable name="end">
393               <xsl:choose>
394                 <xsl:when test="string-length($ends) > 0">
395                   <xsl:value-of select="substring-before($ends,',')"/>
396                 </xsl:when>
397                 <xsl:otherwise>
398                   <xsl:text>1000</xsl:text>
399                 </xsl:otherwise>
400               </xsl:choose>
401             </xsl:variable>
402             <xsl:variable name="display">
403               <xsl:for-each select="../marc:subfield[position() &gt; $start and position() &lt; $end and @code!=2 and @code!=3]">
404                 <xsl:value-of select="."/>
405                 <xsl:if test="not(position()=last())">
406                   <xsl:text>, </xsl:text>
407                 </xsl:if>
408               </xsl:for-each>
409             </xsl:variable>
410             <a>
411               <xsl:attribute name="href">
412                 <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
413                 <xsl:value-of select="str:encode-uri(., true())"/>
414               </xsl:attribute>
415               <xsl:choose>
416                 <xsl:when test="string-length($display) &gt; 0">
417                   <xsl:call-template name="chopPunctuation">
418                     <xsl:with-param name="chopString">
419                       <xsl:value-of select="$display"/>
420                     </xsl:with-param>
421                   </xsl:call-template>
422                 </xsl:when>
423                 <xsl:otherwise>
424                   <xsl:value-of select="."/>
425                 </xsl:otherwise>
426               </xsl:choose>
427             </a>
428             <xsl:variable name="ncommas"
429                  select="string-length($ends) - string-length(translate($ends, ',', ''))" />
430             <xsl:if test="$ncommas &gt; 1">
431               <xsl:text> -- </xsl:text>
432             </xsl:if>
433           </xsl:if>
434         </xsl:for-each>
435       </xsl:when>
436       <xsl:when test="marc:subfield[@code='a']">
437         <a>
438           <xsl:attribute name="href">
439             <xsl:text>/cgi-bin/koha/opac-search.pl?q=su:</xsl:text>
440             <xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
441           </xsl:attribute>
442           <xsl:call-template name="chopPunctuation">
443             <xsl:with-param name="chopString">
444               <xsl:call-template name="subfieldSelect">
445                 <xsl:with-param name="codes">abcdfijkmnptvxyz</xsl:with-param>
446                 <xsl:with-param name="subdivCodes">ijknpxyz</xsl:with-param>
447                 <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
448               </xsl:call-template>
449             </xsl:with-param>
450           </xsl:call-template>
451         </a>
452       </xsl:when>
453       <xsl:otherwise/>
454     </xsl:choose>
455     <xsl:if test="not(position()=last())">
456       <xsl:text> | </xsl:text>
457     </xsl:if>
458   </xsl:template>
459
460   <xsl:template name="tag_subject">
461     <xsl:param name="tag" />
462     <xsl:param name="label" />
463     <xsl:param name="spanclass" />
464     <xsl:if test="marc:datafield[@tag=$tag]">
465       <span class="results_summary subjects {$spanclass}">
466         <span class="label">
467           <xsl:value-of select="$label"/>
468           <xsl:text>: </xsl:text>
469         </span>
470         <span class="value">
471           <xsl:for-each select="marc:datafield[@tag=$tag]">
472             <xsl:call-template name="tag_onesubject">
473             </xsl:call-template>
474           </xsl:for-each>
475         </span>
476       </span>
477     </xsl:if>
478   </xsl:template>
479
480   <xsl:template name="tag_7xx">
481     <xsl:param name="tag" />
482     <xsl:param name="label" />
483     <xsl:param name="spanclass" />
484     <xsl:variable name="IdRef" select="marc:sysprefs/marc:syspref[@name='IdRef']"/>
485     <xsl:if test="marc:datafield[@tag=$tag]">
486       <span class="results_summary author {$spanclass}">
487         <span class="label">
488           <xsl:value-of select="$label" />
489           <xsl:text>: </xsl:text>
490         </span>
491         <span class="value">
492           <xsl:for-each select="marc:datafield[@tag=$tag]">
493             <a>
494               <xsl:choose>
495                 <xsl:when test="marc:subfield[@code=9]">
496                   <xsl:attribute name="href">
497                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
498                     <xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
499                   </xsl:attribute>
500                 </xsl:when>
501                 <xsl:otherwise>
502                   <xsl:attribute name="href">
503                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=au:</xsl:text>
504                     <xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
505                     <xsl:text>%20</xsl:text>
506                     <xsl:value-of select="str:encode-uri(marc:subfield[@code='b'], true())"/>
507                   </xsl:attribute>
508                 </xsl:otherwise>
509               </xsl:choose>
510               <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']">
511                 <xsl:choose>
512                   <xsl:when test="@code='9'">
513                   </xsl:when>
514                   <xsl:otherwise>
515                     <xsl:value-of select="."/>
516                   </xsl:otherwise>
517                 </xsl:choose>
518                 <xsl:if test="not(position() = last())">
519                   <xsl:text>, </xsl:text>
520                 </xsl:if>
521               </xsl:for-each>
522             </a>
523             <xsl:if test="$IdRef = '1'">
524               <xsl:if test="marc:subfield[@code=3]">
525                 <xsl:text> </xsl:text>
526                 <a>
527                   <xsl:attribute name="href">
528                     <xsl:text>/cgi-bin/koha/opac-idref.pl?unimarc3=</xsl:text>
529                     <xsl:value-of select="str:encode-uri(marc:subfield[@code=3], true())"/>
530                   </xsl:attribute>
531                   <xsl:attribute name="title">IdRef</xsl:attribute>
532                   <xsl:attribute name="rel">gb_page_center[600,500]</xsl:attribute>
533                   <xsl:text>Idref</xsl:text>
534                 </a>
535               </xsl:if>
536             </xsl:if>
537             <xsl:if test="not(position() = last())">
538               <span style="padding: 3px;">
539                 <xsl:text>;</xsl:text>
540               </span>
541             </xsl:if>
542           </xsl:for-each>
543         </span>
544       </span>
545     </xsl:if>
546   </xsl:template>
547
548 </xsl:stylesheet>