source: metadata/trunk/toolkit/xslt/imdi2clarin.xsl @ 4137

Last change on this file since 4137 was 4137, checked in by larlam, 10 years ago

Changed handling of corpus links: for mpi handles, add @format=cmdi (if there is no part identifier already), for plain URLs add a call to the translation service.

  • Property svn:keywords set to Date Revision
File size: 43.8 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3$Rev: 4137 $
4$LastChangedDate: 2013-12-03 14:17:35 +0000 (Tue, 03 Dec 2013) $
5-->
6<xsl:stylesheet xmlns="http://www.clarin.eu/cmd/"
7    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8    xmlns:xs="http://www.w3.org/2001/XMLSchema"
9    xmlns:MPI="http://www.mpi.nl/"
10    version="2.0"
11    xpath-default-namespace="http://www.mpi.nl/IMDI/Schema/IMDI">
12   
13    <!-- Check if Handle System handle references an object hosted by MPI or not. -->
14    <xsl:function 
15        name="MPI:is_MPI_handle"
16        as="xs:boolean">
17        <xsl:param 
18            name="handle" 
19            as="xs:string"/>
20        <xsl:sequence
21            select="starts-with(normalize-space($handle), 'hdl:1839/')"/>
22        <!--<xsl:value-of select="$return_value"/>-->
23    </xsl:function>
24   
25    <!-- Produce URL to view IMDI file at IMDI_URL IMDI Browser based on MPI handle -->
26    <xsl:function 
27        name="MPI:URL_to_view_in_IMDI_Browser_by_handle"
28        as="xs:string">
29        <xsl:param 
30            name="IMDI_URL" 
31            as="xs:string"/>
32        <xsl:sequence 
33            select="concat($IMDI_browser_URL, 'ds/imdi_browser/?openhandle=', encode-for-uri($IMDI_URL))"/> 
34        <!--<xsl:value-of select="$return_value"/>-->
35    </xsl:function>
36   
37    <!-- Produce URL to view IMDI file at IMDI_URL IMDI Browser based on path (= URL) -->
38    <xsl:function 
39        name="MPI:URL_to_view_in_IMDI_Browser_by_path"
40        as="xs:string">
41        <xsl:param 
42            name="IMDI_URL" 
43            as="xs:string"/>
44        <xsl:sequence 
45            select="concat($IMDI_browser_URL, 'ds/imdi_browser/?openpath=', encode-for-uri($IMDI_URL))"/> 
46        <!--<xsl:value-of select="$return_value"/>-->
47    </xsl:function>
48   
49    <!-- 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:
50    java -jar saxon8.jar -it main batch-imdi2clarin.xsl
51    the last template in this file has to be modified to reflect the actual directory name. -->
52    <xsl:output 
53        method="xml" 
54        indent="yes"/>
55
56    <!-- A collection name can be specified for each record. This information is extrinsic to the IMDI file, so it is given as an external parameter. Omit this if you are unsure. -->
57    <xsl:param 
58        name="collection" 
59        select="''"
60        as="xs:string"/>
61
62    <!-- If this optional parameter is defined, the behaviour of this stylesheet changes in the following ways: If no archive handle is
63    available for MdSelfLink, the base URI is inserted there instead. All links (ResourceProxy elements) that contain relative
64    paths are resolved into absolute URIs in the context of the base URI. Omit this if you are unsure. -->
65    <xsl:param 
66        name="uri-base" 
67        select="''"
68        as="xs:string"/>
69   
70    <!-- An URL (composed of scheme and host URL components) pointing to the IMDI browser -->
71    <xsl:param 
72        name="IMDI_browser_URL" 
73        select="'http://corpus1.mpi.nl/'" 
74        as="xs:string"/>
75
76    <!-- A URL pointing to the imdi-to-cmdi translation service, with
77    'IMDI' to be replaced by the URL or handle of the IMDI file. -->
78    <xsl:param name="translation_service_url"
79               select="'http://corpus1.mpi.nl/ds/TranslationService/translate?in=IMDI&amp;outFormat=cmdi'"
80               as="xs:string"/>
81
82    <!-- A prefix for the MdCollectionDisplayName with a meaning similar to the old 'Data provider' facet in the Virtual Language Observatory. -->
83    <xsl:param 
84        name="collection_display_name_prefix" 
85        select="'TLA'" 
86        as="xs:string"/> 
87
88    <!-- definition of the SRU-searchable collections at TLA (for use later on) -->
89    <xsl:variable 
90        name="SruSearchable" 
91        select="('childes','ESF corpus','IFA corpus','MPI CGN','talkbank')"
92        as='xs:string+'/>
93   
94    <xsl:template 
95        name="metatranscriptDelegate">
96        <xsl:param 
97            name="profile" 
98            as="xs:string"
99            select="''"/>
100        <xsl:param 
101            name="MdSelfLink" 
102            as="xs:string"
103            select="''"/>
104       
105        <Header>
106            <MdCreator><xsl:text>imdi2clarin.xsl</xsl:text></MdCreator>
107            <MdCreationDate>
108                <xsl:value-of 
109                    select="format-date(current-date(), '[Y]-[M01]-[D01]')"/>
110            </MdCreationDate>
111            <MdSelfLink>
112                <xsl:value-of 
113                    select="$MdSelfLink"/>           
114            </MdSelfLink>
115            <MdProfile>
116                <xsl:value-of 
117                    select="$profile"/>
118            </MdProfile>
119            <xsl:if 
120                test="not(normalize-space($collection)='')">
121                <MdCollectionDisplayName>
122                    <xsl:choose>
123                        <xsl:when 
124                            test="not(normalize-space($collection_display_name_prefix)='')">
125                            <xsl:value-of 
126                                select="$collection_display_name_prefix"/><xsl:text>: </xsl:text><xsl:value-of 
127                                                                                                     select="$collection"/>       
128                        </xsl:when>
129                        <xsl:otherwise>
130                            <xsl:value-of 
131                                select="$collection"/> 
132                        </xsl:otherwise>
133                    </xsl:choose>
134                </MdCollectionDisplayName>
135            </xsl:if>
136        </Header>
137        <Resources>
138            <ResourceProxyList>
139                <ResourceProxy id="{generate-id()}">
140                    <ResourceType><xsl:text>LandingPage</xsl:text></ResourceType>                       
141                    <xsl:choose>
142                        <!-- ArchiveHandle attribute has MPI handle prefix? If so, generate a LandingPage resource to the original IMDI -->
143                        <xsl:when 
144                            test="MPI:is_MPI_handle(@ArchiveHandle)">
145                            <xsl:choose>
146                                <xsl:when 
147                                    test="ends-with($MdSelfLink,'@format=cmdi')">
148                                    <ResourceRef><xsl:value-of 
149                                        select="concat(substring-before($MdSelfLink,'@format=cmdi'),'@view')"/></ResourceRef>
150                                </xsl:when>
151                                <xsl:otherwise>
152                                    <ResourceRef><xsl:value-of 
153                                        select="concat($MdSelfLink,'@view')"/></ResourceRef>
154<!--                                    <ResourceRef><xsl:value-of
155                                        select="MPI:URL_to_view_in_IMDI_Browser_by_handle(@ArchiveHandle)"/></ResourceRef> -->
156                                </xsl:otherwise>
157                            </xsl:choose>                               
158                        </xsl:when>
159                        <!-- When ArchiveHandle is not an MPI handle, it is necessarily a (non-MPI) handle. Use $uri-base as LandingPage, because the IMDI Browser cannot show external resources. -->
160                        <xsl:when test="not(MPI:is_MPI_handle(@ArchiveHandle)) and not(normalize-space($uri-base)='')">
161                            <ResourceRef><xsl:value-of 
162                                select="MPI:URL_to_view_in_IMDI_Browser_by_path($uri-base)"/></ResourceRef> 
163                        </xsl:when>
164                        <xsl:otherwise>
165                            <xsl:message 
166                                terminate="yes">
167                            <xsl:text>ERROR: @ArchiveHandle is not an MPI handle, but $uri-base is empty. </xsl:text><xsl:value-of select="name()"/>
168                        </xsl:message></xsl:otherwise>
169                    </xsl:choose>     
170                </ResourceProxy>
171               
172                <xsl:apply-templates 
173                    select="//Resources" 
174                    mode="linking"/>
175                <xsl:apply-templates 
176                    select="//Description[not(normalize-space(./@ArchiveHandle)='') or not(normalize-space(./@Link)='')]" 
177                    mode="linking"/>
178                <xsl:apply-templates 
179                    select="//Corpus" 
180                    mode="linking"/>
181                <!-- If this collection name is indicated to be SRU-searchable, add a link to the TLA SRU endpoint -->
182                <xsl:if 
183                    test="not(normalize-space($collection)='') and (some $searchable_collection in $SruSearchable satisfies $collection = $searchable_collection)">
184                    <ResourceProxy id="sru">
185                        <ResourceType><xsl:text>SearchService</xsl:text></ResourceType>
186                        <ResourceRef><xsl:text>http://cqlservlet.mpi.nl/</xsl:text></ResourceRef>
187                    </ResourceProxy>
188                </xsl:if>
189            </ResourceProxyList>
190            <JournalFileProxyList> </JournalFileProxyList>
191            <ResourceRelationList> </ResourceRelationList>
192        </Resources>
193        <Components>
194            <xsl:apply-templates 
195                select="Session"/>
196            <xsl:apply-templates 
197                select="Corpus"/>
198        </Components>
199    </xsl:template>
200
201    <xsl:template 
202        match="METATRANSCRIPT" 
203        name="METATRANSCRIPT_rec">
204        <xsl:param 
205            name="MdSelfLink"
206            select="''"
207            as="xs:string"/>
208        <xsl:choose>
209            <xsl:when 
210                test="not(normalize-space($MdSelfLink))">
211                <xsl:choose>
212                    <!-- MPI handle prefix? Use handle + @format=cmdi suffix -->
213                    <xsl:when 
214                        test="MPI:is_MPI_handle(@ArchiveHandle)">
215                        <xsl:call-template 
216                            name="METATRANSCRIPT_rec">
217                            <xsl:with-param 
218                                name="MdSelfLink" 
219                                as="xs:string"
220                                select="concat(@ArchiveHandle, '@format=cmdi')"/>
221                        </xsl:call-template>
222                    </xsl:when>
223                    <!-- No handle but $uri-base was specified? Then use $uri-base. -->
224                    <xsl:when 
225                        test="not($uri-base='') and normalize-space(@ArchiveHandle)=''">
226                        <xsl:call-template 
227                            name="METATRANSCRIPT_rec">
228                            <xsl:with-param 
229                                name="MdSelfLink" 
230                                as="xs:string"
231                                select="$uri-base"/>
232                        </xsl:call-template>
233                    </xsl:when>
234                    <!-- Other handle prefix? Use handle (e.g. Lund) -->
235                    <xsl:otherwise>
236                        <xsl:call-template 
237                            name="METATRANSCRIPT_rec">
238                            <xsl:with-param 
239                                name="MdSelfLink" 
240                                as="xs:string"
241                                select="@ArchiveHandle"/>
242                        </xsl:call-template>
243                    </xsl:otherwise> 
244                </xsl:choose>
245            </xsl:when>
246            <xsl:otherwise>
247               <xsl:choose>
248                   <xsl:when 
249                       test=".[@Type='SESSION'] or .[@Type='SESSION.Profile']">
250                       <CMD 
251                           CMDVersion="1.1" 
252                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
253                           xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1271859438204/xsd">
254                           <xsl:call-template 
255                               name="metatranscriptDelegate">
256                               <xsl:with-param 
257                                   name="profile"
258                                   as="xs:string"
259                                   select="'clarin.eu:cr1:p_1271859438204'"/>
260                               <xsl:with-param 
261                                   name="MdSelfLink"
262                                   as="xs:string"
263                                   select="$MdSelfLink"/>
264                           </xsl:call-template>
265                       </CMD>
266                   </xsl:when>
267                   <xsl:when test=".[@Type='CORPUS'] or .[@Type='CORPUS.Profile']">
268                       <CMD 
269                           CMDVersion="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
270                           xsi:schemaLocation="http://www.clarin.eu/cmd/ http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/clarin.eu:cr1:p_1274880881885/xsd">
271                           <xsl:call-template 
272                               name="metatranscriptDelegate">
273                               <xsl:with-param 
274                                   name="profile"
275                                   select="'clarin.eu:cr1:p_1274880881885'"/>
276                               <xsl:with-param 
277                                   name="MdSelfLink"
278                                   as="xs:string"
279                                   select="$MdSelfLink"/>
280                           </xsl:call-template>
281                       </CMD>
282                   </xsl:when>
283                   <xsl:otherwise>
284                       <!-- Currently we are only processing 'SESSION' and 'CORPUS' types. The error displayed can be used to filter out erroneous files after processing -->
285                       <xsl:message 
286                           terminate="yes">
287                           <xsl:text>ERROR: Invalid METATRANSCRIPT type: </xsl:text><xsl:value-of select="name()"/>
288                       </xsl:message>
289                    </xsl:otherwise>
290               </xsl:choose>
291            </xsl:otherwise>
292        </xsl:choose>
293    </xsl:template>
294
295    <xsl:template 
296        match="Corpus">
297        <imdi-corpus>
298            <Corpus>
299                <xsl:apply-templates select="child::Name"/>
300                <xsl:apply-templates select="child::Title"/>
301                <xsl:if test="exists(child::Description)">
302                    <descriptions>
303                        <xsl:variable name="reflist">
304                            <xsl:for-each select="Description">
305                                <xsl:if test="not(normalize-space(@ArchiveHandle)='') or not(normalize-space(@Link)='')">
306                                    <xsl:value-of select="generate-id()"/>
307                                    <xsl:text> </xsl:text>
308                                </xsl:if>
309                            </xsl:for-each> 
310                        </xsl:variable>
311                       
312                        <xsl:attribute name="ref" select="normalize-space($reflist)"></xsl:attribute>
313                       
314                        <xsl:for-each select="Description">
315                        <Description>
316                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
317                            <xsl:value-of select="."/>
318                        </Description>
319                        </xsl:for-each>
320                       
321                    </descriptions>
322                </xsl:if>
323                <xsl:if test="exists(child::CorpusLink)">
324                    <xsl:for-each select="CorpusLink">
325                        <CorpusLink>
326                            <CorpusLinkContent>
327                                <!--<xsl:attribute name="ArchiveHandle" select="@ArchiveHandle"/>-->
328                                <xsl:attribute name="Name" select="@Name"/>
329                                <xsl:value-of select="."/>
330                            </CorpusLinkContent>
331                        </CorpusLink>
332                    </xsl:for-each>
333                </xsl:if>
334            </Corpus>
335        </imdi-corpus>
336    </xsl:template>
337
338    <xsl:template 
339        match="Corpus" mode="linking">
340        <xsl:for-each select="CorpusLink">
341            <ResourceProxy id="{generate-id()}">
342                <ResourceType><xsl:text>Metadata</xsl:text></ResourceType>
343                <ResourceRef>
344                    <xsl:choose>
345                        <xsl:when test="not(normalize-space(./@ArchiveHandle)='')">
346                          <xsl:choose>
347                            <xsl:when test="MPI:is_MPI_handle(@ArchiveHandle) and not(contains(./@ArchiveHandle, '@'))">
348                              <xsl:value-of select="./@ArchiveHandle"/><xsl:text>@format=cmdi</xsl:text>
349                            </xsl:when>
350                            <xsl:otherwise>
351                              <xsl:value-of select="./@ArchiveHandle"/>
352                            </xsl:otherwise>
353                          </xsl:choose>
354                        </xsl:when>
355                        <xsl:when test="starts-with(., 'hdl:')">
356                            <xsl:value-of select="."/>
357                        </xsl:when>
358                        <xsl:when test="$uri-base=''"><xsl:value-of select="replace($translation_service_url, 'IMDI', .)"/></xsl:when>
359                        <xsl:otherwise>
360                            <xsl:value-of
361                                select="replace($translation_service_url,'IMDI',resolve-uri(normalize-space(.), $uri-base))"/>
362                        </xsl:otherwise>
363                    </xsl:choose>
364                </ResourceRef>
365            </ResourceProxy>
366        </xsl:for-each>
367    </xsl:template>
368
369    <!-- Create ResourceProxy for MediaFile and WrittenResource -->
370    <xsl:template 
371        match="Resources" 
372        mode="linking">
373        <xsl:for-each select="MediaFile">
374            <xsl:call-template 
375                name="CreateResourceProxyTypeResource"/>       
376        </xsl:for-each>
377        <xsl:for-each 
378            select="WrittenResource">
379            <xsl:call-template 
380                name="CreateResourceProxyTypeResource"/>
381        </xsl:for-each>
382    </xsl:template>
383   
384    <!-- Create ResourceProxy for Info files -->
385    <xsl:template 
386        match="//Description[@ArchiveHandle or @Link]" 
387        mode="linking">
388        <xsl:call-template 
389            name="CreateResourceProxyTypeResource"/>
390    </xsl:template> 
391   
392    <!-- To be called during the creation of the ResourceProxyList (in linking mode) -->
393    <xsl:template 
394        name="CreateResourceProxyTypeResource">
395        <ResourceProxy id="{generate-id()}">
396            <ResourceType>
397                <xsl:if test="exists(Format) and not(empty(Format))">
398                    <xsl:attribute name="mimetype">
399                        <xsl:value-of select="./Format"/>
400                    </xsl:attribute>
401                </xsl:if>
402                <xsl:text>Resource</xsl:text>
403            </ResourceType>
404            <ResourceRef>
405                <xsl:choose>
406                    <xsl:when test="not(normalize-space(ResourceLink/@ArchiveHandle)='')">
407                        <xsl:value-of select="ResourceLink/@ArchiveHandle"/>
408                    </xsl:when>
409                    <xsl:when test="not($uri-base='')">
410                        <xsl:value-of
411                            select="resolve-uri(normalize-space(ResourceLink/.), $uri-base)"/>
412                    </xsl:when>
413                    <!-- for info files the @ArchiveHandle or @Link is part of the Description element - preference for ArchiveHandle -->
414                    <xsl:when test="not(normalize-space(@ArchiveHandle)='')">
415                        <xsl:value-of select="@ArchiveHandle"/>
416                    </xsl:when>
417                    <xsl:when test="not(normalize-space(@Link)='')">
418                        <xsl:value-of select="@Link"/>
419                    </xsl:when>
420                </xsl:choose>
421            </ResourceRef>
422        </ResourceProxy>
423    </xsl:template>
424   
425    <xsl:template 
426        match="Session">
427        <Session>
428            <xsl:apply-templates select="child::Name"/>
429            <xsl:apply-templates select="child::Title"/>
430            <xsl:apply-templates select="child::Date"/>
431            <xsl:if test="exists(child::Description)">
432                <descriptions>
433                    <xsl:variable name="reflist">
434                        <xsl:for-each select="Description">
435                            <xsl:if test="not(normalize-space(@ArchiveHandle)='') or not(normalize-space(@Link)='')">
436                                <xsl:value-of select="generate-id()"/>
437                                <xsl:text> </xsl:text>
438                            </xsl:if>
439                        </xsl:for-each> 
440                    </xsl:variable>
441                   
442                    <xsl:if test="not(normalize-space($reflist)='')">
443                        <xsl:attribute name="ref" select="normalize-space($reflist)"></xsl:attribute>
444                    </xsl:if>
445
446                    <xsl:for-each select="Description">
447                        <Description>
448                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
449                            <xsl:value-of select="."/>
450                        </Description>
451                    </xsl:for-each>
452                </descriptions>
453            </xsl:if>
454            <xsl:apply-templates select="child::MDGroup"/>
455            <xsl:apply-templates select="child::Resources" mode="regular"/>
456            <xsl:apply-templates select="child::References"/>
457        </Session>
458    </xsl:template>
459
460    <xsl:template 
461        match="child::Name">
462        <Name>
463            <xsl:value-of select="."/>
464        </Name>
465    </xsl:template>
466
467    <xsl:template 
468        match="child::Title">
469        <Title>
470            <xsl:value-of select="."/>
471        </Title>
472    </xsl:template>
473
474    <xsl:template 
475        match="child::Date">
476        <Date>
477            <xsl:value-of select="."/>
478        </Date>
479    </xsl:template>
480
481    <xsl:template 
482        match="child::MDGroup">
483        <MDGroup>
484            <xsl:apply-templates 
485                select="child::Location"/>
486            <xsl:apply-templates 
487                select="child::Project"/>
488            <xsl:apply-templates 
489                select="child::Keys"/>
490            <xsl:apply-templates 
491                select="child::Content"/>
492            <xsl:apply-templates 
493                select="child::Actors"/>
494        </MDGroup>
495    </xsl:template>
496
497    <xsl:template 
498        match="Location">
499        <Location>
500            <Continent>
501                <xsl:value-of 
502                    select="child::Continent"/>
503            </Continent>
504            <Country>
505                <xsl:value-of 
506                    select="child::Country"/>
507            </Country>
508            <xsl:if 
509                test="exists(child::Region)">
510                <Region>
511                    <xsl:value-of 
512                        select="child::Region"/>
513                </Region>
514            </xsl:if>
515            <xsl:if 
516                test="exists(child::Address)">
517                <Address>
518                    <xsl:value-of 
519                        select="child::Address"/>
520                </Address>
521            </xsl:if>
522        </Location>
523    </xsl:template>
524
525    <xsl:template 
526        match="Project">
527        <Project>
528            <Name>
529                <xsl:value-of select="child::Name"/>
530            </Name>
531            <Title>
532                <xsl:value-of select="child::Title"/>
533            </Title>
534            <Id>
535                <xsl:value-of select="child::Id"/>
536            </Id>
537            <xsl:apply-templates select="Contact"/>
538            <xsl:if test="exists(child::Description)">
539                <descriptions>
540                    <xsl:for-each select="Description">
541                        <Description>
542                            <xsl:attribute 
543                                name="LanguageId" 
544                                select="@LanguageId"/>
545                            <xsl:value-of select="."/>
546                        </Description>
547                    </xsl:for-each>
548                </descriptions>
549            </xsl:if>
550        </Project>
551    </xsl:template>
552
553    <xsl:template 
554        match="Contact">
555        <Contact>
556            <Name>
557                <xsl:value-of select="child::Name"/>
558            </Name>
559            <Address>
560                <xsl:value-of select="child::Address"/>
561            </Address>
562            <Email>
563                <xsl:value-of select="child::Email"/>
564            </Email>
565            <Organisation>
566                <xsl:value-of select="child::Organisation"/>
567            </Organisation>
568        </Contact>
569    </xsl:template>
570
571    <xsl:template 
572        match="Keys">
573        <Keys>
574            <xsl:for-each select="Key">
575                <Key>
576                    <xsl:attribute name="Name">
577                        <xsl:value-of select="@Name"/>
578                    </xsl:attribute>
579                    <xsl:value-of select="."/>
580                </Key>
581            </xsl:for-each>
582        </Keys>
583    </xsl:template>
584
585    <xsl:template 
586        match="Content">
587        <Content>
588            <Genre>
589                <xsl:value-of select="child::Genre"/>
590            </Genre>
591            <xsl:if test="exists(child::SubGenre)">
592                <SubGenre>
593                    <xsl:value-of select="child::SubGenre"/>
594                </SubGenre>
595            </xsl:if>
596            <xsl:if test="exists(child::Task)">
597                <Task>
598                    <xsl:value-of select="child::Task"/>
599                </Task>
600            </xsl:if>
601            <xsl:if test="exists(child::Modalities)">
602                <Modalities>
603                    <xsl:value-of select="child::Modalities"/>
604                </Modalities>
605            </xsl:if>
606            <xsl:if test="exists(child::Subject)">
607                <Subject>
608                    <xsl:value-of select="child::Subject"/>
609                </Subject>
610            </xsl:if>
611            <xsl:apply-templates select="child::CommunicationContext"/>
612            <xsl:apply-templates select="child::Languages" mode="content"/>
613            <xsl:apply-templates select="child::Keys"/>
614            <xsl:if test="exists(child::Description)">
615                <descriptions>
616                    <xsl:for-each select="Description">
617                        <Description>
618                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
619                            <xsl:value-of select="."/>
620                        </Description>
621                    </xsl:for-each>
622                </descriptions>
623            </xsl:if>
624        </Content>
625
626    </xsl:template>
627
628    <xsl:template 
629        match="CommunicationContext">
630        <CommunicationContext>
631            <xsl:if test="exists(child::Interactivity)">
632                <Interactivity>
633                    <xsl:value-of select="child::Interactivity"/>
634                </Interactivity>
635            </xsl:if>
636            <xsl:if test="exists(child::PlanningType)">
637                <PlanningType>
638                    <xsl:value-of select="child::PlanningType"/>
639                </PlanningType>
640            </xsl:if>
641            <xsl:if test="exists(child::Involvement)">
642                <Involvement>
643                    <xsl:value-of select="child::Involvement"/>
644                </Involvement>
645            </xsl:if>
646            <xsl:if test="exists(child::SocialContext)">
647                <SocialContext>
648                    <xsl:value-of select="child::SocialContext"/>
649                </SocialContext>
650            </xsl:if>
651            <xsl:if test="exists(child::EventStructure)">
652                <EventStructure>
653                    <xsl:value-of select="child::EventStructure"/>
654                </EventStructure>
655            </xsl:if>
656            <xsl:if test="exists(child::Channel)">
657                <Channel>
658                    <xsl:value-of select="child::Channel"/>
659                </Channel>
660            </xsl:if>
661        </CommunicationContext>
662    </xsl:template>
663
664    <xsl:template 
665        match="Languages" 
666        mode="content">
667        <Content_Languages>
668            <xsl:if test="exists(child::Description)">
669                <descriptions>
670                    <xsl:for-each 
671                        select="Description">
672                        <Description>
673                            <xsl:attribute 
674                                name="LanguageId" 
675                                select="@LanguageId"/>
676                            <xsl:value-of 
677                                select="."/>
678                        </Description>
679                    </xsl:for-each>
680                </descriptions>
681            </xsl:if>
682            <xsl:for-each 
683                select="Language">
684                <Content_Language>
685                    <Id>
686                        <xsl:value-of 
687                            select=" ./Id"/>
688                    </Id>
689                    <Name>
690                        <xsl:value-of 
691                            select=" ./Name"/>
692                    </Name>
693                    <xsl:if 
694                        test="exists(child::Dominant)">
695                        <Dominant>
696                            <xsl:value-of 
697                                select=" ./Dominant"/>
698                        </Dominant>
699                    </xsl:if>
700                    <xsl:if 
701                        test="exists(child::SourceLanguage)">
702                        <SourceLanguage>
703                            <xsl:value-of 
704                                select=" ./SourceLanguage"/>
705                        </SourceLanguage>
706                    </xsl:if>
707                    <xsl:if 
708                        test="exists(child::TargetLanguage)">
709                        <TargetLanguage>
710                            <xsl:value-of 
711                                select=" ./TargetLanguage"/>
712                        </TargetLanguage>
713                    </xsl:if>
714                    <xsl:if 
715                        test="exists(child::Description)">
716                        <descriptions>
717                            <xsl:for-each 
718                                select="Description">
719                                <Description>
720                                    <xsl:attribute 
721                                        name="LanguageId" 
722                                        select="@LanguageId"/>
723                                    <xsl:value-of select="."/>
724                                </Description>
725                            </xsl:for-each>
726                        </descriptions>
727                    </xsl:if>
728                </Content_Language>
729            </xsl:for-each>
730        </Content_Languages>
731    </xsl:template>
732
733    <xsl:template 
734        match="Actors">
735        <Actors>
736            <xsl:if test="exists(child::Description)">
737                <descriptions>
738                    <xsl:for-each select="Description">
739                        <Description>
740                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
741                            <xsl:value-of select="."/>
742                        </Description>
743                    </xsl:for-each>
744                </descriptions>
745            </xsl:if>
746            <xsl:for-each select="Actor">
747                <Actor>
748                    <Role>
749                        <xsl:value-of select=" ./Role"/>
750                    </Role>
751                    <Name>
752                        <xsl:value-of select=" ./Name"/>
753                    </Name>
754                    <FullName>
755                        <xsl:value-of select=" ./FullName"/>
756                    </FullName>
757                    <Code>
758                        <xsl:value-of select=" ./Code"/>
759                    </Code>
760                    <FamilySocialRole>
761                        <xsl:value-of select=" ./FamilySocialRole"/>
762                    </FamilySocialRole>
763                    <EthnicGroup>
764                        <xsl:value-of select=" ./EthnicGroup"/>
765                    </EthnicGroup>
766                    <Age>
767                        <xsl:value-of select=" ./Age"/>
768                    </Age>
769                    <BirthDate>
770                        <xsl:value-of select=" ./BirthDate"/>
771                    </BirthDate>
772                    <Sex>
773                        <xsl:value-of select=" ./Sex"/>
774                    </Sex>
775                    <Education>
776                        <xsl:value-of select=" ./Education"/>
777                    </Education>
778                    <Anonymized>
779                        <xsl:value-of select=" ./Anonymized"/>
780                    </Anonymized>
781                    <xsl:apply-templates select="Contact"/>
782                    <xsl:apply-templates select="child::Keys"/>
783                    <xsl:if test="exists(child::Description)">
784                        <descriptions>
785                            <xsl:for-each select="Description">
786                                <Description>
787                                    <xsl:attribute name="LanguageId" select="@LanguageId"/>
788                                    <xsl:value-of select="."/>
789                                </Description>
790                            </xsl:for-each>
791                        </descriptions>
792                    </xsl:if>
793                    <xsl:apply-templates select="child::Languages" mode="actor"/>
794                </Actor>
795            </xsl:for-each>
796        </Actors>
797    </xsl:template>
798
799    <xsl:template 
800        match="Languages" 
801        mode="actor">
802        <Actor_Languages>
803            <xsl:if test="exists(child::Description)">
804                <descriptions>
805                    <xsl:for-each select="Description">
806                        <Description>
807                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
808                            <xsl:value-of select="."/>
809                        </Description>
810                    </xsl:for-each>
811                </descriptions>
812            </xsl:if>
813            <xsl:for-each select="Language">
814                <Actor_Language>
815                    <Id>
816                        <xsl:value-of select=" ./Id"/>
817                    </Id>
818                    <Name>
819                        <xsl:value-of select=" ./Name"/>
820                    </Name>
821                    <xsl:if test="exists(child::MotherTongue)">
822                        <MotherTongue>
823                            <xsl:value-of select=" ./MotherTongue"/>
824                        </MotherTongue>
825                    </xsl:if>
826                    <xsl:if test="exists(child::PrimaryLanguage)">
827                        <PrimaryLanguage>
828                            <xsl:value-of select=" ./PrimaryLanguage"/>
829                        </PrimaryLanguage>
830                    </xsl:if>
831                    <xsl:if test="exists(child::Description)">
832                        <descriptions>
833                            <xsl:for-each select="Description">
834                                <Description>
835                                    <xsl:attribute name="LanguageId" select="@LanguageId"/>
836                                    <xsl:value-of select="."/>
837                                </Description>
838                            </xsl:for-each>
839                        </descriptions>
840                    </xsl:if>
841                </Actor_Language>
842            </xsl:for-each>
843        </Actor_Languages>
844    </xsl:template>
845
846    <xsl:template 
847        match="child::Resources" 
848        mode="regular">
849        <Resources>
850            <xsl:apply-templates select="MediaFile"/>
851            <xsl:apply-templates select="WrittenResource"/>
852            <xsl:apply-templates select="Source"/>
853            <xsl:apply-templates select="Anonyms"/>
854        </Resources>
855    </xsl:template>
856
857    <xsl:template 
858        match="MediaFile">
859        <MediaFile 
860            ref="{generate-id()}">
861            <ResourceLink>
862                <xsl:value-of 
863                    select=" ./ResourceLink"/>
864            </ResourceLink>
865            <Type>
866                <xsl:value-of 
867                    select=" ./Type"/>
868            </Type>
869            <Format>
870                <xsl:value-of 
871                    select=" ./Format"/>
872            </Format>
873            <Size>
874                <xsl:value-of 
875                    select=" ./Size"/>
876            </Size>
877            <Quality>
878                <xsl:value-of 
879                    select=" ./Quality"/>
880            </Quality>
881            <RecordingConditions>
882                <xsl:value-of 
883                    select=" ./RecordingConditions"/>
884            </RecordingConditions>
885            <TimePosition>
886                <Start>
887                    <xsl:apply-templates 
888                        select="TimePosition/Start"/>
889                </Start>
890                <xsl:if test="exists(descendant::End)">
891                    <End>
892                        <xsl:apply-templates 
893                            select="TimePosition/End"/>
894                    </End>
895                </xsl:if>
896            </TimePosition>
897            <xsl:apply-templates select="Access"/>
898            <xsl:if test="exists(child::Description)">
899                <descriptions>
900                    <xsl:for-each select="Description">
901                        <Description>
902                            <xsl:attribute 
903                                name="LanguageId" 
904                                select="@LanguageId"/>
905                            <xsl:value-of select="."/>
906                        </Description>
907                    </xsl:for-each>
908                </descriptions>
909            </xsl:if>
910            <xsl:apply-templates select="child::Keys"/>
911        </MediaFile>
912    </xsl:template>
913
914    <xsl:template 
915        match="Access">
916        <Access>
917            <Availability>
918                <xsl:value-of select=" ./Availability"/>
919            </Availability>
920            <Date>
921                <xsl:value-of select=" ./Date"/>
922            </Date>
923            <Owner>
924                <xsl:value-of select=" ./Owner"/>
925            </Owner>
926            <Publisher>
927                <xsl:value-of select=" ./Publisher"/>
928            </Publisher>
929            <xsl:apply-templates select="Contact"/>
930            <xsl:if test="exists(child::Description)">
931                <descriptions>
932                    <xsl:for-each select="Description">
933                        <Description>
934                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
935                            <xsl:value-of select="."/>
936                        </Description>
937                    </xsl:for-each>
938                </descriptions>
939            </xsl:if>
940        </Access>
941    </xsl:template>
942
943    <xsl:template 
944        match="WrittenResource">
945        <WrittenResource ref="{generate-id()}">
946            <ResourceLink>
947                <xsl:value-of select=" ./ResourceLink"/>
948            </ResourceLink>
949            <MediaResourceLink>
950                <xsl:value-of select=" ./MediaResourceLink"/>
951            </MediaResourceLink>
952            <Date>
953                <xsl:value-of select=" ./Date"/>
954            </Date>
955            <Type>
956                <xsl:value-of select=" ./Type"/>
957            </Type>
958            <SubType>
959                <xsl:value-of select=" ./SubType"/>
960            </SubType>
961            <Format>
962                <xsl:value-of select=" ./Format"/>
963            </Format>
964            <Size>
965                <xsl:value-of select=" ./Size"/>
966            </Size>
967            <Derivation>
968                <xsl:value-of select=" ./Derivation"/>
969            </Derivation>
970            <CharacterEncoding>
971                <xsl:value-of select=" ./CharacterEncoding"/>
972            </CharacterEncoding>
973            <ContentEncoding>
974                <xsl:value-of select=" ./ContentEncoding"/>
975            </ContentEncoding>
976            <LanguageId>
977                <xsl:value-of select=" ./LanguageId"/>
978            </LanguageId>
979            <Anonymized>
980                <xsl:value-of select=" ./Anonymized"/>
981            </Anonymized>
982            <xsl:apply-templates select="Validation"/>
983            <xsl:apply-templates select="Access"/>
984            <xsl:if test="exists(child::Description)">
985                <descriptions>
986                    <xsl:for-each select="Description">
987                        <Description>
988                            <xsl:attribute 
989                                name="LanguageId" 
990                                select="@LanguageId"/>
991                            <xsl:value-of select="."/>
992                        </Description>
993                    </xsl:for-each>
994                </descriptions>
995            </xsl:if>
996            <xsl:apply-templates select="Keys"/>
997        </WrittenResource>
998    </xsl:template>
999
1000    <xsl:template 
1001        match="Validation">
1002        <Validation>
1003            <Type>
1004                <xsl:value-of select=" ./Type"/>
1005            </Type>
1006            <Methodology>
1007                <xsl:value-of select=" ./Methodology"/>
1008            </Methodology>
1009            <Level>
1010                <xsl:value-of select=" ./Level"/>
1011            </Level>
1012            <xsl:if test="exists(child::Description)">
1013                <descriptions>
1014                    <xsl:for-each select="Description">
1015                        <Description>
1016                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
1017                            <xsl:value-of select="."/>
1018                        </Description>
1019                    </xsl:for-each>
1020                </descriptions>
1021            </xsl:if>
1022        </Validation>
1023    </xsl:template>
1024
1025    <xsl:template 
1026        match="Source">
1027        <Source>
1028            <Id>
1029                <xsl:value-of select=" ./Id"/>
1030            </Id>
1031            <Format>
1032                <xsl:value-of select=" ./Format"/>
1033            </Format>
1034            <Quality>
1035                <xsl:value-of select=" ./Quality"/>
1036            </Quality>
1037            <xsl:if test="exists(child::CounterPosition)">
1038                <CounterPosition>
1039                    <Start>
1040                        <xsl:apply-templates select="CounterPosition/Start"/>
1041                    </Start>
1042                    <xsl:if test="exists(descendant::End)">
1043                        <End>
1044                            <xsl:apply-templates select="CounterPosition/End"/>
1045                        </End>
1046                    </xsl:if>
1047                </CounterPosition>
1048            </xsl:if>
1049            <xsl:if test="exists(child::TimePosition)">
1050                <TimePosition>
1051                    <Start>
1052                        <xsl:apply-templates select="TimePosition/Start"/>
1053                    </Start>
1054                    <xsl:if test="exists(descendant::End)">
1055                        <End>
1056                            <xsl:apply-templates select="TimePosition/End"/>
1057                        </End>
1058                    </xsl:if>
1059                </TimePosition>
1060            </xsl:if>
1061            <xsl:apply-templates select="Access"/>
1062            <xsl:if test="exists(child::Description)">
1063                <descriptions>
1064                    <xsl:for-each select="Description">
1065                        <Description>
1066                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
1067                            <xsl:value-of select="."/>
1068                        </Description>
1069                    </xsl:for-each>
1070                </descriptions>
1071            </xsl:if>
1072            <xsl:apply-templates select="child::Keys"/>
1073        </Source>
1074    </xsl:template>
1075
1076    <xsl:template 
1077        match="Anonyms">
1078        <Anonyms>
1079            <ResourceLink>
1080                <xsl:value-of select=" ./ResourceLink"/>
1081            </ResourceLink>
1082            <xsl:apply-templates select="Access"/>
1083        </Anonyms>
1084    </xsl:template>
1085
1086    <xsl:template 
1087        match="child::References">
1088        <References>
1089            <xsl:if test="exists(child::Description)">
1090                <descriptions>
1091                    <xsl:for-each select="Description">
1092                        <Description>
1093                            <xsl:attribute name="LanguageId" select="@LanguageId"/>
1094                            <xsl:value-of select="."/>
1095                        </Description>
1096                    </xsl:for-each>
1097                </descriptions>
1098            </xsl:if>
1099        </References>
1100    </xsl:template>
1101
1102    <xsl:template 
1103        name="main">
1104        <xsl:for-each
1105            select="collection('file:///home/paucas/corpus_copy/corpus_copy/data/corpora?select=*.imdi;recurse=yes;on-error=ignore')">
1106            <xsl:result-document href="{document-uri(.)}.cmdi">
1107                <xsl:apply-templates select="."/>
1108            </xsl:result-document>
1109        </xsl:for-each>
1110    </xsl:template>
1111
1112</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.