source: metadata/trunk/toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl @ 6907

Last change on this file since 6907 was 6907, checked in by Menzo Windhouwer, 9 years ago

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

  • unescaped escaped CMDI 1.2 attributes
  • warn when a @ref contains multiple resource proxy references, and use only the first one

M toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl

  • escape attributes that would clash with CMDI 1.1 reserved attributes

M toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd
A toolkit/src/main/resources/toolkit/sch/cmd-component-best-practices.sch

  • moved Schematron rules which are validate best practices

M toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

  • removed obsolete commented out code
File size: 4.8 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:cue="http://www.clarin.eu/cmdi/cues/1"
6    exclude-result-prefixes="xs"
7    version="2.0">
8
9    <xsl:param name="cmd-component-xsd" select="'http://infra.clarin.eu/cmd/general-component-schema.xsd'"/>
10   
11    <xsl:param name="escape" select="'ccmmddii_'"/>
12   
13    <!-- identity copy -->
14    <xsl:template match="@*">
15        <xsl:copy/>
16    </xsl:template>
17   
18    <xsl:template match="node()">
19        <xsl:copy>
20            <xsl:apply-templates select="@*|node()"/>
21        </xsl:copy>
22    </xsl:template>
23
24    <!-- refer to cmd-component.xsd -->
25    <xsl:template match="@xsi:noNamespaceSchemaLocation" priority="1">
26        <xsl:attribute name="xsi:noNamespaceSchemaLocation" select="$cmd-component-xsd"/>
27    </xsl:template>
28
29    <!-- add CMD_ prefix -->
30    <xsl:template match="ComponentSpec" priority="1">
31        <CMD_ComponentSpec>
32            <xsl:apply-templates select="@*|node()"/>
33        </CMD_ComponentSpec>
34    </xsl:template>
35
36    <xsl:template match="Component" priority="1">
37        <CMD_Component>
38            <xsl:apply-templates select="@*|node()"/>
39        </CMD_Component>
40    </xsl:template>
41   
42    <xsl:template match="Element" priority="1">
43        <CMD_Element>
44            <xsl:apply-templates select="@*"/>
45            <xsl:apply-templates select="Documentation"/>
46            <xsl:apply-templates select="node() except Documentation"/>
47        </CMD_Element>
48    </xsl:template>
49   
50    <!-- remove Status and friends -->
51    <xsl:template match="Header/Status" priority="1"/>
52    <xsl:template match="Header/StatusComment" priority="1"/>
53    <xsl:template match="Header/Successor" priority="1"/>
54   
55    <!-- turn <Documentation/> into @Documentation -->
56    <xsl:template match="Documentation" priority="1">
57        <xsl:choose>
58            <xsl:when test="exists(../Documentation[@xml:lang=('en','eng')])">
59                <xsl:if test="@xml:lang=('en','eng') and empty(preceding-sibling::Documentation[@xml:lang=('en','eng')])">
60                    <!-- first english documentation -->
61                    <xsl:attribute name="Documentation" select="."/>
62                </xsl:if>
63            </xsl:when>
64            <xsl:when test="exists(../Documentation[normalize-space(@xml:lang)=''])">
65                <xsl:if test="normalize-space(@xml:lang)='' and empty(preceding-sibling::Documentation[normalize-space(@xml:lang)=''])">
66                    <!-- first general documentation -->
67                    <xsl:attribute name="Documentation" select="."/>
68                </xsl:if>
69            </xsl:when>
70            <xsl:when test="empty(preceding-sibling::Documentation)">
71                <!-- first documentation -->
72                <xsl:attribute name="Documentation" select="."/>
73            </xsl:when>
74        </xsl:choose>
75    </xsl:template>
76
77    <!-- remove Vocabulary level, incl. attributes -->
78    <xsl:template match="Vocabulary" priority="1">
79        <xsl:apply-templates select="node()"/>
80    </xsl:template>
81   
82    <!-- turn Attribute child elements into attributes -->
83    <xsl:template match="Attribute" priority="1">
84        <xsl:variable name="name">
85            <xsl:choose>
86                <xsl:when test="exists(parent::AttributeList/parent::Component) and Name=('ref','ComponentId')">
87                    <xsl:message>WRN: user-defined ref and ComponentId attributes for a Component are not supported by CMDI 1.1! Adding the <xsl:value-of select="$escape"/> prefix</xsl:message>
88                    <xsl:value-of select="concat($escape,@name)"/>
89                </xsl:when>
90                <xsl:otherwise>
91                    <xsl:value-of select="@name"/>
92                </xsl:otherwise>
93            </xsl:choose>
94        </xsl:variable>
95        <Attribute>
96            <Name>
97                <xsl:value-of select="$name"/>
98            </Name>
99            <xsl:if test="normalize-space(@ConceptLink)!=''">
100                <ConceptLink>
101                    <xsl:value-of select="@ConceptLink"/>
102                </ConceptLink>
103            </xsl:if>
104            <xsl:if test="normalize-space(@ValueScheme)!=''">
105                <Type>
106                    <xsl:value-of select="@ValueScheme"/>
107                </Type>
108            </xsl:if>
109            <!-- @Required is skipped -->
110            <xsl:apply-templates select="node()"/>
111        </Attribute>
112    </xsl:template>
113   
114    <!-- remove cue namespace for DisplayPriority -->
115    <xsl:template match="@cue:DisplayPriority" priority="2">
116        <xsl:attribute name="DisplayPriority">
117            <xsl:value-of select="."/>
118        </xsl:attribute>
119    </xsl:template>
120   
121    <!-- remove other cue attributes -->
122    <xsl:template match="@cue:*" priority="1"/>
123
124</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.