Bug 14716: Fix more unencoded url parameters.
[koha-ffzg.git] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / MARC21slimUtils.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE stylesheet [<!ENTITY nbsp "&#160;" >]>
3 <xsl:stylesheet version="1.0"
4   xmlns:marc="http://www.loc.gov/MARC21/slim"
5   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6   xmlns:str="http://exslt.org/strings"
7   exclude-result-prefixes="marc str">
8         <xsl:template name="datafield">
9                 <xsl:param name="tag"/>
10                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
11                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
12                 <xsl:param name="subfields"/>
13                 <xsl:element name="datafield">
14                         <xsl:attribute name="tag">
15                                 <xsl:value-of select="$tag"/>
16                         </xsl:attribute>
17                         <xsl:attribute name="ind1">
18                                 <xsl:value-of select="$ind1"/>
19                         </xsl:attribute>
20                         <xsl:attribute name="ind2">
21                                 <xsl:value-of select="$ind2"/>
22                         </xsl:attribute>
23                         <xsl:copy-of select="$subfields"/>
24                 </xsl:element>
25         </xsl:template>
26
27         <xsl:template name="subfieldSelect">
28                 <xsl:param name="codes"/>
29                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
30                 <xsl:param name="subdivCodes"/>
31                 <xsl:param name="subdivDelimiter"/>
32         <xsl:param name="prefix"/>
33         <xsl:param name="suffix"/>
34         <xsl:param name="urlencode"/>
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="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:value-of select="$delimeter"/>
42                                 </xsl:if>
43                         </xsl:for-each>
44                 </xsl:variable>
45         <xsl:choose>
46             <xsl:when test="$urlencode=1">
47                 <xsl:value-of select="str:encode-uri(substring($str,1,string-length($str)-string-length($delimeter)), true())"/>
48             </xsl:when>
49             <xsl:otherwise>
50                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
51             </xsl:otherwise>
52         </xsl:choose>
53         </xsl:template>
54
55     <xsl:template name="subfieldSelectSpan">
56         <xsl:param name="codes"/>
57         <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
58         <xsl:param name="subdivCodes"/>
59         <xsl:param name="subdivDelimiter"/>
60         <xsl:param name="prefix"/>
61         <xsl:param name="suffix"/>
62             <xsl:for-each select="marc:subfield">
63                 <xsl:if test="contains($codes, @code)">
64                     <span>
65                         <xsl:attribute name="class"><xsl:value-of select="@code"/></xsl:attribute>
66                         <xsl:if test="contains($subdivCodes, @code)">
67                             <xsl:value-of select="$subdivDelimiter"/>
68                         </xsl:if>
69                         <xsl:value-of select="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:if test="position()!=last()"><xsl:value-of select="$delimeter"/></xsl:if>
70                     </span>
71                 </xsl:if>
72             </xsl:for-each>
73     </xsl:template>
74
75         <xsl:template name="buildSpaces">
76                 <xsl:param name="spaces"/>
77                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
78                 <xsl:if test="$spaces>0">
79                         <xsl:value-of select="$char"/>
80                         <xsl:call-template name="buildSpaces">
81                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
82                                 <xsl:with-param name="char" select="$char"/>
83                         </xsl:call-template>
84                 </xsl:if>
85         </xsl:template>
86
87   <xsl:template name="buildBiblioDefaultViewURL">
88     <xsl:param name="BiblioDefaultView"/>
89     <xsl:choose>
90         <xsl:when test="$BiblioDefaultView='normal'">
91             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
92         </xsl:when>
93         <xsl:when test="$BiblioDefaultView='isbd'">
94             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
95         </xsl:when>
96         <xsl:when test="$BiblioDefaultView='marc'">
97             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
98         </xsl:when>
99         <xsl:otherwise>
100             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
101         </xsl:otherwise>
102     </xsl:choose>
103   </xsl:template>
104
105         <xsl:template name="chopPunctuation">
106                 <xsl:param name="chopString"/>
107                 <xsl:variable name="length" select="string-length($chopString)"/>
108                 <xsl:choose>
109                         <xsl:when test="$length=0"/>
110                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
111                                 <xsl:call-template name="chopPunctuation">
112                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
113                                 </xsl:call-template>
114                         </xsl:when>
115                         <xsl:when test="not($chopString)"/>
116                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
117                 </xsl:choose>
118         </xsl:template>
119
120         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
121              Parameter: control number string.
122              Assumes LOC convention: (OrgCode)recordNumber.
123              If OrgCode is not present, return full string.
124              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
125          Returns the value URI-encoded.
126         -->
127         <xsl:template name="extractControlNumber">
128             <xsl:param name="subfieldW"/>
129             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
130             <xsl:choose>
131               <xsl:when test="contains($tranW,')')">
132                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
133               </xsl:when>
134               <xsl:otherwise>
135                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
136               </xsl:otherwise>
137             </xsl:choose>
138         </xsl:template>
139
140     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
141         - should be called immediately before the corresonding latin tags are processed
142         - tags in right-to-left languages are displayed floating right
143         * Parameter:
144            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
145            + codes: display these subfields codes
146         * Options:
147             - class: wrap output in <span class="$class">...</span>
148             - label: prefix each(!) tag with label $label
149             - bibno: link to biblionumber $bibno
150             - index: build a search link using index $index with subfield $a as key; if subfield $9 is present use index 'an' with key $9 instead.
151          * Limitations:
152             - displays every field on a separate line (to switch between rtl and ltr)
153          * Pitfalls:
154            (!) output might be empty
155     -->
156     <xsl:template name="m880Select">
157          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
158         <xsl:param name="codes"/> <!-- e.g. abc  -->
159         <xsl:param name="class"/> <!-- e.g. results_summary -->
160         <xsl:param name="label"/> <!-- e.g.  Edition -->
161         <xsl:param name="bibno"/>
162         <xsl:param name="index"/> <!-- e.g.  au -->
163
164         <xsl:for-each select="marc:datafield[@tag=880]">
165             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
166             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
167                 <span>
168                     <xsl:choose>
169                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
170                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
171                         <xsl:attribute name="dir">rtl</xsl:attribute>
172                     </xsl:when>
173                      <xsl:when test="boolean($class)">
174                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
175                         <xsl:attribute name="style">display:block; </xsl:attribute>
176                     </xsl:when>
177                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
178                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
179                     </xsl:when>
180                     </xsl:choose>
181                     <xsl:if test="boolean($label)">
182                         <span class="label">
183                             <xsl:value-of select="$label"/>
184                         </span>
185                     </xsl:if>
186                     <xsl:variable name="str">
187                         <xsl:for-each select="marc:subfield">
188                             <xsl:if test="contains($codes, @code)">
189                                 <xsl:value-of select="text()"/>
190                                 <xsl:text> </xsl:text>
191                             </xsl:if>
192                         </xsl:for-each>
193                     </xsl:variable>
194                     <xsl:if test="string-length($str) &gt; 0">
195                         <xsl:choose>
196                             <xsl:when test="boolean($bibno)">
197                                 <a>
198                                     <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
199                                     <xsl:value-of select="$str"/>
200                                 </a>
201                             </xsl:when>
202                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
203                                 <a>
204                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
205                                     <xsl:value-of select="$str"/>
206                                 </a>
207                             </xsl:when>
208                             <xsl:when test="boolean($index)">
209                                 <a>
210                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of select="str:encode-uri($index, true())"/>:<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/></xsl:attribute>
211                                     <xsl:value-of select="$str"/>
212                                 </a>
213                             </xsl:when>
214                             <xsl:otherwise>
215                                 <xsl:value-of select="$str"/>
216                             </xsl:otherwise>
217                         </xsl:choose>
218                     </xsl:if>
219                 </span>
220             </xsl:if>
221         </xsl:for-each>
222     </xsl:template>
223
224     <xsl:template name="showRDAtag264">
225         <!-- Function showRDAtag264 shows selected information from tag 264
226          on the Publisher line (used by OPAC Detail and Results)
227          Depending on how many tags you have, we will pick by preference
228          Publisher-latest or Publisher or 'Other'-latest or 'Other'
229          The preferred tag is saved in the fav variable and passed to a
230          helper named-template -->
231         <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
232         <xsl:param name="show_url"/>
233         <xsl:choose>
234             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
235                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
236                     <xsl:call-template name="showRDAtag264helper">
237                         <xsl:with-param name="field" select="."/>
238                         <xsl:with-param name="url" select="$show_url"/>
239                     </xsl:call-template>
240                 </xsl:for-each>
241             </xsl:when>
242             <xsl:otherwise>
243                 <xsl:for-each select="marc:datafield[@tag=264]">
244                     <xsl:call-template name="showRDAtag264helper">
245                         <xsl:with-param name="field" select="."/>
246                         <xsl:with-param name="url" select="$show_url"/>
247                     </xsl:call-template>
248                 </xsl:for-each>
249             </xsl:otherwise>
250         </xsl:choose>
251     </xsl:template>
252     <xsl:template name="showRDAtag264helper">
253         <xsl:param name="field"/>
254         <xsl:param name="url"/>
255         <xsl:variable name="ind2" select="$field/@ind2"/>
256         <span class="results_summary">
257             <xsl:choose>
258                 <xsl:when test="$ind2='0'">
259                     <span class="label">Producer: </span>
260                 </xsl:when>
261                 <xsl:when test="$ind2='1'">
262                     <span class="label">Publisher: </span>
263                 </xsl:when>
264                 <xsl:when test="$ind2='2'">
265                     <span class="label">Distributor: </span>
266                 </xsl:when>
267                 <xsl:when test="$ind2='3'">
268                     <span class="label">Manufacturer: </span>
269                 </xsl:when>
270                 <xsl:when test="$ind2='4'">
271                     <span class="label">Copyright date: </span>
272                 </xsl:when>
273             </xsl:choose>
274
275             <xsl:if test="$field/marc:subfield[@code='a']">
276                 <xsl:call-template name="subfieldSelect">
277                     <xsl:with-param name="codes">a</xsl:with-param>
278                 </xsl:call-template>
279             </xsl:if>
280             <xsl:text> </xsl:text>
281
282             <xsl:choose>
283                 <xsl:when test="$url='1'">
284                     <xsl:if test="$field/marc:subfield[@code='b']">
285                          <a>
286                          <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=Provider:<xsl:value-of select="str:encode-uri($field/marc:subfield[@code='b'], true())"/>"</xsl:attribute>
287                          <xsl:call-template name="subfieldSelect">
288                              <xsl:with-param name="codes">b</xsl:with-param>
289                          </xsl:call-template>
290                          </a>
291                     </xsl:if>
292                 </xsl:when>
293                 <xsl:otherwise>
294                     <xsl:if test="$field/marc:subfield[@code='b']">
295                         <xsl:call-template name="subfieldSelect">
296                             <xsl:with-param name="codes">b</xsl:with-param>
297                         </xsl:call-template>
298                     </xsl:if>
299                 </xsl:otherwise>
300             </xsl:choose>
301             <xsl:text> </xsl:text>
302             <xsl:call-template name="chopPunctuation">
303                 <xsl:with-param name="chopString">
304                     <xsl:call-template name="subfieldSelect">
305                         <xsl:with-param name="codes">c</xsl:with-param>
306                     </xsl:call-template>
307                 </xsl:with-param>
308             </xsl:call-template>
309
310         </span>
311     </xsl:template>
312 </xsl:stylesheet>
313
314 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
315 <metaInformation>
316 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
317 </metaInformation>
318 -->