Bug 14304: RDA: Intranet display link in XSLT for 264 field to reflect Zebra indexing
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / xslt / MARC21slimUtils.xsl
blob192107b280d91c69af877ad5283d506626d6640d
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" exclude-result-prefixes="marc">
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>
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>
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>
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>
75 <xsl:template name="buildBiblioDefaultViewURL">
76 <xsl:param name="IntranetBiblioDefaultView"/>
77 <xsl:choose>
78 <xsl:when test="$IntranetBiblioDefaultView='normal'">
79 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
80 </xsl:when>
81 <xsl:when test="$IntranetBiblioDefaultView='isbd'">
82 <xsl:text>/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=</xsl:text>
83 </xsl:when>
84 <xsl:when test="$IntranetBiblioDefaultView='labeled_marc'">
85 <xsl:text>/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=</xsl:text>
86 </xsl:when>
87 <xsl:when test="$IntranetBiblioDefaultView='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>
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>
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.
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>
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 <xsl:param name="UseAuthoritiesForTracings"/>
155 <xsl:for-each select="marc:datafield[@tag=880]">
156 <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
157 <xsl:if test="contains(string($basetags), substring($code6,1,3))">
158 <span>
159 <xsl:choose>
160 <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
161 <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
162 <xsl:attribute name="dir">rtl</xsl:attribute>
163 </xsl:when>
164 <xsl:when test="boolean($class)">
165 <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
166 <xsl:attribute name="style">display:block; </xsl:attribute>
167 </xsl:when>
168 <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
169 <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
170 </xsl:when>
171 </xsl:choose>
172 <xsl:if test="boolean($label)">
173 <span class="label">
174 <xsl:value-of select="$label"/>
175 </span>
176 </xsl:if>
177 <xsl:variable name="str">
178 <xsl:for-each select="marc:subfield">
179 <xsl:if test="contains($codes, @code)">
180 <xsl:value-of select="text()"/>
181 <xsl:text> </xsl:text>
182 </xsl:if>
183 </xsl:for-each>
184 </xsl:variable>
185 <xsl:choose>
186 <xsl:when test="boolean($bibno)">
188 <xsl:attribute name="href">/cgi-bin/koha/catalogue/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]) and $UseAuthoritiesForTracings='1'">
194 <xsl:attribute name="href">/cgi-bin/koha/catalogue/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)">
200 <xsl:attribute name="href">/cgi-bin/koha/catalogue/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 </span>
209 </xsl:if>
210 </xsl:for-each>
211 </xsl:template>
213 <xsl:template name="showRDAtag264">
214 <!-- Function showRDAtag264 shows selected information from tag 264
215 on the Publisher line (used by OPAC Detail and Results)
216 Depending on how many tags you have, we will pick by preference
217 Publisher-latest or Publisher or 'Other'-latest or 'Other'
218 The preferred tag is saved in the fav variable and passed to a
219 helper named-template -->
220 <!-- Amended to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record) -->
221 <xsl:param name="show_url"/>
222 <xsl:choose>
223 <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
224 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
225 <xsl:call-template name="showRDAtag264helper">
226 <xsl:with-param name="field" select="."/>
227 <xsl:with-param name="url" select="$show_url"/>
228 </xsl:call-template>
229 </xsl:for-each>
230 </xsl:when>
231 <xsl:otherwise>
232 <xsl:for-each select="marc:datafield[@tag=264]">
233 <xsl:call-template name="showRDAtag264helper">
234 <xsl:with-param name="field" select="."/>
235 <xsl:with-param name="url" select="$show_url"/>
236 </xsl:call-template>
237 </xsl:for-each>
238 </xsl:otherwise>
239 </xsl:choose>
240 </xsl:template>
241 <xsl:template name="showRDAtag264helper">
242 <xsl:param name="field"/>
243 <xsl:param name="url"/>
244 <xsl:variable name="ind2" select="$field/@ind2"/>
245 <span class="results_summary">
246 <xsl:choose>
247 <xsl:when test="$ind2='0'">
248 <span class="label">Producer: </span>
249 </xsl:when>
250 <xsl:when test="$ind2='1'">
251 <span class="label">Publisher: </span>
252 </xsl:when>
253 <xsl:when test="$ind2='2'">
254 <span class="label">Distributor: </span>
255 </xsl:when>
256 <xsl:when test="$ind2='3'">
257 <span class="label">Manufacturer: </span>
258 </xsl:when>
259 <xsl:when test="$ind2='4'">
260 <span class="label">Copyright date: </span>
261 </xsl:when>
262 </xsl:choose>
264 <xsl:if test="$field/marc:subfield[@code='a']">
265 <xsl:call-template name="subfieldSelect">
266 <xsl:with-param name="codes">a</xsl:with-param>
267 </xsl:call-template>
268 </xsl:if>
269 <xsl:text> </xsl:text>
271 <xsl:choose>
272 <xsl:when test="$url='1'">
273 <xsl:if test="$field/marc:subfield[@code='b']">
274 <a href="/cgi-bin/koha/catalogue/search.pl?q=Provider:{$field/marc:subfield[@code='b']}">
275 <xsl:call-template name="subfieldSelect">
276 <xsl:with-param name="codes">b</xsl:with-param>
277 </xsl:call-template>
278 </a>
279 </xsl:if>
280 </xsl:when>
281 <xsl:otherwise>
282 <xsl:if test="$field/marc:subfield[@code='b']">
283 <xsl:call-template name="subfieldSelect">
284 <xsl:with-param name="codes">b</xsl:with-param>
285 </xsl:call-template>
286 </xsl:if>
287 </xsl:otherwise>
288 </xsl:choose>
289 <xsl:text> </xsl:text>
290 <xsl:call-template name="chopPunctuation">
291 <xsl:with-param name="chopString">
292 <xsl:call-template name="subfieldSelect">
293 <xsl:with-param name="codes">c</xsl:with-param>
294 </xsl:call-template>
295 </xsl:with-param>
296 </xsl:call-template>
298 </span>
299 </xsl:template>
301 </xsl:stylesheet>
303 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
304 <metaInformation>
305 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
306 </metaInformation>