source: metadata/branches/clarin2imdi-resourcerefs/toolkit/xslt/imdi2clarin.xsl @ 2549

Last change on this file since 2549 was 2549, checked in by twagoo, 11 years ago

Added transformation of resourceId and resourceRef for writtenresoure and actor

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