Bug 15208: Followup to reorder words
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / xslt / MARC21slimUtils-MODS31.xsl
blob5a8d6cc6ef7bce081e1070e8629135513c58ccfa
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"
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6 <!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
7 <!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
8 <!-- 12/14/07: ntra added url encoding template -->
9 <!-- url encoding -->
11 <xsl:variable name="ascii">
12 <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
13 </xsl:variable>
15 <xsl:variable name="latin1">
16 <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
17 </xsl:variable>
18 <!-- Characters that usually don't need to be escaped -->
19 <xsl:variable name="safe">
20 <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
21 </xsl:variable>
23 <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
26 <xsl:template name="datafield">
27 <xsl:param name="tag"/>
28 <xsl:param name="ind1">
29 <xsl:text> </xsl:text>
30 </xsl:param>
31 <xsl:param name="ind2">
32 <xsl:text> </xsl:text>
33 </xsl:param>
34 <xsl:param name="subfields"/>
35 <xsl:element name="marc:datafield">
36 <xsl:attribute name="tag">
37 <xsl:value-of select="$tag"/>
38 </xsl:attribute>
39 <xsl:attribute name="ind1">
40 <xsl:value-of select="$ind1"/>
41 </xsl:attribute>
42 <xsl:attribute name="ind2">
43 <xsl:value-of select="$ind2"/>
44 </xsl:attribute>
45 <xsl:copy-of select="$subfields"/>
46 </xsl:element>
47 </xsl:template>
49 <xsl:template name="subfieldSelect">
50 <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
51 <xsl:param name="delimeter">
52 <xsl:text> </xsl:text>
53 </xsl:param>
54 <xsl:variable name="str">
55 <xsl:for-each select="marc:subfield">
56 <xsl:if test="contains($codes, @code)">
57 <xsl:value-of select="text()"/>
58 <xsl:value-of select="$delimeter"/>
59 </xsl:if>
60 </xsl:for-each>
61 </xsl:variable>
62 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
63 </xsl:template>
65 <xsl:template name="buildSpaces">
66 <xsl:param name="spaces"/>
67 <xsl:param name="char">
68 <xsl:text> </xsl:text>
69 </xsl:param>
70 <xsl:if test="$spaces>0">
71 <xsl:value-of select="$char"/>
72 <xsl:call-template name="buildSpaces">
73 <xsl:with-param name="spaces" select="$spaces - 1"/>
74 <xsl:with-param name="char" select="$char"/>
75 </xsl:call-template>
76 </xsl:if>
77 </xsl:template>
79 <xsl:template name="chopPunctuation">
80 <xsl:param name="chopString"/>
81 <xsl:param name="punctuation">
82 <xsl:text>.:,;/ </xsl:text>
83 </xsl:param>
84 <xsl:variable name="length" select="string-length($chopString)"/>
85 <xsl:choose>
86 <xsl:when test="$length=0"/>
87 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
88 <xsl:call-template name="chopPunctuation">
89 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
90 <xsl:with-param name="punctuation" select="$punctuation"/>
91 </xsl:call-template>
92 </xsl:when>
93 <xsl:when test="not($chopString)"/>
94 <xsl:otherwise>
95 <xsl:value-of select="$chopString"/>
96 </xsl:otherwise>
97 </xsl:choose>
98 </xsl:template>
100 <xsl:template name="chopPunctuationFront">
101 <xsl:param name="chopString"/>
102 <xsl:variable name="length" select="string-length($chopString)"/>
103 <xsl:choose>
104 <xsl:when test="$length=0"/>
105 <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
106 <xsl:call-template name="chopPunctuationFront">
107 <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
109 </xsl:call-template>
110 </xsl:when>
111 <xsl:when test="not($chopString)"/>
112 <xsl:otherwise>
113 <xsl:value-of select="$chopString"/>
114 </xsl:otherwise>
115 </xsl:choose>
116 </xsl:template>
118 <xsl:template name="chopPunctuationBack">
119 <xsl:param name="chopString"/>
120 <xsl:param name="punctuation">
121 <xsl:text>.:,;/] </xsl:text>
122 </xsl:param>
123 <xsl:variable name="length" select="string-length($chopString)"/>
124 <xsl:choose>
125 <xsl:when test="$length=0"/>
126 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
127 <xsl:call-template name="chopPunctuation">
128 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
129 <xsl:with-param name="punctuation" select="$punctuation"/>
130 </xsl:call-template>
131 </xsl:when>
132 <xsl:when test="not($chopString)"/>
133 <xsl:otherwise>
134 <xsl:value-of select="$chopString"/>
135 </xsl:otherwise>
136 </xsl:choose>
137 </xsl:template>
139 <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
140 <xsl:template name="url-encode">
142 <xsl:param name="str"/>
144 <xsl:if test="$str">
145 <xsl:variable name="first-char" select="substring($str,1,1)"/>
146 <xsl:choose>
147 <xsl:when test="contains($safe,$first-char)">
148 <xsl:value-of select="$first-char"/>
149 </xsl:when>
150 <xsl:otherwise>
151 <xsl:variable name="codepoint">
152 <xsl:choose>
153 <xsl:when test="contains($ascii,$first-char)">
154 <xsl:value-of
155 select="string-length(substring-before($ascii,$first-char)) + 32"
157 </xsl:when>
158 <xsl:when test="contains($latin1,$first-char)">
159 <xsl:value-of
160 select="string-length(substring-before($latin1,$first-char)) + 160"/>
161 <!-- was 160 -->
162 </xsl:when>
163 <xsl:otherwise>
164 <xsl:message terminate="no">Warning: string contains a character
165 that is out of range! Substituting "?".</xsl:message>
166 <xsl:text>63</xsl:text>
167 </xsl:otherwise>
168 </xsl:choose>
169 </xsl:variable>
170 <xsl:variable name="hex-digit1"
171 select="substring($hex,floor($codepoint div 16) + 1,1)"/>
172 <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
173 <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
174 <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
175 </xsl:otherwise>
176 </xsl:choose>
177 <xsl:if test="string-length($str) &gt; 1">
178 <xsl:call-template name="url-encode">
179 <xsl:with-param name="str" select="substring($str,2)"/>
180 </xsl:call-template>
181 </xsl:if>
182 </xsl:if>
183 </xsl:template>
184 </xsl:stylesheet>
185 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
186 <metaInformation>
187 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
188 </metaInformation>