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