1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | |
---|
3 | <!-- |
---|
4 | $Revision: 14516 $ |
---|
5 | $Date: 2009-03-25 16:36:01 +0100 (Wed, 25 Mar 2009) $ |
---|
6 | --> |
---|
7 | |
---|
8 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" |
---|
9 | xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dcr="http://www.isocat.org"> |
---|
10 | <xsl:strip-space elements="*"/> |
---|
11 | <xsl:include href="comp2schema-header.xsl"/> |
---|
12 | |
---|
13 | <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> |
---|
14 | |
---|
15 | <xsl:template match="/CMD_ComponentSpec"> |
---|
16 | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dcr="http://www.isocat.org"> |
---|
17 | <xs:element name="CMD"> |
---|
18 | <xs:complexType> |
---|
19 | <xs:sequence> |
---|
20 | |
---|
21 | <!-- First produce header elements (description and resources)--> |
---|
22 | <xsl:call-template name="PrintHeader"/> |
---|
23 | |
---|
24 | <!-- Then generate the components --> |
---|
25 | <xs:element name="Components"> |
---|
26 | <xs:complexType> |
---|
27 | <xs:sequence> |
---|
28 | <!--Start with processing the root component once and then process everything else recursively--> |
---|
29 | <xsl:apply-templates select="/CMD_ComponentSpec/CMD_Component"/> |
---|
30 | </xs:sequence> |
---|
31 | </xs:complexType> |
---|
32 | </xs:element> |
---|
33 | |
---|
34 | <!-- Generate the footer --> |
---|
35 | </xs:sequence> |
---|
36 | </xs:complexType> |
---|
37 | </xs:element> |
---|
38 | </xs:schema> |
---|
39 | </xsl:template> |
---|
40 | |
---|
41 | <!-- convert all components --> |
---|
42 | <xsl:template match="CMD_Component"> |
---|
43 | |
---|
44 | <!-- TODO: maybe there is a more elegant construction than this choose --> |
---|
45 | <xsl:choose> |
---|
46 | <!-- ConceptLink attribute exists --> |
---|
47 | <xsl:when test="@ConceptLink"> |
---|
48 | <xs:element name="{@name}" minOccurs="{@CardinalityMin}" maxOccurs="{@CardinalityMax}" dcr:datcat="{@ConceptLink}"> |
---|
49 | <xs:complexType> |
---|
50 | <xs:sequence> |
---|
51 | <!-- process all elements at this level --> |
---|
52 | <xsl:apply-templates select="./CMD_Element"/> |
---|
53 | <!-- process all components at one level deeper (recursive call) --> |
---|
54 | <xsl:apply-templates select="./CMD_Component"/> |
---|
55 | </xs:sequence> |
---|
56 | <xs:attribute name="ref" type="xs:IDREF"/> |
---|
57 | </xs:complexType> |
---|
58 | </xs:element> |
---|
59 | </xsl:when> |
---|
60 | <!-- else (there is no ConceptLink attribute) --> |
---|
61 | <xsl:otherwise> |
---|
62 | <xs:element name="{@name}" minOccurs="{@CardinalityMin}" maxOccurs="{@CardinalityMax}"> |
---|
63 | <xs:complexType> |
---|
64 | <xs:sequence> |
---|
65 | <!-- process all elements at this level --> |
---|
66 | <xsl:apply-templates select="./CMD_Element"/> |
---|
67 | <!-- process all components at one level deeper (recursive call) --> |
---|
68 | <xsl:apply-templates select="./CMD_Component"/> |
---|
69 | </xs:sequence> |
---|
70 | <xs:attribute name="ref" type="xs:IDREF"/> |
---|
71 | </xs:complexType> |
---|
72 | </xs:element> |
---|
73 | </xsl:otherwise> |
---|
74 | </xsl:choose> |
---|
75 | |
---|
76 | </xsl:template> |
---|
77 | |
---|
78 | <!-- Rename CMD_Element and convert its attributes and children --> |
---|
79 | <xsl:template match="CMD_Element"> |
---|
80 | <xsl:element name="xs:element"> |
---|
81 | <xsl:apply-templates select="@* | node()"/> |
---|
82 | </xsl:element> |
---|
83 | </xsl:template> |
---|
84 | |
---|
85 | <!-- then convert all ValueScheme elements --> |
---|
86 | <xsl:template match="ValueScheme"> |
---|
87 | <xs:simpleType> |
---|
88 | <xs:restriction base="xs:string"> |
---|
89 | <xsl:apply-templates select="pattern"/> |
---|
90 | <xsl:apply-templates select="enumeration"/> |
---|
91 | </xs:restriction> |
---|
92 | </xs:simpleType> |
---|
93 | </xsl:template> |
---|
94 | |
---|
95 | <!-- Convert patterns --> |
---|
96 | <xsl:template match="pattern"> |
---|
97 | <xs:pattern value="{self::node()}"/> |
---|
98 | </xsl:template> |
---|
99 | |
---|
100 | <!-- Convert enumerations --> |
---|
101 | <xsl:template match="enumeration"> |
---|
102 | <xsl:for-each select="item"> |
---|
103 | <xs:enumeration value="{node()}" dcr:datcat="{@ConceptLink}"/> |
---|
104 | </xsl:for-each> |
---|
105 | </xsl:template> |
---|
106 | |
---|
107 | <!-- remove empty attributes --> |
---|
108 | <!--<xsl:template match="@*[not(string())]" />--> |
---|
109 | |
---|
110 | <!-- default action: keep the attributes like they are --> |
---|
111 | <xsl:template match="@*|node()"> |
---|
112 | <xsl:copy/> |
---|
113 | </xsl:template> |
---|
114 | |
---|
115 | <!-- except for those attributes we want to be renamed --> |
---|
116 | <xsl:template match="@CardinalityMin"> |
---|
117 | <xsl:attribute name="minOccurs"> |
---|
118 | <xsl:value-of select="."/> |
---|
119 | </xsl:attribute> |
---|
120 | </xsl:template> |
---|
121 | |
---|
122 | <xsl:template match="@CardinalityMax"> |
---|
123 | <xsl:attribute name="maxOccurs"> |
---|
124 | <xsl:value-of select="."/> |
---|
125 | </xsl:attribute> |
---|
126 | </xsl:template> |
---|
127 | |
---|
128 | <xsl:template match="@ConceptLink"> |
---|
129 | <!-- if attribute is not empty convert it --> |
---|
130 | <xsl:if test="string(.)"> |
---|
131 | <xsl:attribute name="dcr:datcat"> |
---|
132 | <xsl:value-of select="."/> |
---|
133 | </xsl:attribute> |
---|
134 | </xsl:if> |
---|
135 | </xsl:template> |
---|
136 | |
---|
137 | <xsl:template match="@ValueScheme"> |
---|
138 | <xsl:attribute name="type"> |
---|
139 | <xsl:value-of select="concat('xs:',.)"/> |
---|
140 | </xsl:attribute> |
---|
141 | </xsl:template> |
---|
142 | |
---|
143 | </xsl:stylesheet> |
---|