source: metadata/trunk/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl @ 5634

Last change on this file since 5634 was 5634, checked in by Menzo Windhouwer, 10 years ago

M toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

  • generate better reference to the profile XSD
File size: 6.3 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4    xmlns:xs="http://www.w3.org/2001/XMLSchema"
5    xmlns:cmd="http://www.clarin.eu/cmd/"
6    exclude-result-prefixes="xs"
7    version="2.0">
8   
9    <xsl:param name="cmd-envelop-xsd" select="'../../xsd/cmd-envelop.xsd'"/>
10    <xsl:param name="cmd-component-registry" select="'../components/'"/>
11    <xsl:param name="cmd-component-registry-xsd" select="'-1_2.xsd'"/>
12   
13
14    <!-- identity copy -->
15    <xsl:template match="@*|node()">
16        <xsl:copy>
17            <xsl:apply-templates select="@*|node()"/>
18        </xsl:copy>
19    </xsl:template>
20   
21    <!-- try to determine the profile -->
22    <xsl:variable name="profile">
23        <xsl:variable name="header" select="/cmd:CMD/cmd:Header/cmd:MdProfile/replace(.,'.*(clarin.eu:cr1:p_[0-9]).*','$1')"/>
24        <xsl:variable name="schema" select="/cmd:CMD/(@xsi:schemaLocation|@xsi:noNamespaceSchemaLocation)/replace(.,'.*(clarin.eu:cr1:p_[0-9]+).*','$1')"/>
25        <xsl:if test="count($header) gt 1">
26            <xsl:message>WRN: found more then one profile ID (<xsl:value-of select="string-join($header,',')"/>) in a cmd:MdProfile, will use the first one! </xsl:message>
27        </xsl:if>
28        <xsl:if test="count($schema) gt 1">
29            <xsl:message>WRN: found more then one profile ID (<xsl:value-of select="string-join($schema,',')"/>) in a xsi:schemaLocation, will use the first one! </xsl:message>
30        </xsl:if>
31        <xsl:choose>
32            <xsl:when test="exists($header) and exists($schema)">
33                <xsl:if test="($header)[1] ne ($schema)[1]">
34                    <xsl:message>WRN: the profile IDs found in cmd:MdProfile (<xsl:value-of select="($header)[1]"/>) and xsi:schemaLocation (<xsl:value-of select="($schema)[1]"/>), don't agree, will use the xsi:schemaLocation!</xsl:message>
35                </xsl:if>
36                <xsl:value-of select="($schema)[1]"/>
37            </xsl:when>
38            <xsl:when test="exists($header) and empty($schema)">
39                <xsl:value-of select="($header)[1]"/>
40            </xsl:when>
41            <xsl:when test="empty($header) and exists($schema)">
42                <xsl:value-of select="($schema)[1]"/>
43            </xsl:when>
44            <xsl:otherwise>
45                <xsl:message terminate="yes">ERR: the profile ID can't be determined!</xsl:message>
46            </xsl:otherwise>
47        </xsl:choose>
48    </xsl:variable>
49   
50    <!-- CMD version becomes 1.2 -->
51    <xsl:template match="/cmd:CMD/@CMDVersion">
52        <xsl:attribute name="CMDVersion" select="'1.2'"/>
53    </xsl:template>
54   
55    <!-- Create our own xsi:schemaLocation -->
56    <xsl:template match="@xsi:schemaLocation"/>
57   
58    <xsl:template match="@xsi:noNamespaceSchemaLocation"/>
59   
60    <xsl:template match="cmd:CMD">
61        <cmd:CMD>
62            <xsl:namespace name="cmd" select="'http://www.clarin.eu/cmd/'"/>
63            <xsl:namespace name="cmdp" select="$profile"/>
64            <xsl:apply-templates select="@* except (@xsi:schemaLocation|@xsi:noNamespaceSchemaLocation)"/>
65            <xsl:attribute name="xsi:schemaLocation">
66                <xsl:text>http://www.clarin.eu/cmd/ </xsl:text>
67                <xsl:value-of select="$cmd-envelop-xsd"/>
68                <xsl:text> </xsl:text>
69                <xsl:value-of select="$profile"/>
70                <xsl:text> </xsl:text>
71                <xsl:value-of select="$cmd-component-registry"/>
72                <xsl:value-of select="$profile"/>
73                <xsl:value-of select="$cmd-component-registry-xsd"/>
74            </xsl:attribute>
75            <xsl:apply-templates select="cmd:Header"/>
76            <xsl:apply-templates select="cmd:Resources"/>
77            <xsl:apply-templates select="cmd:Resources/cmd:IsPartOfList"/>
78            <xsl:apply-templates select="cmd:Components"/>
79        </cmd:CMD>
80    </xsl:template>
81   
82    <!-- Make sure cmd:Header contains cmd:MdProfile -->
83    <xsl:template match="cmd:Header">
84        <cmd:Header>
85            <xsl:apply-templates select="cmd:MdCreator"/>
86            <xsl:apply-templates select="cmd:MdCreationDate"/>
87            <xsl:apply-templates select="cmd:MdSelfLink"/>
88            <cmd:MdProfile>
89                <xsl:value-of select="$profile"/>
90            </cmd:MdProfile>
91            <xsl:apply-templates select="cmd:MdCollectionDisplayName"/>
92        </cmd:Header>
93    </xsl:template>
94   
95    <!-- Skip cmd:Resources/cmd:IsPartOfList -->
96    <xsl:template match="cmd:Resources">
97        <cmd:Resources>
98            <xsl:apply-templates select="cmd:ResourceProxyList"/>
99            <xsl:apply-templates select="cmd:JournalFileProxyList"/>
100            <xsl:apply-templates select="cmd:ResourceRelationList"/>
101        </cmd:Resources>
102    </xsl:template>
103   
104    <!-- Reshape ResourceRelationList -->
105    <xsl:template match="cmd:ResourceRelation/cmd:RelationType">
106        <cmd:RelationType>
107            <!-- take the string value, ignore deeper structure -->
108            <xsl:value-of select="."/>
109        </cmd:RelationType>
110    </xsl:template>
111   
112    <xsl:template match="cmd:ResourceRelation/cmd:res1">
113        <cmd:Resource>
114            <xsl:apply-templates select="@*"/>
115        </cmd:Resource>
116    </xsl:template>
117   
118    <xsl:template match="cmd:ResourceRelation/cmd:res2">
119        <cmd:Resource>
120            <xsl:apply-templates select="@*"/>
121        </cmd:Resource>
122    </xsl:template>
123   
124    <!-- put envelop in the envelop namespace (it already is, but add the namespace) -->
125    <xsl:template match="/cmd:CMD//*" priority="1">
126        <xsl:element name="cmd:{local-name()}">
127            <xsl:apply-templates select="@*|node()"/>
128        </xsl:element>
129    </xsl:template>
130   
131    <!-- put payload in the profile namespace -->
132    <xsl:template match="cmd:Components//*" priority="2">
133        <xsl:element namespace="{$profile}" name="cmdp:{local-name()}">
134            <xsl:apply-templates select="@*|node()"/>
135        </xsl:element>
136    </xsl:template>
137   
138    <!-- move CMD attributes to the CMD namespace -->
139    <xsl:template match="cmd:Components//@ref">
140        <xsl:attribute name="cmd:ref" select="."/>
141    </xsl:template>
142   
143    <xsl:template match="cmd:Components//@ComponentId">
144        <xsl:attribute name="cmd:ComponentId" select="."/>
145    </xsl:template>
146   
147   
148</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.