Bug 12725: Show RDA tag 264 on Intranet Results and Detail XSLT view (MARC21)
[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" 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="chopPunctuation">
76                 <xsl:param name="chopString"/>
77                 <xsl:variable name="length" select="string-length($chopString)"/>
78                 <xsl:choose>
79                         <xsl:when test="$length=0"/>
80                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
81                                 <xsl:call-template name="chopPunctuation">
82                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
83                                 </xsl:call-template>
84                         </xsl:when>
85                         <xsl:when test="not($chopString)"/>
86                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
87                 </xsl:choose>
88         </xsl:template>
89
90         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
91              Parameter: control number string.
92              Assumes LOC convention: (OrgCode)recordNumber.
93              If OrgCode is not present, return full string.
94              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
95         -->
96         <xsl:template name="extractControlNumber">
97             <xsl:param name="subfieldW"/>
98             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
99             <xsl:choose>
100               <xsl:when test="contains($tranW,')')">
101                 <xsl:value-of select="normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;',''))"/>
102               </xsl:when>
103               <xsl:otherwise>
104                 <xsl:value-of select="normalize-space($subfieldW)"/>
105               </xsl:otherwise>
106             </xsl:choose>
107         </xsl:template>
108
109     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
110         - should be called immediately before the corresonding latin tags are processed 
111         - tags in right-to-left languages are displayed floating right
112         * Parameter:
113            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
114            + codes: display these subfields codes
115         * Options: 
116             - class: wrap output in <span class="$class">...</span>
117             - label: prefix each(!) tag with label $label
118             - bibno: link to biblionumber $bibno
119             - 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.
120          * Limitations:
121             - displays every field on a separate line (to switch between rtl and ltr)
122          * Pitfalls:
123            (!) output might be empty
124     --> 
125     <xsl:template name="m880Select">
126          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
127         <xsl:param name="codes"/> <!-- e.g. abc  -->
128         <xsl:param name="class"/> <!-- e.g. results_summary -->
129         <xsl:param name="label"/> <!-- e.g.  Edition -->
130         <xsl:param name="bibno"/>
131         <xsl:param name="index"/> <!-- e.g.  au -->
132         <xsl:param name="UseAuthoritiesForTracings"/>
133
134         <xsl:for-each select="marc:datafield[@tag=880]">
135             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
136             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
137                 <span>
138                     <xsl:choose>
139                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
140                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
141                         <xsl:attribute name="dir">rtl</xsl:attribute>
142                     </xsl:when>
143                      <xsl:when test="boolean($class)">
144                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
145                         <xsl:attribute name="style">display:block; </xsl:attribute>
146                     </xsl:when>    
147                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
148                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
149                     </xsl:when>                                    
150                     </xsl:choose>
151                     <xsl:if test="boolean($label)">
152                         <span class="label">
153                             <xsl:value-of select="$label"/>
154                         </span>
155                     </xsl:if>
156                     <xsl:variable name="str">
157                         <xsl:for-each select="marc:subfield">
158                             <xsl:if test="contains($codes, @code)">
159                                 <xsl:value-of select="text()"/>
160                                 <xsl:text> </xsl:text>
161                             </xsl:if>
162                         </xsl:for-each>
163                     </xsl:variable>
164                     <xsl:choose>
165                         <xsl:when test="boolean($bibno)">
166                             <a>
167                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/detail.pl?biblionumber=<xsl:value-of  select="$bibno"/></xsl:attribute>
168                                 <xsl:value-of select="$str"/>
169                             </a>
170                         </xsl:when>
171                        <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9]) and $UseAuthoritiesForTracings='1'">
172                             <a>
173                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=an:<xsl:value-of  select="marc:subfield[@code=9]"/></xsl:attribute>
174                                   <xsl:value-of select="$str"/>
175                             </a>
176                         </xsl:when>
177                         <xsl:when test="boolean($index)">
178                             <a>
179                                 <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>
180                                 <xsl:value-of select="$str"/>
181                             </a>
182                         </xsl:when>
183                         <xsl:otherwise>
184                             <xsl:value-of select="$str"/>
185                         </xsl:otherwise>
186                     </xsl:choose>
187                 </span>
188             </xsl:if>
189         </xsl:for-each>
190     </xsl:template>
191
192     <xsl:template name="showRDAtag264">
193     <!-- Function showRDAtag264 shows selected information from tag 264
194          on the Publisher line (used by OPAC Detail and Results)
195          Depending on how many tags you have, we will pick by preference
196          Publisher-latest or Publisher or 'Other'-latest or 'Other'
197          The preferred tag is saved in the fav variable and passed to a
198          helper named-template -->
199         <xsl:choose>
200             <xsl:when test="marc:datafield[@tag=264 and @ind1=3 and @ind2=1]">
201             <!-- ind1==3 means latest change -->
202             <!-- ind2==1 means Publisher -->
203               <xsl:variable name="fav" select="marc:datafield[@tag=264 and @ind1=3 and @ind2=1][1]"/>
204               <xsl:call-template name="showRDAtag264helper">
205                 <xsl:with-param name="field" select="$fav"/>
206               </xsl:call-template>
207             </xsl:when>
208
209             <xsl:when test="marc:datafield[@tag=264 and @ind2=1]">
210               <xsl:variable name="fav" select="marc:datafield[@tag=264 and @ind2=1][last()]"/>
211               <xsl:call-template name="showRDAtag264helper">
212                 <xsl:with-param name="field" select="$fav"/>
213               </xsl:call-template>
214             </xsl:when>
215
216             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
217               <xsl:variable name="fav" select="marc:datafield[@tag=264 and @ind1=3][1]"/>
218               <xsl:call-template name="showRDAtag264helper">
219                 <xsl:with-param name="field" select="$fav"/>
220               </xsl:call-template>
221             </xsl:when>
222
223             <xsl:otherwise>
224               <xsl:variable name="fav" select="marc:datafield[@tag=264][last()]"/>
225               <xsl:call-template name="showRDAtag264helper">
226                 <xsl:with-param name="field" select="$fav"/>
227               </xsl:call-template>
228             </xsl:otherwise>
229         </xsl:choose>
230     </xsl:template>
231     <xsl:template name="showRDAtag264helper">
232         <xsl:param name="field"/>
233         <xsl:variable name="ind2" select="$field/@ind2"/>
234         <xsl:choose>
235             <xsl:when test="$ind2='0'">
236                 <span class="label">Producer: </span>
237             </xsl:when>
238             <xsl:when test="$ind2='1'">
239                 <span class="label">Publisher: </span>
240             </xsl:when>
241             <xsl:when test="$ind2='2'">
242                 <span class="label">Distributor: </span>
243             </xsl:when>
244             <xsl:when test="$ind2='3'">
245                 <span class="label">Manufacturer: </span>
246             </xsl:when>
247         </xsl:choose>
248         <xsl:value-of select="$field/marc:subfield[@code='a']"/>
249         <xsl:text> </xsl:text>
250         <xsl:value-of select="$field/marc:subfield[@code='b']"/>
251         <xsl:text> </xsl:text>
252         <xsl:value-of select="$field/marc:subfield[@code='c']"/>
253     </xsl:template>
254
255 </xsl:stylesheet>
256
257 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
258 <metaInformation>
259 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
260 </metaInformation>
261 -->