bb5a254044492fa243066c4e9dfa281f31ffbb7b
[koha.git] / koha-tmpl / intranet-tmpl / prog / 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">
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="IntranetBiblioDefaultView"/>
89         <xsl:choose>
90             <xsl:when test="$IntranetBiblioDefaultView='normal'">
91                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
92             </xsl:when>
93             <xsl:when test="$IntranetBiblioDefaultView='isbd'">
94                 <xsl:text>/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=</xsl:text>
95             </xsl:when>
96             <xsl:when test="$IntranetBiblioDefaultView='labeled_marc'">
97                 <xsl:text>/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=</xsl:text>
98             </xsl:when>
99             <xsl:when test="$IntranetBiblioDefaultView='marc'">
100                 <xsl:text>/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=</xsl:text>
101             </xsl:when>
102             <xsl:otherwise>
103                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
104             </xsl:otherwise>
105         </xsl:choose>
106     </xsl:template>
107
108         <xsl:template name="chopPunctuation">
109                 <xsl:param name="chopString"/>
110                 <xsl:variable name="length" select="string-length($chopString)"/>
111                 <xsl:choose>
112                         <xsl:when test="$length=0"/>
113                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
114                                 <xsl:call-template name="chopPunctuation">
115                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
116                                 </xsl:call-template>
117                         </xsl:when>
118                         <xsl:when test="not($chopString)"/>
119                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
120                 </xsl:choose>
121         </xsl:template>
122
123         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
124              Parameter: control number string.
125              Assumes LOC convention: (OrgCode)recordNumber.
126              If OrgCode is not present, return full string.
127              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
128          Returns the value URI-encoded.
129         -->
130         <xsl:template name="extractControlNumber">
131             <xsl:param name="subfieldW"/>
132             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
133             <xsl:choose>
134               <xsl:when test="contains($tranW,')')">
135                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
136               </xsl:when>
137               <xsl:otherwise>
138                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
139               </xsl:otherwise>
140             </xsl:choose>
141         </xsl:template>
142
143     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
144         - should be called immediately before the corresonding latin tags are processed 
145         - tags in right-to-left languages are displayed floating right
146         * Parameter:
147            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
148            + codes: display these subfields codes
149         * Options: 
150             - class: wrap output in <span class="$class">...</span>
151             - label: prefix each(!) tag with label $label
152             - bibno: link to biblionumber $bibno
153             - 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.
154          * Limitations:
155             - displays every field on a separate line (to switch between rtl and ltr)
156          * Pitfalls:
157            (!) output might be empty
158     --> 
159     <xsl:template name="m880Select">
160          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
161         <xsl:param name="codes"/> <!-- e.g. abc  -->
162         <xsl:param name="class"/> <!-- e.g. results_summary -->
163         <xsl:param name="label"/> <!-- e.g.  Edition -->
164         <xsl:param name="bibno"/>
165         <xsl:param name="index"/> <!-- e.g.  au -->
166         <xsl:param name="UseAuthoritiesForTracings"/>
167
168         <xsl:for-each select="marc:datafield[@tag=880]">
169             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
170             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
171                 <span>
172                     <xsl:choose>
173                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
174                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
175                         <xsl:attribute name="dir">rtl</xsl:attribute>
176                     </xsl:when>
177                      <xsl:when test="boolean($class)">
178                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
179                         <xsl:attribute name="style">display:block; </xsl:attribute>
180                     </xsl:when>    
181                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
182                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
183                     </xsl:when>                                    
184                     </xsl:choose>
185                     <xsl:if test="boolean($label)">
186                         <span class="label">
187                             <xsl:value-of select="$label"/>
188                         </span>
189                     </xsl:if>
190                     <xsl:variable name="str">
191                         <xsl:for-each select="marc:subfield">
192                             <xsl:if test="contains($codes, @code)">
193                                 <xsl:value-of select="text()"/>
194                                 <xsl:text> </xsl:text>
195                             </xsl:if>
196                         </xsl:for-each>
197                     </xsl:variable>
198                     <xsl:choose>
199                         <xsl:when test="boolean($bibno)">
200                             <a>
201                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
202                                 <xsl:value-of select="$str"/>
203                             </a>
204                         </xsl:when>
205                        <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9]) and $UseAuthoritiesForTracings='1'">
206                             <a>
207                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=an:<xsl:value-of  select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
208                                   <xsl:value-of select="$str"/>
209                             </a>
210                         </xsl:when>
211                         <xsl:when test="boolean($index)">
212                             <a>
213                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/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>
214                                 <xsl:value-of select="$str"/>
215                             </a>
216                         </xsl:when>
217                         <xsl:otherwise>
218                             <xsl:value-of select="$str"/>
219                         </xsl:otherwise>
220                     </xsl:choose>
221                 </span>
222             </xsl:if>
223         </xsl:for-each>
224     </xsl:template>
225
226     <xsl:template name="showRDAtag264">
227     <!-- Function showRDAtag264 shows selected information from tag 264
228          on the Publisher line (used by OPAC Detail and Results)
229          Depending on how many tags you have, we will pick by preference
230          Publisher-latest or Publisher or 'Other'-latest or 'Other'
231          The preferred tag is saved in the fav variable and passed to a
232          helper named-template -->
233     <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
234         <xsl:param name="show_url"/>
235         <xsl:choose>
236             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
237                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
238                     <xsl:call-template name="showRDAtag264helper">
239                         <xsl:with-param name="field" select="."/>
240                         <xsl:with-param name="url" select="$show_url"/>
241                     </xsl:call-template>
242                 </xsl:for-each>
243             </xsl:when>
244             <xsl:otherwise>
245                 <xsl:for-each select="marc:datafield[@tag=264]">
246                     <xsl:call-template name="showRDAtag264helper">
247                         <xsl:with-param name="field" select="."/>
248                         <xsl:with-param name="url" select="$show_url"/>
249                     </xsl:call-template>
250                 </xsl:for-each>
251             </xsl:otherwise>
252         </xsl:choose>
253     </xsl:template>
254     <xsl:template name="showRDAtag264helper">
255         <xsl:param name="field"/>
256         <xsl:param name="url"/>
257         <xsl:variable name="ind2" select="$field/@ind2"/>
258         <span class="results_summary">
259             <xsl:choose>
260                 <xsl:when test="$ind2='0'">
261                     <span class="label">Producer: </span>
262                 </xsl:when>
263                 <xsl:when test="$ind2='1'">
264                     <span class="label">Publisher: </span>
265                 </xsl:when>
266                 <xsl:when test="$ind2='2'">
267                     <span class="label">Distributor: </span>
268                 </xsl:when>
269                 <xsl:when test="$ind2='3'">
270                     <span class="label">Manufacturer: </span>
271                 </xsl:when>
272                 <xsl:when test="$ind2='4'">
273                     <span class="label">Copyright date: </span>
274                 </xsl:when>
275             </xsl:choose>
276
277             <xsl:if test="$field/marc:subfield[@code='a']">
278                 <xsl:call-template name="subfieldSelect">
279                     <xsl:with-param name="codes">a</xsl:with-param>
280                 </xsl:call-template>
281             </xsl:if>
282             <xsl:text> </xsl:text>
283
284             <xsl:choose>
285                 <xsl:when test="$url='1'">
286                     <xsl:if test="$field/marc:subfield[@code='b']">
287                          <a>
288                          <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Provider:<xsl:value-of select="str:encode-uri($field/marc:subfield[@code='b'], true())"/></xsl:attribute>
289                          <xsl:call-template name="subfieldSelect">
290                              <xsl:with-param name="codes">b</xsl:with-param>
291                          </xsl:call-template>
292                          </a>
293                     </xsl:if>
294                 </xsl:when>
295                 <xsl:otherwise>
296                     <xsl:if test="$field/marc:subfield[@code='b']">
297                         <xsl:call-template name="subfieldSelect">
298                             <xsl:with-param name="codes">b</xsl:with-param>
299                         </xsl:call-template>
300                     </xsl:if>
301                 </xsl:otherwise>
302             </xsl:choose>
303             <xsl:text> </xsl:text>
304             <xsl:call-template name="chopPunctuation">
305                 <xsl:with-param name="chopString">
306                     <xsl:call-template name="subfieldSelect">
307                         <xsl:with-param name="codes">c</xsl:with-param>
308                     </xsl:call-template>
309                 </xsl:with-param>
310             </xsl:call-template>
311
312         </span>
313     </xsl:template>
314
315     <xsl:template name="showISBNISSN">
316       <xsl:call-template name="showSingleSubfield">
317         <xsl:with-param name="tag">020</xsl:with-param>
318         <xsl:with-param name="code">a</xsl:with-param>
319         <xsl:with-param name="class">isbn</xsl:with-param>
320         <xsl:with-param name="label">ISBN: </xsl:with-param>
321       </xsl:call-template>
322       <xsl:call-template name="showSingleSubfield">
323         <xsl:with-param name="tag">022</xsl:with-param>
324         <xsl:with-param name="code">a</xsl:with-param>
325         <xsl:with-param name="class">issn</xsl:with-param>
326         <xsl:with-param name="label">ISSN: </xsl:with-param>
327       </xsl:call-template>
328     </xsl:template>
329
330     <xsl:template name="showSingleSubfield">
331       <xsl:param name="tag"/>
332       <xsl:param name="code"/>
333       <xsl:param name="class"/>
334       <xsl:param name="label"/>
335       <xsl:if test="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
336         <span><xsl:attribute name="class"><xsl:value-of select="concat('results_summary ', $class)"/></xsl:attribute>
337         <span class="label"><xsl:value-of select="$label"/></span>
338             <xsl:for-each select="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
339               <span><xsl:attribute name="property"><xsl:value-of select="$class"/></xsl:attribute>
340                 <xsl:value-of select="."/>
341                 <xsl:choose>
342                   <xsl:when test="position()=last()">
343                     <xsl:text>.</xsl:text>
344                   </xsl:when>
345                   <xsl:otherwise>
346                     <xsl:text>; </xsl:text>
347                   </xsl:otherwise>
348                 </xsl:choose>
349               </span>
350             </xsl:for-each>
351           </span>
352         </xsl:if>
353     </xsl:template>
354
355 </xsl:stylesheet>
356
357 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
358 <metaInformation>
359 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
360 </metaInformation>
361 -->