source: main/tags/2.71/gsdl/etc/dc2marc.xsl@ 25382

Last change on this file since 25382 was 12595, checked in by shaoqun, 18 years ago

transformation file for dc to marc

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