Bug 6147 : Correcting invalid RSS
[koha.git] / koha-tmpl / opac-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="buildSpaces">
44                 <xsl:param name="spaces"/>
45                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
46                 <xsl:if test="$spaces>0">
47                         <xsl:value-of select="$char"/>
48                         <xsl:call-template name="buildSpaces">
49                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
50                                 <xsl:with-param name="char" select="$char"/>
51                         </xsl:call-template>
52                 </xsl:if>
53         </xsl:template>
54
55         <xsl:template name="chopPunctuation">
56                 <xsl:param name="chopString"/>
57                 <xsl:variable name="length" select="string-length($chopString)"/>
58                 <xsl:choose>
59                         <xsl:when test="$length=0"/>
60                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
61                                 <xsl:call-template name="chopPunctuation">
62                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
63                                 </xsl:call-template>
64                         </xsl:when>
65                         <xsl:when test="not($chopString)"/>
66                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
67                 </xsl:choose>
68 <xsl:text> </xsl:text>
69         </xsl:template>
70
71         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
72              Parameter: control number string.
73              Assumes LOC convention: (OrgCode)recordNumber.
74              If OrgCode is not present, return full string.
75              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
76         -->
77         <xsl:template name="extractControlNumber">
78             <xsl:param name="subfieldW"/>
79             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
80             <xsl:choose>
81               <xsl:when test="contains($tranW,')')">
82                 <xsl:value-of select="normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;',''))"/>
83               </xsl:when>
84               <xsl:otherwise>
85                 <xsl:value-of select="normalize-space($subfieldW)"/>
86               </xsl:otherwise>
87             </xsl:choose>
88         </xsl:template>
89
90     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
91         - should be called immediately before the corresonding latin tags are processed 
92         - tags in right-to-left languages are displayed floating right
93         * Parameter:
94            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
95            + codes: display these subfields codes
96         * Options: 
97             - class: wrap output in <span class="$class">...</span>
98             - label: prefix each(!) tag with label $label
99             - bibno: link to biblionumber $bibno
100             - 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.
101          * Limitations:
102             - displays every field on a separate line (to switch between rtl and ltr)
103          * Pitfalls:
104            (!) output might be empty
105     -->
106     <xsl:template name="m880Select">
107          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
108         <xsl:param name="codes"/> <!-- e.g. abc  -->
109         <xsl:param name="class"/> <!-- e.g. results_summary -->
110         <xsl:param name="label"/> <!-- e.g.  Edition -->
111         <xsl:param name="bibno"/>
112         <xsl:param name="index"/> <!-- e.g.  au -->
113
114         <xsl:for-each select="marc:datafield[@tag=880]">
115             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
116             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
117                 <span>
118                     <xsl:choose>
119                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
120                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
121                         <xsl:attribute name="dir">rtl</xsl:attribute>
122                     </xsl:when>
123                      <xsl:when test="boolean($class)">
124                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
125                         <xsl:attribute name="style">display:block; </xsl:attribute>
126                     </xsl:when>    
127                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
128                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
129                     </xsl:when>                                    
130                     </xsl:choose>
131                     <xsl:if test="boolean($label)">
132                         <span class="label">
133                             <xsl:value-of select="$label"/>
134                         </span>
135                     </xsl:if>
136                     <xsl:variable name="str">
137                         <xsl:for-each select="marc:subfield">
138                             <xsl:if test="contains($codes, @code)">
139                                 <xsl:value-of select="text()"/>
140                                 <xsl:text> </xsl:text>
141                             </xsl:if>
142                         </xsl:for-each>
143                     </xsl:variable>
144                     <xsl:choose>
145                         <xsl:when test="boolean($bibno)">
146                             <a>
147                                 <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="$bibno"/></xsl:attribute>
148                                 <xsl:value-of select="$str"/>
149                             </a>
150                         </xsl:when>
151                        <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
152                             <a>
153                                 <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="marc:subfield[@code=9]"/></xsl:attribute>
154                                   <xsl:value-of select="$str"/>
155                             </a>
156                         </xsl:when>
157                         <xsl:when test="boolean($index)">
158                             <a>
159                                 <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>
160                                 <xsl:value-of select="$str"/>
161                             </a>
162                         </xsl:when>
163                         <xsl:otherwise>
164                             <xsl:value-of select="$str"/>
165                         </xsl:otherwise>
166                     </xsl:choose>
167                 </span>
168             </xsl:if>
169         </xsl:for-each>
170
171     </xsl:template>
172
173 </xsl:stylesheet>
174
175 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
176 <metaInformation>
177 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
178 </metaInformation>
179 -->