source: metadata/trunk/toolkit/xslt/olac2cmdi.xsl @ 1570

Last change on this file since 1570 was 1570, checked in by dietuyt, 13 years ago

Added support in dc:identifier for urn:nbn PIDs

File size: 15.1 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns="http://www.clarin.eu/cmd/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
4    xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
5    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
6    xmlns:defns="http://www.openarchives.org/OAI/2.0/"
7    xmlns:olac="http://www.language-archives.org/OLAC/1.0/"
8    xmlns:olac11="http://www.language-archives.org/OLAC/1.1/"
9    xsi:schemaLocation="    http://purl.org/dc/elements/1.1/    http://www.language-archives.org/OLAC/1.0/dc.xsd    http://purl.org/dc/terms/    http://www.language-archives.org/OLAC/1.0/dcterms.xsd    http://www.language-archives.org/OLAC/1.0/    http://www.language-archives.org/OLAC/1.0/olac.xsd    http://www.language-archives.org/OLAC/1.0/ http://www.language-archives.org/OLAC/1.0/third-party/software.xsd ">
10
11    <!-- run on Ubuntu with: saxonb-xslt -ext:on -it main ~/svn/clarin/metadata/trunk/toolkit/xslt/olac2cmdi.xsl  -->
12
13    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
14
15    <xsl:key name="iso-lookup" match="lang" use="sil"/>
16    <xsl:key name="provider-lookup" match="prov" use="identifier"/>
17
18    <!--
19        This parameter can be used to specify path to the iso xml
20        file.
21      -->
22    <xsl:param name="iso_xml_path"/>
23    <xsl:variable name="lang-top" select="document(concat($iso_xml_path,'sil_to_iso6393.xml'))/languages"/>
24
25    <xsl:param name="providers_path"/>
26    <xsl:variable name="id-top" select="document(concat($providers_path,'id_to_name.xml'))/providers"/>
27   
28
29    <xsl:template match="/">
30        <CMD CMDVersion="1.1"
31            xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1288172614026/xsd">
32            <Header>
33                <MdCreator>olac2cmdi.xsl</MdCreator>
34                <MdCreationDate>
35                    <xsl:variable name="date">
36                        <xsl:value-of select="/defns:OAI-PMH/defns:GetRecord[1]/defns:record[1]/defns:header[1]/defns:datestamp[1]"/>
37                    </xsl:variable>
38                    <xsl:choose>
39                        <xsl:when test="contains($date,'T')">
40                            <xsl:value-of select="substring-before($date,'T')"/>
41                        </xsl:when>
42                        <xsl:otherwise>
43                            <xsl:value-of select="$date"/>
44                        </xsl:otherwise>
45                    </xsl:choose>
46                </MdCreationDate>
47                <MdSelfLink>
48                    <xsl:value-of select="/defns:OAI-PMH/defns:GetRecord[1]/defns:record[1]/defns:header[1]/defns:identifier[1]"/>
49                </MdSelfLink>
50                <MdProfile>clarin.eu:cr1:p_1288172614026</MdProfile>
51                <xsl:variable name="oai_id">
52                    <xsl:value-of select="tokenize(/defns:OAI-PMH/defns:GetRecord[1]/defns:record[1]/defns:header[1]/defns:identifier[1], ':')[2]"/>
53                </xsl:variable>
54                <MdCollectionDisplayName>
55                    <xsl:apply-templates select="$id-top">
56                        <xsl:with-param name="curr-label" select="$oai_id"/>
57                    </xsl:apply-templates>
58                </MdCollectionDisplayName>
59            </Header>
60            <Resources>
61                <ResourceProxyList>
62                    <xsl:apply-templates select="//dc:identifier" mode="preprocess"/>
63                </ResourceProxyList>
64                <JournalFileProxyList/>
65                <ResourceRelationList/>
66            </Resources>
67            <Components>
68                <OLAC-DcmiTerms>
69
70                    <xsl:apply-templates select="//dcterms:abstract"/>
71                    <xsl:apply-templates select="//dcterms:accessRights"/>
72                    <xsl:apply-templates select="//dcterms:accrualMethod"/>
73                    <xsl:apply-templates select="//dcterms:accrualPeriodicity"/>
74                    <xsl:apply-templates select="//dcterms:accrualPolicy"/>
75                    <xsl:apply-templates select="//dcterms:alternative"/>
76                    <xsl:apply-templates select="//dcterms:audience"/>
77                    <xsl:apply-templates select="//dcterms:available"/>
78                    <xsl:apply-templates select="//dcterms:bibliographicCitation"/>
79                    <xsl:apply-templates select="//dcterms:conformsTo"/>
80
81                    <xsl:apply-templates select="//dc:contributor"/>
82                    <xsl:apply-templates select="//dc:coverage"/>
83
84                    <xsl:apply-templates select="//dcterms:created"/>
85
86                    <xsl:apply-templates select="//dc:creator"/>
87                    <xsl:apply-templates select="//dc:date"/>
88
89                    <xsl:apply-templates select="//dcterms:dateAccepted"/>
90                    <xsl:apply-templates select="//dcterms:dateCopyrighted"/>
91                    <xsl:apply-templates select="//dcterms:dateSubmitted"/>
92
93                    <xsl:apply-templates select="//dc:description"/>
94
95                    <xsl:apply-templates select="//dcterms:educationLevel"/>
96                    <xsl:apply-templates select="//dcterms:extent"/>
97
98                    <xsl:apply-templates select="//dc:format"/>
99
100                    <xsl:apply-templates select="//dcterms:hasFormat"/>
101                    <xsl:apply-templates select="//dcterms:hasPart"/>
102                    <xsl:apply-templates select="//dcterms:hasVersion"/>
103
104                    <xsl:apply-templates select="//dc:identifier"/>
105
106                    <xsl:apply-templates select="//dc:instructionalMethod"/>
107
108                    <xsl:apply-templates select="//dcterms:isFormatOf"/>
109                    <xsl:apply-templates select="//dcterms:isPartOf"/>
110                    <xsl:apply-templates select="//dcterms:isReferencedBy"/>
111                    <xsl:apply-templates select="//dcterms:isReplacedBy"/>
112                    <xsl:apply-templates select="//dcterms:isRequiredBy"/>
113                    <xsl:apply-templates select="//dcterms:issued"/>
114                    <xsl:apply-templates select="//dcterms:isVersionOf"/>
115
116                    <xsl:apply-templates select="//dc:language"/>
117
118                    <xsl:apply-templates select="//dcterms:license"/>
119                    <xsl:apply-templates select="//dcterms:mediator"/>
120                    <xsl:apply-templates select="//dcterms:medium"/>
121                    <xsl:apply-templates select="//dcterms:modified"/>
122                    <xsl:apply-templates select="//dcterms:provenance"/>
123
124                    <xsl:apply-templates select="//dc:publisher"/>
125
126                    <xsl:apply-templates select="//dcterms:references"/>
127
128                    <xsl:apply-templates select="//dc:relation"/>
129
130                    <xsl:apply-templates select="//dcterms:replaces"/>
131                    <xsl:apply-templates select="//dcterms:requires"/>
132
133                    <xsl:apply-templates select="//dc:rights"/>
134
135                    <xsl:apply-templates select="//dcterms:rightsHolder"/>
136
137                    <xsl:apply-templates select="//dc:source"/>
138
139                    <xsl:apply-templates select="//dcterms:spatial"/>
140
141                    <xsl:apply-templates select="//dc:subject"/>
142
143                    <xsl:apply-templates select="//dcterms:tableOfContents"/>
144                    <xsl:apply-templates select="//dcterms:temporal"/>
145
146                    <xsl:apply-templates select="//dc:title"/>
147                    <xsl:apply-templates select="//dc:type"/>
148
149                    <xsl:apply-templates select="//dcterms:valid"/>
150
151                </OLAC-DcmiTerms>
152            </Components>
153        </CMD>
154    </xsl:template>
155
156    <xsl:template match="dc:contributor">
157        <contributor>
158            <xsl:if test="@xsi:type='olac:role'">
159                <xsl:if test="@*:code">
160                    <xsl:attribute name="olac-role">
161                        <!-- note: namespace wildcard necessary to match with both OLAC 1.0 and 1.1 -->
162                        <xsl:value-of select="@*:code"/>
163                    </xsl:attribute>
164                </xsl:if>
165            </xsl:if>
166            <xsl:value-of select="."/>
167        </contributor>
168    </xsl:template>
169
170    <xsl:template match="dc:description">
171        <description>
172            <xsl:apply-templates select="./@xml:lang"/>
173            <xsl:apply-templates select="@xsi:type"/>
174            <xsl:value-of select="."/>
175        </description>
176    </xsl:template>
177
178    <xsl:template match="dc:language[@xsi:type='olac:language']" priority="3">
179        <language>
180            <xsl:if test="@*:code">
181                <xsl:attribute name="olac-language">
182                    <!-- can be enabled when there is a 1-to-1 mapping in sil_to_iso6393.xml           -->
183                    <xsl:choose>
184                        <xsl:when test="contains(@*:code, 'x-sil-')">
185                            <xsl:apply-templates select="$lang-top">
186                                <xsl:with-param name="curr-label" select="."/>
187                            </xsl:apply-templates>
188                        </xsl:when>
189                        <xsl:otherwise>
190                            <xsl:value-of select="@*:code"/>
191                        </xsl:otherwise>
192                    </xsl:choose>
193                </xsl:attribute>
194            </xsl:if>
195            <xsl:value-of select="."/>
196        </language>
197    </xsl:template>
198
199    <xsl:template match="languages">
200        <xsl:param name="curr-label"/>
201        <xsl:variable name="silcode">
202            <xsl:value-of select="lower-case(replace($curr-label/@*:code, 'x-sil-', ''))"/>
203        </xsl:variable>
204        <xsl:value-of select="key('iso-lookup', $silcode)/iso"/>
205    </xsl:template>
206   
207    <xsl:template match="providers">
208        <xsl:param name="curr-label"/>
209        <xsl:variable name="id">
210            <xsl:value-of select="$curr-label"/>
211        </xsl:variable>
212        <xsl:value-of select="key('provider-lookup', $id)/name"/>
213    </xsl:template>
214   
215
216
217    <xsl:template match="dc:identifier" mode="preprocess">
218 
219        <xsl:if test="contains(., 'http://') or contains(., 'urn:nbn') or contains(., 'hdl:')">
220        <ResourceProxy>
221            <xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>
222            <ResourceType>Resource</ResourceType>
223            <ResourceRef><xsl:value-of select="."/></ResourceRef>
224        </ResourceProxy>
225        </xsl:if>
226     
227    </xsl:template>
228
229
230    <xsl:template match="dc:subject[@xsi:type='olac:language']" priority="3">
231        <subject>
232            <!-- can be enabled when there is a 1-to-1 mapping in sil_to_iso6393.xml           -->
233            <xsl:if test="@*:code">
234                <xsl:attribute name="olac-language">
235                    <xsl:choose>
236                        <xsl:when test="contains(@*:code, 'x-sil-')">
237                            <xsl:apply-templates select="$lang-top">
238                                <xsl:with-param name="curr-label" select="."/>
239                            </xsl:apply-templates>
240                        </xsl:when>
241                        <xsl:otherwise>
242                            <xsl:value-of select="@*:code"/>
243                        </xsl:otherwise>
244                    </xsl:choose>
245                </xsl:attribute>
246            </xsl:if>
247            <xsl:value-of select="."/>
248        </subject>
249    </xsl:template>
250
251    <xsl:template match="//dc:subject[@xsi:type='olac:linguistic-field']" priority="3">
252        <subject>
253            <xsl:if test="@*:code">
254                <xsl:attribute name="olac-linguistic-field">
255                    <xsl:value-of select="@*:code"/>
256                </xsl:attribute>
257            </xsl:if>
258            <xsl:value-of select="."/>
259        </subject>
260    </xsl:template>
261
262    <xsl:template match="//dc:subject[@xsi:type='olac:discourse-type']" priority="3">
263        <subject>
264            <xsl:attribute name="olac-discourse-type">
265                <xsl:value-of select="@*:code"/>
266            </xsl:attribute>
267            <xsl:value-of select="."/>
268        </subject>
269    </xsl:template>
270
271
272    <xsl:template match="//dc:subject" priority="1">
273        <subject>
274            <xsl:apply-templates select="./@xml:lang"/>
275            <xsl:apply-templates select="@xsi:type"/>
276            <xsl:value-of select="."/>
277        </subject>
278    </xsl:template>
279
280
281    <xsl:template match="//dc:title">
282        <title>
283            <xsl:apply-templates select="./@xml:lang"/>
284            <xsl:apply-templates select="@xsi:type"/>
285            <xsl:value-of select="."/>
286        </title>
287    </xsl:template>
288
289
290    <xsl:template match="//dc:type[@xsi:type='olac:discourse-type']" priority="2">
291        <type>
292            <xsl:if test="@*:code">
293                <xsl:attribute name="olac-discourse-type">
294                    <xsl:value-of select="@*:code"/>
295                </xsl:attribute>
296            </xsl:if>
297            <xsl:value-of select="."/>
298        </type>
299    </xsl:template>
300
301
302    <xsl:template match="//dc:type[@xsi:type='olac:linguistic-type']" priority="2">
303        <type>
304            <xsl:if test="@*:code">
305                <xsl:attribute name="olac-linguistic-type">
306                    <xsl:value-of select="@*:code"/>
307                </xsl:attribute>
308            </xsl:if>
309            <xsl:value-of select="."/>
310        </type>
311    </xsl:template>
312
313
314    <xsl:template match="//dc:type" priority="1">
315        <type>
316            <xsl:apply-templates select="@xsi:type"/>
317            <xsl:value-of select="."/>
318        </type>
319    </xsl:template>
320
321    <xsl:template match="@xml:lang">
322        <xsl:attribute name="xml:lang">
323            <xsl:value-of select="."/>
324        </xsl:attribute>
325    </xsl:template>
326
327    <xsl:template match="@xsi:type">
328        <xsl:variable name="attval">
329            <xsl:value-of select="."/>
330        </xsl:variable>
331        <xsl:if test="contains($attval, 'dcterms:')">
332            <xsl:variable name="attclean">
333                <xsl:value-of select="replace($attval, 'dcterms:','')"/>
334            </xsl:variable>
335            <xsl:attribute name="dcterms-type">
336                <xsl:value-of select="$attclean"/>
337            </xsl:attribute>
338        </xsl:if>
339    </xsl:template>
340
341    <!--  general DC  template -->
342    <xsl:template match="dc:*">
343        <xsl:variable name="tagname">
344            <xsl:value-of select="local-name()"/>
345        </xsl:variable>
346        <xsl:element name="{$tagname}">
347            <xsl:apply-templates select="@xsi:type"/>
348            <xsl:value-of select="."/>
349        </xsl:element>
350    </xsl:template>
351
352    <!--  general DC terms template -->
353    <xsl:template match="dcterms:*">
354        <xsl:variable name="tagname">
355            <xsl:value-of select="local-name()"/>
356        </xsl:variable>
357
358        <xsl:element name="{$tagname}">
359            <xsl:apply-templates select="@xsi:type"/>
360            <xsl:value-of select="."/>
361        </xsl:element>
362    </xsl:template>
363
364
365
366    <xsl:template name="main">
367        <xsl:for-each
368            select="collection('file:////home/dietuyt/olac?select=*.xml;recurse=yes;on-error=ignore')">
369            <xsl:result-document href="{document-uri(.)}.cmdi">
370                <xsl:apply-templates select="."/>
371            </xsl:result-document>
372        </xsl:for-each>
373    </xsl:template>
374
375
376</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.