Bug 14716: Fix more unencoded url parameters.
[koha-ffzg.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   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"/>: </span>
119         <xsl:for-each select="marc:datafield[@tag=$tag]">
120           <xsl:call-template name="addClassRtl" />
121           <xsl:for-each select="marc:subfield">
122             <xsl:choose>
123               <xsl:when test="@code='a'">
124                 <xsl:variable name="title" select="."/>
125                 <xsl:variable name="ntitle"
126                  select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
127                 <xsl:value-of select="$ntitle" />
128               </xsl:when>
129               <xsl:when test="@code='b'">
130                 <xsl:text>[</xsl:text>
131                 <xsl:value-of select="."/>
132                 <xsl:text>]</xsl:text>
133               </xsl:when>
134               <xsl:when test="@code='d'">
135                 <xsl:text> = </xsl:text>
136                 <xsl:value-of select="."/>
137               </xsl:when>
138               <xsl:when test="@code='e'">
139                 <xsl:text> : </xsl:text>
140                 <xsl:value-of select="."/>
141               </xsl:when>
142               <xsl:when test="@code='f'">
143                 <xsl:text> / </xsl:text>
144                 <xsl:value-of select="."/>
145               </xsl:when>
146               <xsl:when test="@code='g'">
147                 <xsl:text> ; </xsl:text>
148                 <xsl:value-of select="."/>
149               </xsl:when>
150               <xsl:otherwise>
151                 <xsl:if test="position()>1">
152                   <xsl:text>, </xsl:text>
153                 </xsl:if>
154                 <xsl:value-of select="."/>
155               </xsl:otherwise>
156             </xsl:choose>
157           </xsl:for-each>
158           <xsl:if test="not (position() = last())">
159             <xsl:text> • </xsl:text>
160           </xsl:if>
161         </xsl:for-each>
162       </span>
163     </xsl:if>
164   </xsl:template>
165
166   <xsl:template name="tag_comma">
167     <xsl:param name="tag" />
168     <xsl:param name="label" />
169     <xsl:param name="spanclass" />
170     <xsl:if test="marc:datafield[@tag=$tag]">
171       <span class="results_summary {$spanclass}">
172         <span class="label">
173         <xsl:value-of select="$label"/>: </span>
174         <xsl:for-each select="marc:datafield[@tag=$tag]">
175           <xsl:call-template name="addClassRtl" />
176           <xsl:for-each select="marc:subfield">
177             <xsl:if test="position()>1">
178               <xsl:text>, </xsl:text>
179             </xsl:if>
180             <xsl:value-of select="."/>
181           </xsl:for-each>
182           <xsl:if test="not (position() = last())">
183             <xsl:text> • </xsl:text>
184           </xsl:if>
185         </xsl:for-each>
186       </span>
187     </xsl:if>
188   </xsl:template>
189
190   <xsl:template name="tag_210">
191     <span class="results_summary publication">
192       <span class="label">Publication: </span>
193       <xsl:for-each select="marc:datafield[@tag=210]">
194         <span>
195           <xsl:call-template name="addClassRtl" />
196           <xsl:for-each select="marc:subfield">
197             <xsl:choose>
198               <xsl:when test="@code='c' or @code='g'">
199                 <xsl:if test="position()>1">
200                   <xsl:text> : </xsl:text>
201                 </xsl:if>
202                 <xsl:value-of select="."/>
203               </xsl:when>
204               <xsl:otherwise>
205                 <xsl:if test="position()>1">
206                   <xsl:text>, </xsl:text>
207                 </xsl:if>
208                 <xsl:value-of select="."/>
209               </xsl:otherwise>
210             </xsl:choose>
211           </xsl:for-each>
212           <xsl:if test="not (position() = last())">
213             <xsl:text> • </xsl:text>
214           </xsl:if>
215         </span>
216       </xsl:for-each>
217     </span>
218   </xsl:template>
219
220   <xsl:template name="tag_215">
221     <xsl:for-each select="marc:datafield[@tag=215]">
222           <span class="results_summary description">
223         <span class="label">Description: </span>
224         <xsl:if test="marc:subfield[@code='a']">
225           <xsl:value-of select="marc:subfield[@code='a']"/>
226         </xsl:if>
227         <xsl:if test="marc:subfield[@code='c']"> :
228           <xsl:value-of select="marc:subfield[@code='c']"/>
229         </xsl:if>
230         <xsl:if test="marc:subfield[@code='d']"> ;
231           <xsl:value-of select="marc:subfield[@code='d']"/>
232         </xsl:if>
233         <xsl:if test="marc:subfield[@code='e']"> +
234           <xsl:value-of select="marc:subfield[@code='e']"/>
235         </xsl:if>
236       </span>
237     </xsl:for-each>
238   </xsl:template>
239
240   <xsl:template name="tag_onesubject">
241     <xsl:choose>
242       <xsl:when test="marc:subfield[@code=9]">
243         <xsl:for-each select="marc:subfield">
244           <xsl:if test="@code='9'">
245             <xsl:variable name="start" select="position()"/>
246             <xsl:variable name="ends">
247               <xsl:for-each select="../marc:subfield[position() &gt; $start]">
248                 <xsl:if test="@code=9">
249                   <xsl:variable name="end" select="position() + $start"/>
250                   <xsl:value-of select="$end"/>
251                   <xsl:text>,</xsl:text>
252                 </xsl:if>
253               </xsl:for-each>
254             </xsl:variable>
255             <xsl:variable name="end">
256               <xsl:choose>
257                 <xsl:when test="string-length($ends) > 0">
258                   <xsl:value-of select="substring-before($ends,',')"/>
259                 </xsl:when>
260                 <xsl:otherwise>
261                   <xsl:text>1000</xsl:text>
262                 </xsl:otherwise>
263               </xsl:choose>
264             </xsl:variable>
265             <xsl:variable name="display">
266               <xsl:for-each select="../marc:subfield[position() &gt; $start and position() &lt; $end and @code!=2 and @code!=3]">
267                 <xsl:value-of select="."/>
268                 <xsl:if test="not(position()=last())">
269                   <xsl:text>, </xsl:text>
270                 </xsl:if>
271               </xsl:for-each>
272             </xsl:variable>
273             <a>
274               <xsl:attribute name="href">
275                 <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
276                 <xsl:value-of select="str:encode-uri(., true())"/>
277               </xsl:attribute>
278               <xsl:choose>
279                 <xsl:when test="string-length($display) &gt; 0">
280                   <xsl:call-template name="chopPunctuation">
281                     <xsl:with-param name="chopString">
282                       <xsl:value-of select="$display"/>
283                     </xsl:with-param>
284                   </xsl:call-template>
285                 </xsl:when>
286                 <xsl:otherwise>
287                   <xsl:value-of select="."/>
288                 </xsl:otherwise>
289               </xsl:choose>
290             </a>
291             <xsl:variable name="ncommas"
292                  select="string-length($ends) - string-length(translate($ends, ',', ''))" />
293             <xsl:if test="$ncommas &gt; 1">
294               <xsl:text> -- </xsl:text>
295             </xsl:if>
296           </xsl:if>
297         </xsl:for-each>
298       </xsl:when>
299       <xsl:when test="marc:subfield[@code='a']">
300         <a>
301           <xsl:attribute name="href">
302             <xsl:text>/cgi-bin/koha/opac-search.pl?q=su:</xsl:text>
303             <xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
304           </xsl:attribute>
305           <xsl:call-template name="chopPunctuation">
306             <xsl:with-param name="chopString">
307               <xsl:call-template name="subfieldSelect">
308                 <xsl:with-param name="codes">abcdfijkmnpvxyz</xsl:with-param>
309                 <xsl:with-param name="subdivCodes">ijknpxyz</xsl:with-param>
310                 <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
311               </xsl:call-template>
312             </xsl:with-param>
313           </xsl:call-template>
314         </a>
315       </xsl:when>
316       <xsl:otherwise/>
317     </xsl:choose>
318     <xsl:if test="not(position()=last())">
319       <xsl:text> | </xsl:text>
320     </xsl:if>
321   </xsl:template>
322
323   <xsl:template name="tag_subject">
324     <xsl:param name="tag" />
325     <xsl:param name="label" />
326     <xsl:param name="spanclass" />
327     <xsl:if test="marc:datafield[@tag=$tag]">
328       <span class="results_summary subjects {$spanclass}">
329         <span class="label">
330           <xsl:value-of select="$label"/>
331           <xsl:text>: </xsl:text>
332         </span>
333         <span class="value">
334           <xsl:for-each select="marc:datafield[@tag=$tag]">
335             <xsl:call-template name="tag_onesubject">
336             </xsl:call-template>
337           </xsl:for-each>
338         </span>
339       </span>
340     </xsl:if>
341   </xsl:template>
342
343   <xsl:template name="tag_7xx">
344     <xsl:param name="tag" />
345     <xsl:param name="label" />
346     <xsl:param name="spanclass" />
347     <xsl:variable name="IdRef" select="marc:sysprefs/marc:syspref[@name='IdRef']"/>
348     <xsl:if test="marc:datafield[@tag=$tag]">
349       <span class="results_summary author {$spanclass}">
350         <span class="label">
351           <xsl:value-of select="$label" />
352           <xsl:text>: </xsl:text>
353         </span>
354         <span class="value">
355           <xsl:for-each select="marc:datafield[@tag=$tag]">
356             <a>
357               <xsl:choose>
358                 <xsl:when test="marc:subfield[@code=9]">
359                   <xsl:attribute name="href">
360                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
361                     <xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
362                   </xsl:attribute>
363                 </xsl:when>
364                 <xsl:otherwise>
365                   <xsl:attribute name="href">
366                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=au:</xsl:text>
367                     <xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
368                     <xsl:text>%20</xsl:text>
369                     <xsl:value-of select="str:encode-uri(marc:subfield[@code='b'], true())"/>
370                   </xsl:attribute>
371                 </xsl:otherwise>
372               </xsl:choose>
373               <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']">
374                 <xsl:choose>
375                   <xsl:when test="@code='9'">
376                   </xsl:when>
377                   <xsl:otherwise>
378                     <xsl:value-of select="."/>
379                   </xsl:otherwise>
380                 </xsl:choose>
381                 <xsl:if test="not(position() = last())">
382                   <xsl:text>, </xsl:text>
383                 </xsl:if>
384               </xsl:for-each>
385             </a>
386             <xsl:if test="$IdRef">
387               <xsl:if test="marc:subfield[@code=3]">
388                 <xsl:text> </xsl:text>
389                 <a>
390                   <xsl:attribute name="href">
391                     <xsl:text>/cgi-bin/koha/opac-idref.pl?unimarc3=</xsl:text>
392                     <xsl:value-of select="str:encode-uri(marc:subfield[@code=3], true())"/>
393                   </xsl:attribute>
394                   <xsl:attribute name="title">IdRef</xsl:attribute>
395                   <xsl:attribute name="rel">gb_page_center[600,500]</xsl:attribute>
396                   <xsl:text>Idref</xsl:text>
397                 </a>
398               </xsl:if>
399             </xsl:if>
400             <xsl:if test="not(position() = last())">
401               <span style="padding: 3px;">
402                 <xsl:text>;</xsl:text>
403               </span>
404             </xsl:if>
405           </xsl:for-each>
406         </span>
407       </span>
408     </xsl:if>
409   </xsl:template>
410
411 </xsl:stylesheet>