source: gsdl/trunk/etc/dc2marc.xsl@ 20857

Last change on this file since 20857 was 20857, checked in by mdewsnip, 13 years ago

Added xmlns="http://www.loc.gov/MARC21/slim" to the <collection> element, so the MARC XML files are better XML and can be opened in the Marc Edit program.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:xsltutil="xalan://org.nzdl.gsdl.ApplyXSLTUtil"
4 exclude-result-prefixes="xsltutil">
5
6 <xsl:output method="xml" indent="yes"/>
7
8 <xsl:param name="mapping" />
9
10 <xsl:template match="/">
11 <collection xmlns="http://www.loc.gov/MARC21/slim">
12 <xsl:apply-templates select="/MARCXML/MetadataList"/>
13 </collection>
14 </xsl:template>
15
16 <xsl:template match="MetadataList">
17 <xsl:variable name="lang" >
18 <xsl:choose>
19 <xsl:when test="Metadata[@name='dc.Language']">
20 <xsl:value-of select="Metadata[@name='dc.Language']"/>
21 </xsl:when>
22 <!-- comment out this if you want to test dls.Language as well
23 <xsl:when test="Metadata[@name='dls.Language']">
24 <xsl:value-of select="Metadata[@name='dls.Language']"/>
25 </xsl:when>
26 -->
27 <xsl:when test="Metadata[@name='Language']">
28 <xsl:value-of select="Metadata[@name='Language']"/>
29 </xsl:when>
30 <!-- the defualt language is english -->
31 <xsl:otherwise>
32 <xsl:value-of select="en"/>
33 </xsl:otherwise>
34 </xsl:choose>
35 </xsl:variable>
36 <xsl:variable name="item" select="$mapping/stopwords[@lang=$lang]/item"/>
37 <record xmlns="http://www.loc.gov/MARC21/slim">
38 <xsl:apply-templates select="$mapping/leader">
39 <xsl:with-param name="source" select="." />
40 </xsl:apply-templates>
41 <xsl:apply-templates select="$mapping/controlfield[@required='true']" />
42 <xsl:apply-templates select="$mapping/MarcField" >
43 <xsl:with-param name="source" select="." />
44 <xsl:with-param name="item" select="$item" />
45 </xsl:apply-templates>
46 </record>
47 </xsl:template>
48
49 <xsl:template match="leader">
50 <xsl:param name="source" />
51 <leader xmlns="http://www.loc.gov/MARC21/slim">
52 <xsl:for-each select="*">
53 <xsl:choose>
54 <xsl:when test="@pos='3' and count($source/Metadata[@name='dc.Type'])=1">
55 <xsl:apply-templates select="$mapping/recordTypeMapping/type[1]" mode="mapping-type" >
56 <xsl:with-param name="dctype" select="$source/Metadata[@name='dc.Type'][1]/text()"/>
57 </xsl:apply-templates>
58 </xsl:when>
59 <xsl:when test="@pos='3' and count($source/Metadata[@name='dc.Type'])=2
60 and $source/Metadata[@name='dc.Type' and text()='collection']">
61 <xsl:apply-templates select="$mapping/recordTypeMapping/type[1]" mode="mapping-type" >
62 <xsl:with-param name="dctype" select="$source/Metadata[@name='dc.Type' and text()!='collection']/text()"/>
63 </xsl:apply-templates>
64 </xsl:when>
65 <xsl:when test="@pos='3' and count($source/Metadata[@name='dc.Type'])=2" >
66 <xsl:apply-templates select="$mapping/recordTypeMapping/type[1]" mode="mapping-type" >
67 <xsl:with-param name="dctype" select="$source/Metadata[@name='dc.Type'][1]"/>
68 </xsl:apply-templates>
69 </xsl:when>
70 <xsl:when test="@pos='3' and count($source/Metadata[@name='dc.Type'])>2 ">
71 <xsl:value-of select="'m'"/>
72 </xsl:when>
73 <xsl:when test="@pos='4' and $source/Metadata[@name='dc.Type' and text()='collection']">
74 <xsl:value-of select="'c'"/>
75 </xsl:when>
76 <xsl:otherwise>
77 <xsl:value-of select="@value"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 </xsl:for-each>
81 </leader>
82 </xsl:template>
83
84
85 <xsl:template match="type" mode="mapping-type">
86 <xsl:param name="dctype" />
87 <xsl:variable name="typename" select="@name"/>
88 <xsl:choose>
89 <xsl:when test="$dctype=$typename or count(following-sibling::*)=0">
90 <xsl:choose>
91 <xsl:when test="count(following-sibling::*) !=0 ">
92 <xsl:value-of select="@mapping"/>
93 </xsl:when>
94 <xsl:otherwise>
95 <xsl:value-of select="'a'"/>
96 </xsl:otherwise>
97 </xsl:choose>
98 </xsl:when>
99 <xsl:otherwise>
100 <xsl:apply-templates select="following-sibling::*[1]" mode="mapping-type" >
101 <xsl:with-param name="dctype" select="$dctype" />
102 </xsl:apply-templates>
103 </xsl:otherwise>
104 </xsl:choose>
105 </xsl:template>
106
107 <xsl:template match="controlfield">
108 <controlfield tag="{@tag}" xmlns="http://www.loc.gov/MARC21/slim"><xsl:value-of select="@value"/></controlfield>
109 </xsl:template>
110
111
112 <xsl:template match="MarcField">
113 <xsl:param name="source" />
114 <xsl:param name="item" />
115 <xsl:variable name="this" select="."/>
116 <xsl:choose>
117 <xsl:when test="@multiple='true'">
118 <xsl:variable name="meta" select="subfield[1]/@meta"/>
119 <xsl:for-each select="$source/Metadata[@name=$meta]">
120 <xsl:apply-templates select="$this/subfield[1]" mode="testing">
121 <xsl:with-param name="pos" select="position()"/>
122 <xsl:with-param name="source" select="$source"/>
123 <xsl:with-param name="item" select="$item"/>
124 </xsl:apply-templates>
125 </xsl:for-each>
126 </xsl:when>
127 <xsl:when test="@repeat='true'">
128 <xsl:variable name="meta" select="subfield[1]/@meta"/>
129 <xsl:for-each select="$source/Metadata[@name=$meta][position()!=1]">
130 <xsl:apply-templates select="$this/subfield[1]" mode="testing">
131 <xsl:with-param name="pos" select="position()+1"/>
132 <xsl:with-param name="source" select="$source"/>
133 <xsl:with-param name="item" select="$item"/>
134 </xsl:apply-templates>
135 </xsl:for-each>
136 </xsl:when>
137 <xsl:otherwise>
138 <xsl:apply-templates select="subfield[1]" mode="testing">
139 <xsl:with-param name="pos" select="'0'"/>
140 <xsl:with-param name="source" select="$source"/>
141 <xsl:with-param name="item" select="$item"/>
142 </xsl:apply-templates>
143 </xsl:otherwise>
144 </xsl:choose>
145 </xsl:template>
146
147 <xsl:template match="subfield" mode="testing">
148 <xsl:param name="pos"/>
149 <xsl:param name="source" />
150 <xsl:param name="item" />
151 <xsl:variable name="meta" select="@meta"/>
152 <xsl:choose>
153 <xsl:when test="count($source/Metadata[@name=$meta]) >0">
154 <datafield xmlns="http://www.loc.gov/MARC21/slim">
155 <xsl:apply-templates select="../@*" mode="mapping-attribute">
156 <xsl:with-param name="source" select="$source"/>
157 <xsl:with-param name="item" select="$item"/>
158 </xsl:apply-templates>
159 <xsl:apply-templates select="../subfield[not(@nonfiling)]" >
160 <xsl:with-param name="pos" select="$pos"/>
161 <xsl:with-param name="source" select="$source"/>
162 </xsl:apply-templates>
163 </datafield>
164 </xsl:when>
165 <xsl:otherwise>
166 <xsl:apply-templates select="following-sibling::*[1]" mode="testing" >
167 <xsl:with-param name="pos" select="$pos"/>
168 <xsl:with-param name="source" select="$source"/>
169 <xsl:with-param name="item" select="$item"/>
170 </xsl:apply-templates>
171 </xsl:otherwise>
172 </xsl:choose>
173 </xsl:template>
174
175
176 <xsl:template match="@*" mode="mapping-attribute" >
177 <xsl:param name="source" />
178 <xsl:param name="item" />
179 <xsl:variable name="name" select="name()"/>
180 <xsl:variable name="value" select="."/>
181 <xsl:choose>
182 <xsl:when test="starts-with($name,'ind') and $value='nonfiling'">
183 <xsl:variable name="meta" select="../subfield[@nonfiling='true']/@meta"/>
184 <xsl:variable name="content" select="$source/Metadata[@name=$meta]/text()"/>
185 <xsl:apply-templates select="$item[1]" mode="mapping-item">
186 <xsl:with-param name='name' select="$name"/>
187 <xsl:with-param name='content' select="$content"/>
188 <xsl:with-param name='subfield' select="../subfield[@nonfiling='true']"/>
189 <xsl:with-param name='source' select="$source"/>
190 </xsl:apply-templates>
191 </xsl:when>
192 <xsl:otherwise>
193 <xsl:if test="starts-with($name,'ind') or starts-with($name,'tag') ">
194 <xsl:call-template name="addAttribute" >
195 <xsl:with-param name='name' select="$name"/>
196 <xsl:with-param name='value' select="$value"/>
197 </xsl:call-template>
198 </xsl:if>
199 </xsl:otherwise>
200 </xsl:choose>
201 </xsl:template>
202
203
204 <xsl:template match="item" mode="mapping-item">
205 <xsl:param name="name" />
206 <xsl:param name="content" />
207 <xsl:param name="subfield" />
208 <xsl:param name="source" />
209
210 <xsl:variable name="itemname" select="@name"/>
211 <xsl:variable name="lowercasecontent" select="xsltutil:toLowerCase($content)"/>
212 <xsl:choose>
213 <xsl:when test="starts-with($lowercasecontent,$itemname) or count(following-sibling::*)=0">
214 <xsl:choose>
215 <xsl:when test="starts-with($lowercasecontent,$itemname)" >
216 <xsl:call-template name="addAttribute" >
217 <xsl:with-param name="name" select="$name"/>
218 <xsl:with-param name="value" select="@length"/>
219 </xsl:call-template>
220 <xsl:apply-templates select="$subfield" >
221 <xsl:with-param name="length" select="@length" />
222 <xsl:with-param name="content" select="$content" />
223 <xsl:with-param name="source" select="$source" />
224 </xsl:apply-templates>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:call-template name="addAttribute" >
228 <xsl:with-param name="name" select="$name"/>
229 <xsl:with-param name="value" select="'0'"/>
230 </xsl:call-template>
231 <xsl:apply-templates select="$subfield" >
232 <xsl:with-param name="length" select="'0'" />
233 <xsl:with-param name="content" select="$content" />
234 <xsl:with-param name="source" select="$source" />
235 </xsl:apply-templates>
236 </xsl:otherwise>
237 </xsl:choose>
238 </xsl:when>
239 <xsl:otherwise>
240 <xsl:apply-templates select="following-sibling::*[1]" mode="mapping-item" >
241 <xsl:with-param name="name" select="$name" />
242 <xsl:with-param name="content" select="$content" />
243 <xsl:with-param name="subfield" select="$subfield" />
244 <xsl:with-param name="source" select="$source" />
245 </xsl:apply-templates>
246 </xsl:otherwise>
247 </xsl:choose>
248 </xsl:template>
249
250
251 <xsl:template name="addAttribute">
252 <xsl:param name="value" />
253 <xsl:param name="name" />
254 <xsl:attribute name="{$name}"><xsl:value-of select="$value"/></xsl:attribute>
255 </xsl:template>
256
257
258
259 <xsl:template match="subfield">
260 <xsl:param name="length" />
261 <xsl:param name="content" />
262 <xsl:param name="pos" />
263 <xsl:param name="source" />
264 <xsl:variable name="meta" select="@meta" />
265 <xsl:variable name="punc" select="@punc" />
266 <xsl:if test="$source/Metadata[@name=$meta]">
267 <xsl:choose>
268 <xsl:when test="@nonfiling='true'">
269 <subfield code="{@code}" xmlns="http://www.loc.gov/MARC21/slim"><xsl:value-of select="$content"/><xsl:value-of select="@punc"/></subfield>
270 </xsl:when>
271 <xsl:when test="$pos >0">
272 <subfield code="{@code}" xmlns="http://www.loc.gov/MARC21/slim">
273 <xsl:value-of select="$source/Metadata[@name=$meta][$pos]"/><xsl:value-of select="$punc"/>
274 </subfield>
275 </xsl:when>
276 <xsl:otherwise>
277 <subfield code="{@code}" xmlns="http://www.loc.gov/MARC21/slim">
278 <xsl:value-of select="$source/Metadata[@name=$meta]"/><xsl:value-of select="$punc"/>
279 </subfield>
280 </xsl:otherwise>
281 </xsl:choose>
282 </xsl:if>
283 </xsl:template>
284
285</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.