Ticket #323: imdi2clarin.2.xsl

File imdi2clarin.2.xsl, 34.5 KB (added by sanmai, 11 years ago)

Version that should fix the issue as per Dieter's requirements.

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3$Rev: 2454 $
4$LastChangedDate: 2013-01-10 16:24:21 +0100 (Thu, 10 Jan 2013) $
5-->
6<xsl:stylesheet xmlns="http://www.clarin.eu/cmd/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7    version="2.0" xpath-default-namespace="http://www.mpi.nl/IMDI/Schema/IMDI">
8    <!-- this is a version of imdi2clarin.xsl that batch processes a whole directory structure of imdi files, call it from the command line like this:
9        java -jar saxon8.jar -it main batch-imdi2clarin.xsl
10        the last template in this file has to be modified to reflect the actual directory name
11    -->
12    <xsl:output method="xml" indent="yes"/>
13
14    <!-- A collection name can be specified for each record. This
15    information is extrinsic to the IMDI file, so it is given as an
16    external parameter. Omit this if you are unsure. -->
17    <xsl:param name="collection"/>
18
19    <!-- If this optional parameter is defined, the behaviour of this
20    stylesheet changes in the following ways: If no archive handle is
21    available for MdSelfLink, the base URI is inserted there
22    instead. All links (ResourceProxy elements) that contain relative
23    paths are resolved into absolute URIs in the context of the base
24    URI. Omit this if you are unsure. -->
25    <xsl:param name="uri-base"/>
26   
27    <!-- An URL (composed of scheme and host URL components) pointing to the IMDI browser -->
28    <xsl:param name="IMDI_browser_URL" select="'http://corpus1.mpi.nl/'"/>
29
30    <!-- definition of the SRU-searchable collections at TLA (for use later on) -->
31    <xsl:variable name="SruSearchable">childes,ESF corpus,IFA corpus,MPI CGN,talkbank</xsl:variable>
32
33    <xsl:template name="metatranscriptDelegate">
34        <xsl:param name="profile"/>
35        <Header>
36            <MdCreator>imdi2clarin.xsl</MdCreator>
37            <MdCreationDate>
38                <xsl:value-of select="format-date(current-date(), '[Y]-[M01]-[D01]')"/>
39            </MdCreationDate>
40            <MdSelfLink>
41                <xsl:choose>
42                    <!-- ArchiveHandle attribute has MPI handle prefix? If so, use handle + @format=cmdi suffix -->
43                    <xsl:when test="starts-with(normalize-space(@ArchiveHandle), 'hdl:1839/')">
44                        <xsl:value-of select="@ArchiveHandle"/><xsl:text>@format=cmdi</xsl:text>
45                    </xsl:when>
46                    <!-- No handle? Then just use the URL -->
47                    <xsl:when test="not($uri-base='') and normalize-space(@ArchiveHandle)=''"><xsl:value-of select="$uri-base"/></xsl:when>
48                    <!-- Other handle prefix? Use handle (e.g. Lund) -->
49                    <xsl:otherwise><xsl:value-of select="@ArchiveHandle"/></xsl:otherwise>
50                </xsl:choose>
51            </MdSelfLink>
52            <MdProfile>
53                <xsl:value-of select="$profile"/>
54            </MdProfile>
55            <xsl:if test="$collection">
56                <MdCollectionDisplayName>
57                    <xsl:value-of select="$collection"/>
58                </MdCollectionDisplayName>
59            </xsl:if>
60        </Header>
61        <Resources>
62            <ResourceProxyList>
63                <!-- ArchiveHandle attribute has MPI handle prefix? If so, generate a LandingPage resource to the original IMDI -->
64                <xsl:if test="starts-with(normalize-space(@ArchiveHandle), 'hdl:1839/')">
65                    <ResourceProxy id="{generate-id()}">
66                        <ResourceType>LandingPage</ResourceType>
67                        <ResourceRef><xsl:value-of select="concat($IMDI_browser_URL, 'ds/imdi_browser/?openpath=', encode-for-uri(@ArchiveHandle))"/></ResourceRef> 
68                        <!--  -->
69                    </ResourceProxy>
70                </xsl:if>
71                <xsl:apply-templates select="//Resources" mode="linking"/>
72                <xsl:apply-templates select="//Description[not(normalize-space(./@ArchiveHandle)='') or not(normalize-space(./@Link)='')]" mode="linking"/>
73                <xsl:apply-templates select="//Corpus" mode="linking"/>
74                <!-- If this collection name is indicated to be SRU-searchable, add a link to the TLA SRU endpoint -->
75                <xsl:if test="$collection and contains($SruSearchable,$collection)">
76                <ResourceProxy id="sru">
77                    <ResourceType>SearchService</ResourceType>
78                    <ResourceRef>http://cqlservlet.mpi.nl/</ResourceRef>
79                </ResourceProxy>
80                </xsl:if>
81            </ResourceProxyList>
82            <JournalFileProxyList> </JournalFileProxyList>
83            <ResourceRelationList> </ResourceRelationList>
84        </Resources>
85        <Components>
86            <xsl:apply-templates select="Session"/>
87            <xsl:apply-templates select="Corpus"/>
88        </Components>
89    </xsl:template>
90
91    <xsl:template match="METATRANSCRIPT">
92        <xsl:choose>
93            <xsl:when test=".[@Type='SESSION'] or .[@Type='SESSION.Profile']">
94                <CMD CMDVersion="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
95                    xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1271859438204/xsd">
96                    <xsl:call-template name="metatranscriptDelegate">
97                        <xsl:with-param name="profile"
98                            >clarin.eu:cr1:p_1271859438204</xsl:with-param>
99                    </xsl:call-template>
100                </CMD>
101            </xsl:when>
102            <xsl:when test=".[@Type='CORPUS'] or .[@Type='CORPUS.Profile']">
103                <CMD CMDVersion="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
104                    xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1274880881885/xsd">
105                    <xsl:call-template name="metatranscriptDelegate">
106                        <xsl:with-param name="profile"
107                            >clarin.eu:cr1:p_1274880881885</xsl:with-param>
108                    </xsl:call-template>
109                </CMD>
110            </xsl:when>
111            <xsl:otherwise>
112                <!--                Currently we are only processing 'SESSION' and 'CORPUS' types. The error displayed can be used to filter out erroneous files after processing-->
113                ERROR: Invalid METATRANSCRIPT Type! </xsl:otherwise>
114        </xsl:choose>
115    </xsl:template>
116
117
118    <xsl:template match="Corpus">
119        <imdi-corpus>
120            <Corpus>
121                <xsl:apply-templates select="child::Name"/>
122                <xsl:apply-templates select="child::Title"/>
123                <xsl:if test="exists(child::Description)">
124                    <descriptions>
125                        <xsl:variable name="reflist">
126                            <xsl:for-each select="Description">
127                                <xsl:if test="not(normalize-space(@ArchiveHandle)='') or not(normalize-space(@Link)='')">
128                                    <xsl:value-of select="generate-id()"/>
129                                    <xsl:text> </xsl:text>
130                                </xsl:if>
131                            </xsl:for-each> 
132                        </xsl:variable>
133                       
134                        <xsl:attribute name="ref" select="normalize-space($reflist)"></xsl:attribute>
135                       
136                        <xsl:for-each select="Description">
137                        <Description>
138                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
139                            <xsl:value-of select="."/>
140                        </Description>
141                        </xsl:for-each>
142                       
143                    </descriptions>
144                </xsl:if>
145                <xsl:if test="exists(child::CorpusLink)">
146                    <xsl:for-each select="CorpusLink">
147                        <CorpusLink>
148                            <CorpusLinkContent>
149                                <!--<xsl:attribute name="ArchiveHandle" select="@ArchiveHandle"/>-->
150                                <xsl:attribute name="Name" select="@Name"/>
151                                <xsl:value-of select="."/>
152                            </CorpusLinkContent>
153                        </CorpusLink>
154                    </xsl:for-each>
155                </xsl:if>
156            </Corpus>
157        </imdi-corpus>
158    </xsl:template>
159
160    <xsl:template match="Corpus" mode="linking">
161        <xsl:for-each select="CorpusLink">
162            <ResourceProxy id="{generate-id()}">
163                <ResourceType>Metadata</ResourceType>
164                <ResourceRef>
165                    <xsl:choose>
166                        <xsl:when test="not(normalize-space(./@ArchiveHandle)='')"
167                                >test-<xsl:value-of select="./@ArchiveHandle"/></xsl:when>
168                        <xsl:when test="starts-with(., 'hdl:')">
169                            <xsl:value-of select="."/>
170                        </xsl:when>
171                        <xsl:when test="$uri-base=''"><xsl:value-of select="."/>.cmdi</xsl:when>
172                        <xsl:otherwise>
173                            <xsl:value-of
174                                select="concat(resolve-uri(normalize-space(.), $uri-base), '.cmdi')"
175                            />
176                        </xsl:otherwise>
177                    </xsl:choose>
178                </ResourceRef>
179            </ResourceProxy>
180        </xsl:for-each>
181    </xsl:template>
182
183    <!-- Create ResourceProxy for MediaFile and WrittenResource -->
184    <xsl:template match="Resources" mode="linking">
185        <xsl:for-each select="MediaFile">
186            <xsl:call-template name="CreateResourceProxyTypeResource"/>       
187        </xsl:for-each>
188        <xsl:for-each select="WrittenResource">
189            <xsl:call-template name="CreateResourceProxyTypeResource"/>
190        </xsl:for-each>
191    </xsl:template>
192   
193    <!-- Create ResourceProxy for Info files -->
194    <xsl:template match="//Description[@ArchiveHandle or @Link]" mode="linking">
195        <xsl:call-template name="CreateResourceProxyTypeResource"/>
196    </xsl:template> 
197   
198    <!-- to be called during the creation of the ResourceProxyList (in linking mode) -->
199    <xsl:template name="CreateResourceProxyTypeResource">
200        <ResourceProxy id="{generate-id()}">
201            <ResourceType>
202                <xsl:if test="exists(Format) and not(empty(Format))">
203                    <xsl:attribute name="mimetype">
204                        <xsl:value-of select="./Format"/>
205                    </xsl:attribute>
206                </xsl:if>Resource</ResourceType>
207            <ResourceRef>
208                <xsl:choose>
209                    <xsl:when test="not(normalize-space(ResourceLink/@ArchiveHandle)='')">
210                        <xsl:value-of select="ResourceLink/@ArchiveHandle"/>
211                    </xsl:when>
212                    <xsl:when test="not($uri-base='')">
213                        <xsl:value-of
214                            select="resolve-uri(normalize-space(ResourceLink/.), $uri-base)"/>
215                    </xsl:when>
216                    <!-- for info files the @ArchiveHandle or @Link is part of the Description element - preference for ArchiveHandle -->
217                    <xsl:when test="not(normalize-space(@ArchiveHandle)='')">
218                        <xsl:value-of select="@ArchiveHandle"/>
219                    </xsl:when>
220                    <xsl:when test="not(normalize-space(@Link)='')">
221                        <xsl:value-of select="@Link"/>
222                    </xsl:when>
223                </xsl:choose>
224            </ResourceRef>
225        </ResourceProxy>
226    </xsl:template>
227
228
229
230    <xsl:template match="Session">
231        <Session>
232            <xsl:apply-templates select="child::Name"/>
233            <xsl:apply-templates select="child::Title"/>
234            <xsl:apply-templates select="child::Date"/>
235            <xsl:if test="exists(child::Description)">
236                <descriptions>
237                    <xsl:variable name="reflist">
238                        <xsl:for-each select="Description">
239                            <xsl:if test="not(normalize-space(@ArchiveHandle)='') or not(normalize-space(@Link)='')">
240                                <xsl:value-of select="generate-id()"/>
241                                <xsl:text> </xsl:text>
242                            </xsl:if>
243                        </xsl:for-each> 
244                    </xsl:variable>
245                   
246                    <xsl:if test="not(normalize-space($reflist)='')">
247                        <xsl:attribute name="ref" select="normalize-space($reflist)"></xsl:attribute>
248                    </xsl:if>
249
250                    <xsl:for-each select="Description">
251                        <Description>
252                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
253                            <xsl:value-of select="."/>
254                        </Description>
255                    </xsl:for-each>
256                </descriptions>
257            </xsl:if>
258            <xsl:apply-templates select="child::MDGroup"/>
259            <xsl:apply-templates select="child::Resources" mode="regular"/>
260            <xsl:apply-templates select="child::References"/>
261        </Session>
262    </xsl:template>
263
264    <xsl:template match="child::Name">
265        <Name>
266            <xsl:value-of select="."/>
267        </Name>
268    </xsl:template>
269
270    <xsl:template match="child::Title">
271        <Title>
272            <xsl:value-of select="."/>
273        </Title>
274    </xsl:template>
275
276    <xsl:template match="child::Date">
277        <Date>
278            <xsl:value-of select="."/>
279        </Date>
280    </xsl:template>
281
282    <xsl:template match="child::MDGroup">
283        <MDGroup>
284            <xsl:apply-templates select="child::Location"/>
285            <xsl:apply-templates select="child::Project"/>
286            <xsl:apply-templates select="child::Keys"/>
287            <xsl:apply-templates select="child::Content"/>
288            <xsl:apply-templates select="child::Actors"/>
289        </MDGroup>
290    </xsl:template>
291
292    <xsl:template match="Location">
293        <Location>
294            <Continent>
295                <xsl:value-of select="child::Continent"/>
296            </Continent>
297            <Country>
298                <xsl:value-of select="child::Country"/>
299            </Country>
300            <xsl:if test="exists(child::Region)">
301                <Region>
302                    <xsl:value-of select="child::Region"/>
303                </Region>
304            </xsl:if>
305            <xsl:if test="exists(child::Address)">
306                <Address>
307                    <xsl:value-of select="child::Address"/>
308                </Address>
309            </xsl:if>
310        </Location>
311    </xsl:template>
312
313    <xsl:template match="Project">
314        <Project>
315            <Name>
316                <xsl:value-of select="child::Name"/>
317            </Name>
318            <Title>
319                <xsl:value-of select="child::Title"/>
320            </Title>
321            <Id>
322                <xsl:value-of select="child::Id"/>
323            </Id>
324            <xsl:apply-templates select="Contact"/>
325            <xsl:if test="exists(child::Description)">
326                <descriptions>
327                    <xsl:for-each select="Description">
328                        <Description>
329                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
330                            <xsl:value-of select="."/>
331                        </Description>
332                    </xsl:for-each>
333                </descriptions>
334            </xsl:if>
335        </Project>
336    </xsl:template>
337
338    <xsl:template match="Contact">
339        <Contact>
340            <Name>
341                <xsl:value-of select="child::Name"/>
342            </Name>
343            <Address>
344                <xsl:value-of select="child::Address"/>
345            </Address>
346            <Email>
347                <xsl:value-of select="child::Email"/>
348            </Email>
349            <Organisation>
350                <xsl:value-of select="child::Organisation"/>
351            </Organisation>
352        </Contact>
353    </xsl:template>
354
355    <xsl:template match="Keys">
356        <Keys>
357            <xsl:for-each select="Key">
358                <Key>
359                    <xsl:attribute name="Name">
360                        <xsl:value-of select="@Name"/>
361                    </xsl:attribute>
362                    <xsl:value-of select="."/>
363                </Key>
364            </xsl:for-each>
365        </Keys>
366    </xsl:template>
367
368    <xsl:template match="Content">
369        <Content>
370            <Genre>
371                <xsl:value-of select="child::Genre"/>
372            </Genre>
373            <xsl:if test="exists(child::SubGenre)">
374                <SubGenre>
375                    <xsl:value-of select="child::SubGenre"/>
376                </SubGenre>
377            </xsl:if>
378            <xsl:if test="exists(child::Task)">
379                <Task>
380                    <xsl:value-of select="child::Task"/>
381                </Task>
382            </xsl:if>
383            <xsl:if test="exists(child::Modalities)">
384                <Modalities>
385                    <xsl:value-of select="child::Modalities"/>
386                </Modalities>
387            </xsl:if>
388            <xsl:if test="exists(child::Subject)">
389                <Subject>
390                    <xsl:value-of select="child::Subject"/>
391                </Subject>
392            </xsl:if>
393            <xsl:apply-templates select="child::CommunicationContext"/>
394            <xsl:apply-templates select="child::Languages" mode="content"/>
395            <xsl:apply-templates select="child::Keys"/>
396            <xsl:if test="exists(child::Description)">
397                <descriptions>
398                    <xsl:for-each select="Description">
399                        <Description>
400                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
401                            <xsl:value-of select="."/>
402                        </Description>
403                    </xsl:for-each>
404                </descriptions>
405            </xsl:if>
406        </Content>
407
408    </xsl:template>
409
410    <xsl:template match="CommunicationContext">
411        <CommunicationContext>
412            <xsl:if test="exists(child::Interactivity)">
413                <Interactivity>
414                    <xsl:value-of select="child::Interactivity"/>
415                </Interactivity>
416            </xsl:if>
417            <xsl:if test="exists(child::PlanningType)">
418                <PlanningType>
419                    <xsl:value-of select="child::PlanningType"/>
420                </PlanningType>
421            </xsl:if>
422            <xsl:if test="exists(child::Involvement)">
423                <Involvement>
424                    <xsl:value-of select="child::Involvement"/>
425                </Involvement>
426            </xsl:if>
427            <xsl:if test="exists(child::SocialContext)">
428                <SocialContext>
429                    <xsl:value-of select="child::SocialContext"/>
430                </SocialContext>
431            </xsl:if>
432            <xsl:if test="exists(child::EventStructure)">
433                <EventStructure>
434                    <xsl:value-of select="child::EventStructure"/>
435                </EventStructure>
436            </xsl:if>
437            <xsl:if test="exists(child::Channel)">
438                <Channel>
439                    <xsl:value-of select="child::Channel"/>
440                </Channel>
441            </xsl:if>
442        </CommunicationContext>
443    </xsl:template>
444
445    <xsl:template match="Languages" mode="content">
446        <Content_Languages>
447            <xsl:if test="exists(child::Description)">
448                <descriptions>
449                    <xsl:for-each select="Description">
450                        <Description>
451                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
452                            <xsl:value-of select="."/>
453                        </Description>
454                    </xsl:for-each>
455                </descriptions>
456            </xsl:if>
457            <xsl:for-each select="Language">
458                <Content_Language>
459                    <Id>
460                        <xsl:value-of select=" ./Id"/>
461                    </Id>
462                    <Name>
463                        <xsl:value-of select=" ./Name"/>
464                    </Name>
465                    <xsl:if test="exists(child::Dominant)">
466                        <Dominant>
467                            <xsl:value-of select=" ./Dominant"/>
468                        </Dominant>
469                    </xsl:if>
470                    <xsl:if test="exists(child::SourceLanguage)">
471                        <SourceLanguage>
472                            <xsl:value-of select=" ./SourceLanguage"/>
473                        </SourceLanguage>
474                    </xsl:if>
475                    <xsl:if test="exists(child::TargetLanguage)">
476                        <TargetLanguage>
477                            <xsl:value-of select=" ./TargetLanguage"/>
478                        </TargetLanguage>
479                    </xsl:if>
480                    <xsl:if test="exists(child::Description)">
481                        <descriptions>
482                            <xsl:for-each select="Description">
483                                <Description>
484                                    <xsl:attribute name="LanguageId" select="@LanguageId"/>
485                                    <xsl:value-of select="."/>
486                                </Description>
487                            </xsl:for-each>
488                        </descriptions>
489                    </xsl:if>
490                </Content_Language>
491            </xsl:for-each>
492        </Content_Languages>
493    </xsl:template>
494
495    <xsl:template match="Actors">
496        <Actors>
497            <xsl:if test="exists(child::Description)">
498                <descriptions>
499                    <xsl:for-each select="Description">
500                        <Description>
501                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
502                            <xsl:value-of select="."/>
503                        </Description>
504                    </xsl:for-each>
505                </descriptions>
506            </xsl:if>
507            <xsl:for-each select="Actor">
508                <Actor>
509                    <Role>
510                        <xsl:value-of select=" ./Role"/>
511                    </Role>
512                    <Name>
513                        <xsl:value-of select=" ./Name"/>
514                    </Name>
515                    <FullName>
516                        <xsl:value-of select=" ./FullName"/>
517                    </FullName>
518                    <Code>
519                        <xsl:value-of select=" ./Code"/>
520                    </Code>
521                    <FamilySocialRole>
522                        <xsl:value-of select=" ./FamilySocialRole"/>
523                    </FamilySocialRole>
524                    <EthnicGroup>
525                        <xsl:value-of select=" ./EthnicGroup"/>
526                    </EthnicGroup>
527                    <Age>
528                        <xsl:value-of select=" ./Age"/>
529                    </Age>
530                    <BirthDate>
531                        <xsl:value-of select=" ./BirthDate"/>
532                    </BirthDate>
533                    <Sex>
534                        <xsl:value-of select=" ./Sex"/>
535                    </Sex>
536                    <Education>
537                        <xsl:value-of select=" ./Education"/>
538                    </Education>
539                    <Anonymized>
540                        <xsl:value-of select=" ./Anonymized"/>
541                    </Anonymized>
542                    <xsl:apply-templates select="Contact"/>
543                    <xsl:apply-templates select="child::Keys"/>
544                    <xsl:if test="exists(child::Description)">
545                        <descriptions>
546                            <xsl:for-each select="Description">
547                                <Description>
548                                    <xsl:attribute name="LanguageId" select="@LanguageId"/>
549                                    <xsl:value-of select="."/>
550                                </Description>
551                            </xsl:for-each>
552                        </descriptions>
553                    </xsl:if>
554                    <xsl:apply-templates select="child::Languages" mode="actor"/>
555                </Actor>
556            </xsl:for-each>
557        </Actors>
558    </xsl:template>
559
560    <xsl:template match="Languages" mode="actor">
561        <Actor_Languages>
562            <xsl:if test="exists(child::Description)">
563                <descriptions>
564                    <xsl:for-each select="Description">
565                        <Description>
566                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
567                            <xsl:value-of select="."/>
568                        </Description>
569                    </xsl:for-each>
570                </descriptions>
571            </xsl:if>
572            <xsl:for-each select="Language">
573                <Actor_Language>
574                    <Id>
575                        <xsl:value-of select=" ./Id"/>
576                    </Id>
577                    <Name>
578                        <xsl:value-of select=" ./Name"/>
579                    </Name>
580                    <xsl:if test="exists(child::MotherTongue)">
581                        <MotherTongue>
582                            <xsl:value-of select=" ./MotherTongue"/>
583                        </MotherTongue>
584                    </xsl:if>
585                    <xsl:if test="exists(child::PrimaryLanguage)">
586                        <PrimaryLanguage>
587                            <xsl:value-of select=" ./PrimaryLanguage"/>
588                        </PrimaryLanguage>
589                    </xsl:if>
590                    <xsl:if test="exists(child::Description)">
591                        <descriptions>
592                            <xsl:for-each select="Description">
593                                <Description>
594                                    <xsl:attribute name="LanguageId" select="@LanguageId"/>
595                                    <xsl:value-of select="."/>
596                                </Description>
597                            </xsl:for-each>
598                        </descriptions>
599                    </xsl:if>
600                </Actor_Language>
601            </xsl:for-each>
602        </Actor_Languages>
603    </xsl:template>
604
605
606    <xsl:template match="child::Resources" mode="regular">
607        <Resources>
608            <xsl:apply-templates select="MediaFile"/>
609            <xsl:apply-templates select="WrittenResource"/>
610            <xsl:apply-templates select="Source"/>
611            <xsl:apply-templates select="Anonyms"/>
612        </Resources>
613    </xsl:template>
614
615    <xsl:template match="MediaFile">
616        <MediaFile ref="{generate-id()}">
617            <ResourceLink>
618                <xsl:value-of select=" ./ResourceLink"/>
619            </ResourceLink>
620            <Type>
621                <xsl:value-of select=" ./Type"/>
622            </Type>
623            <Format>
624                <xsl:value-of select=" ./Format"/>
625            </Format>
626            <Size>
627                <xsl:value-of select=" ./Size"/>
628            </Size>
629            <Quality>
630                <xsl:value-of select=" ./Quality"/>
631            </Quality>
632            <RecordingConditions>
633                <xsl:value-of select=" ./RecordingConditions"/>
634            </RecordingConditions>
635            <TimePosition>
636                <Start>
637                    <xsl:apply-templates select="TimePosition/Start"/>
638                </Start>
639                <xsl:if test="exists(descendant::End)">
640                    <End>
641                        <xsl:apply-templates select="TimePosition/End"/>
642                    </End>
643                </xsl:if>
644            </TimePosition>
645            <xsl:apply-templates select="Access"/>
646            <xsl:if test="exists(child::Description)">
647                <descriptions>
648                    <xsl:for-each select="Description">
649                        <Description>
650                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
651                            <xsl:value-of select="."/>
652                        </Description>
653                    </xsl:for-each>
654                </descriptions>
655            </xsl:if>
656            <xsl:apply-templates select="child::Keys"/>
657        </MediaFile>
658    </xsl:template>
659
660    <xsl:template match="Access">
661        <Access>
662            <Availability>
663                <xsl:value-of select=" ./Availability"/>
664            </Availability>
665            <Date>
666                <xsl:value-of select=" ./Date"/>
667            </Date>
668            <Owner>
669                <xsl:value-of select=" ./Owner"/>
670            </Owner>
671            <Publisher>
672                <xsl:value-of select=" ./Publisher"/>
673            </Publisher>
674            <xsl:apply-templates select="Contact"/>
675            <xsl:if test="exists(child::Description)">
676                <descriptions>
677                    <xsl:for-each select="Description">
678                        <Description>
679                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
680                            <xsl:value-of select="."/>
681                        </Description>
682                    </xsl:for-each>
683                </descriptions>
684            </xsl:if>
685        </Access>
686    </xsl:template>
687
688    <xsl:template match="WrittenResource">
689        <WrittenResource ref="{generate-id()}">
690            <ResourceLink>
691                <xsl:value-of select=" ./ResourceLink"/>
692            </ResourceLink>
693            <MediaResourceLink>
694                <xsl:value-of select=" ./MediaResourceLink"/>
695            </MediaResourceLink>
696            <Date>
697                <xsl:value-of select=" ./Date"/>
698            </Date>
699            <Type>
700                <xsl:value-of select=" ./Type"/>
701            </Type>
702            <SubType>
703                <xsl:value-of select=" ./SubType"/>
704            </SubType>
705            <Format>
706                <xsl:value-of select=" ./Format"/>
707            </Format>
708            <Size>
709                <xsl:value-of select=" ./Size"/>
710            </Size>
711            <Derivation>
712                <xsl:value-of select=" ./Derivation"/>
713            </Derivation>
714            <CharacterEncoding>
715                <xsl:value-of select=" ./CharacterEncoding"/>
716            </CharacterEncoding>
717            <ContentEncoding>
718                <xsl:value-of select=" ./ContentEncoding"/>
719            </ContentEncoding>
720            <LanguageId>
721                <xsl:value-of select=" ./LanguageId"/>
722            </LanguageId>
723            <Anonymized>
724                <xsl:value-of select=" ./Anonymized"/>
725            </Anonymized>
726            <xsl:apply-templates select="Validation"/>
727            <xsl:apply-templates select="Access"/>
728            <xsl:if test="exists(child::Description)">
729                <descriptions>
730                    <xsl:for-each select="Description">
731                        <Description>
732                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
733                            <xsl:value-of select="."/>
734                        </Description>
735                    </xsl:for-each>
736                </descriptions>
737            </xsl:if>
738            <xsl:apply-templates select="Keys"/>
739        </WrittenResource>
740    </xsl:template>
741
742    <xsl:template match="Validation">
743        <Validation>
744            <Type>
745                <xsl:value-of select=" ./Type"/>
746            </Type>
747            <Methodology>
748                <xsl:value-of select=" ./Methodology"/>
749            </Methodology>
750            <Level>
751                <xsl:value-of select=" ./Level"/>
752            </Level>
753            <xsl:if test="exists(child::Description)">
754                <descriptions>
755                    <xsl:for-each select="Description">
756                        <Description>
757                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
758                            <xsl:value-of select="."/>
759                        </Description>
760                    </xsl:for-each>
761                </descriptions>
762            </xsl:if>
763        </Validation>
764    </xsl:template>
765
766    <xsl:template match="Source">
767        <Source>
768            <Id>
769                <xsl:value-of select=" ./Id"/>
770            </Id>
771            <Format>
772                <xsl:value-of select=" ./Format"/>
773            </Format>
774            <Quality>
775                <xsl:value-of select=" ./Quality"/>
776            </Quality>
777            <xsl:if test="exists(child::CounterPosition)">
778                <CounterPosition>
779                    <Start>
780                        <xsl:apply-templates select="CounterPosition/Start"/>
781                    </Start>
782                    <xsl:if test="exists(descendant::End)">
783                        <End>
784                            <xsl:apply-templates select="CounterPosition/End"/>
785                        </End>
786                    </xsl:if>
787                </CounterPosition>
788            </xsl:if>
789            <xsl:if test="exists(child::TimePosition)">
790                <TimePosition>
791                    <Start>
792                        <xsl:apply-templates select="TimePosition/Start"/>
793                    </Start>
794                    <xsl:if test="exists(descendant::End)">
795                        <End>
796                            <xsl:apply-templates select="TimePosition/End"/>
797                        </End>
798                    </xsl:if>
799                </TimePosition>
800            </xsl:if>
801            <xsl:apply-templates select="Access"/>
802            <xsl:if test="exists(child::Description)">
803                <descriptions>
804                    <xsl:for-each select="Description">
805                        <Description>
806                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
807                            <xsl:value-of select="."/>
808                        </Description>
809                    </xsl:for-each>
810                </descriptions>
811            </xsl:if>
812            <xsl:apply-templates select="child::Keys"/>
813        </Source>
814    </xsl:template>
815
816    <xsl:template match="Anonyms">
817        <Anonyms>
818            <ResourceLink>
819                <xsl:value-of select=" ./ResourceLink"/>
820            </ResourceLink>
821            <xsl:apply-templates select="Access"/>
822        </Anonyms>
823    </xsl:template>
824
825    <xsl:template match="child::References">
826        <References>
827            <xsl:if test="exists(child::Description)">
828                <descriptions>
829                    <xsl:for-each select="Description">
830                        <Description>
831                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
832                            <xsl:value-of select="."/>
833                        </Description>
834                    </xsl:for-each>
835                </descriptions>
836            </xsl:if>
837        </References>
838    </xsl:template>
839
840    <xsl:template name="main">
841        <xsl:for-each
842            select="collection('file:///home/paucas/corpus_copy/corpus_copy/data/corpora?select=*.imdi;recurse=yes;on-error=ignore')">
843            <xsl:result-document href="{document-uri(.)}.cmdi">
844                <xsl:apply-templates select="."/>
845            </xsl:result-document>
846        </xsl:for-each>
847    </xsl:template>
848
849</xsl:stylesheet>