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