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

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

imdi2clarin: Not all resources have a handle, so we have to check for handle-less nodes.

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