/[volute]/trunk/projects/theory/snapdm/res/xmi2xsd.xsl
ViewVC logotype

Contents of /trunk/projects/theory/snapdm/res/xmi2xsd.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (show annotations)
Wed Feb 20 19:39:48 2008 UTC (12 years, 9 months ago) by richard.p.wagner
File MIME type: application/xml
File size: 8589 byte(s)
Initial creation and import of the theory data model.
1 <?xml version="1.0" encoding="UTF-8"?>
2 <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"
3 version="1.0"
4 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5 xmlns:x2s="http://ns.eurovotech.org/registry-metadata#"
6 xmlns:uml="http://schema.omg.org/spec/UML/2.0"
7 xmlns:xmi="http://schema.omg.org/spec/XMI/2.1">
8 <output method="xml" version="1.0" indent="yes"/>
9
10 <key name="classid" match="*" use="@xmi:id"/>
11
12 <variable name="snap-ns">http://www.ivoa.net/xml/theory/SNAPSimulation_types/v0.1</variable>
13 <variable name="xsd-ns">http://www.w3.org/2001/XMLSchema</variable>
14 <variable name="xsd-prefix">xsd:</variable>
15
16 <template match="/">
17 <choose>
18 <when test="namespace-uri(/*) != 'http://schema.omg.org/spec/XMI/2.1'">
19 <x2s:ERROR>Wrong namespace: this script can convert only XMI v2.1</x2s:ERROR>
20 </when>
21 <otherwise>
22 <apply-templates select="xmi:XMI"/>
23 </otherwise>
24 </choose>
25 </template>
26
27 <template match="xmi:XMI">
28 <xsd:schema>
29 <attribute name="xml:snap">
30 <value-of select="$snap-ns"/>
31 </attribute>
32 <attribute name="xml:xsd">
33 <value-of select="$xsd-ns"/>
34 </attribute>
35 <xsd:annotation>
36 <xsd:documentation>
37 Generated from XMI.
38 </xsd:documentation>
39 </xsd:annotation>
40 <apply-templates select="uml:Model"/>
41 </xsd:schema>
42 </template>
43
44 <template match="uml:Model">
45 <apply-templates select=".//*[@xmi:type='uml:Class' and @name]"/>
46 <apply-templates select=".//*[@xmi:type='uml:DataType' and @name]"/>
47 <apply-templates select=".//*[@xmi:type='uml:Enumeration']"/>
48 </template>
49
50 <template match="*[@xmi:type='uml:Class']">
51 <xsd:complexType>
52 <attribute name="name">
53 <text><value-of select="@name"/></text>
54 </attribute>
55 <if test="@isAbstract">
56 <attribute name="abstract">
57 <text>true</text>
58 </attribute>
59 </if>
60 <apply-templates select="ownedComment"/>
61 <choose>
62 <when test="*[@xmi:type='uml:Generalization']">
63 <apply-templates select="*[@xmi:type='uml:Generalization']"/>
64 </when>
65 <otherwise>
66 <call-template name="class-content">
67 <with-param name="class" select="."/>
68 </call-template>
69 </otherwise>
70 </choose>
71 </xsd:complexType>
72 </template>
73
74 <template match="*[@xmi:type='uml:DataType']">
75 <choose>
76 <when test="*[@xmi:type='uml:Property']">
77 <call-template name="complex-datatype"/>
78 </when>
79 <otherwise>
80 <call-template name="simple-datatype"/>
81 </otherwise>
82 </choose>
83 </template>
84
85 <template name="complex-datatype">
86 <xsd:complexType>
87 <attribute name="name">
88 <text><value-of select="@name"/></text>
89 </attribute>
90 <if test="@isAbstract">
91 <attribute name="abstract">
92 <text>true</text>
93 </attribute>
94 </if>
95 <apply-templates select="ownedComment"/>
96 <choose>
97 <when test="*[@xmi:type='uml:Generalization']">
98 <apply-templates select="*[@xmi:type='uml:Generalization']"/>
99 </when>
100 <otherwise>
101 <call-template name="class-content">
102 <with-param name="class" select="."/>
103 </call-template>
104 </otherwise>
105 </choose>
106 </xsd:complexType>
107 </template>
108
109 <template name="simple-datatype">
110 <xsd:simpleType>
111 <attribute name="name">
112 <text><value-of select="@name"/></text>
113 </attribute>
114 <apply-templates select="ownedComment"/>
115 <xsd:restriction>
116 <attribute name="base">
117 <choose>
118 <when test="*[@xmi:type='uml:Generalization']">
119 <call-template name="class-from-id">
120 <with-param name="id">
121 <value-of select="*[@xmi:type='uml:Generalization']/@general"/>
122 </with-param>
123 </call-template>
124 </when>
125 <otherwise>
126 <text>xsd:string</text>
127 </otherwise>
128 </choose>
129 </attribute>
130 </xsd:restriction>
131 </xsd:simpleType>
132 </template>
133
134 <template match="*[@xmi:type='uml:Generalization']">
135 <xsd:complexContent>
136 <xsd:extension>
137 <attribute name="base">
138 <call-template name="class-from-id">
139 <with-param name="id">
140 <value-of select="@general"/>
141 </with-param>
142 </call-template>
143 </attribute>
144 <call-template name="class-content">
145 <with-param name="class" select=".."/>
146 </call-template>
147 </xsd:extension>
148 </xsd:complexContent>
149 </template>
150
151 <template name="class-content">
152 <param name="class"/>
153 <xsd:sequence>
154 <apply-templates select="$class//*[@xmi:type='uml:Property']"/>
155 </xsd:sequence>
156 </template>
157
158 <template match="*[@xmi:type='uml:Enumeration']">
159 <xsd:simpleType>
160 <attribute name="name">
161 <text><value-of select="@name"/></text>
162 </attribute>
163 <apply-templates select="ownedComment"/>
164 <xsd:restriction>
165 <attribute name="base">
166 <text>xsd:string</text>
167 </attribute>
168 <apply-templates select="*[@xmi:type='uml:EnumerationLiteral']"/>
169 </xsd:restriction>
170 </xsd:simpleType>
171 </template>
172
173 <template match="*[@xmi:type='uml:EnumerationLiteral']">
174 <xsd:enumeration>
175 <attribute name="value">
176 <value-of select="@name"/>
177 <!-- <value-of select="translate(substring(@name,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
178 <value-of select="translate(substring(@name,2),' !#$%&amp;()*+,-./:;&lt;=&gt;?@[\]^_`{|}~','_')"/>
179 -->
180 </attribute>
181 </xsd:enumeration>
182 </template>
183
184 <template match="*[@xmi:type='uml:Property']">
185 <if test="../@xmi:type='uml:Class' or ../@xmi:type='uml:DataType'">
186 <variable name="c" select="key('classid',@type)"/>
187 <xsd:element>
188 <attribute name="name">
189 <value-of select="@name"/>
190 </attribute>
191 <attribute name="type">
192 <choose>
193 <when test="not(./@aggregation='composite') and $c/@xmi:type = 'uml:Class'">
194 <text>xsd:IDREF</text>
195 </when>
196 <otherwise>
197 <call-template name="class-from-id">
198 <with-param name="id">
199 <value-of select="@type"/>
200 </with-param>
201 </call-template>
202 </otherwise>
203 </choose>
204 </attribute>
205 <attribute name="minOccurs">
206 <choose>
207 <when test="lowerValue/@value">
208 <value-of select="lowerValue/@value"/>
209 </when>
210 <otherwise>
211 <text>0</text>
212 </otherwise>
213 </choose>
214 </attribute>
215 <attribute name="maxOccurs">
216 <choose>
217 <when test="not(upperValue/@value)">
218 <text>1</text>
219 </when>
220 <when test="upperValue/@value = -1">
221 <text>unbounded</text>
222 </when>
223 <otherwise>
224 <value-of select="upperValue/@value"/>
225 </otherwise>
226 </choose>
227 </attribute>
228 <apply-templates select="ownedComment"/>
229 <if test="not(./@aggregation='composite') and $c/@xmi:type = 'uml:Class'">
230 <xsd:annotation>
231 <xsd:documentation>
232 This should be a reference to a
233 <call-template name="class-from-id">
234 <with-param name="id">
235 <value-of select="@type"/>
236 </with-param>
237 </call-template>.
238 We use IDREF here, it may have to be changed to some other implementation of a reference.
239 </xsd:documentation>
240 </xsd:annotation>
241 </if>
242 </xsd:element>
243 </if>
244 </template>
245
246 <template match="ownedComment">
247 <xsd:annotation>
248 <xsd:documentation>
249 <value-of select="@body"/>
250 </xsd:documentation>
251 </xsd:annotation>
252 </template>
253
254 <template name="class-from-id">
255 <param name="id"/>
256 <param name="prefix"/>
257 <variable name="c" select="key('classid',$id)"/>
258 <choose>
259 <when test="$c/@xmi:type = 'uml:PrimitiveType'">
260 <value-of select="$xsd-prefix"/>
261 <value-of select="$c/@name"/>
262 </when>
263 <otherwise><value-of select="$prefix"/>
264 <value-of select="$c/@name"/>
265 </otherwise>
266 </choose>
267 </template>
268
269
270 </stylesheet>

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26