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