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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 177 - (show annotations)
Fri Apr 4 06:30:24 2008 UTC (12 years, 8 months ago) by gerard.lemson
File MIME type: application/xml
File size: 11292 byte(s)
continuing updates to schema generation
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE stylesheet [
4 <!ENTITY cr "<xsl:text>
5 </xsl:text>">
6 <!ENTITY bl "<xsl:text> </xsl:text>">
7 ]>
8
9 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
11
12
13 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
14
15 <xsl:strip-space elements="*" />
16
17 <!-- xml index on xmlid -->
18 <xsl:key name="element" match="*//*" use="@xmiid"/>
19 <xsl:key name="package" match="*//package" use="@xmiid"/>
20
21 <!-- Input parameters -->
22 <xsl:param name="targetnamespace_root"/>
23 <xsl:param name="schemalocation_root" />
24 <xsl:param name="xmlLastModified"/>
25 <xsl:param name="xslLastModified"/>
26
27 <!-- if XSL's last modified date later XML's, then update -->
28 <xsl:variable name="lastModified">
29 <xsl:choose>
30 <xsl:when test="number(/model/lastModifiedDate) &gt; number($xslLastModified)"><xsl:value-of select="/model/lastModifiedDate"/></xsl:when>
31 <xsl:otherwise><xsl:value-of select="$xslLastModified"/></xsl:otherwise>
32 </xsl:choose>
33 </xsl:variable>
34
35 <xsl:variable name="xsd-ns">http://www.w3.org/2001/XMLSchema</xsl:variable>
36 <xsl:variable name="xsd-prefix">xsd:</xsl:variable>
37
38
39
40 <xsl:template match="/">
41 <xsl:message>Target namespace root = <xsl:value-of select="$targetnamespace_root"/></xsl:message>
42 <xsl:message>Schema location root = <xsl:value-of select="$schemalocation_root"/></xsl:message>
43 <xsl:apply-templates select="model"/>
44 </xsl:template>
45
46
47
48
49 <xsl:template match="model">
50 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
51 <xsl:apply-templates select="package"/>
52 </xsl:template>
53
54
55
56 <!-- Calculate the full path to the package identified by the packageid
57 Use the specified delimiter. -->
58 <xsl:template name="package-path">
59 <xsl:param name="packageid"/>
60 <xsl:param name="delimiter"/>
61 <xsl:param name="suffix"/>
62
63 <xsl:variable name="p" select="key('element',$packageid)"/>
64 <xsl:choose>
65 <xsl:when test="name($p) = 'package'">
66 <xsl:variable name="newsuffix">
67 <xsl:choose>
68 <xsl:when test="$suffix">
69 <xsl:value-of select="concat($p/name,$delimiter,$suffix)"/>
70 </xsl:when>
71 <xsl:otherwise>
72 <xsl:value-of select="$p/name"/>
73 </xsl:otherwise>
74 </xsl:choose>
75 </xsl:variable>
76 <xsl:call-template name="package-path">
77 <xsl:with-param name="packageid" select="$p/../@xmiid"/>
78 <xsl:with-param name="suffix" select="$newsuffix"/>
79 <xsl:with-param name="delimiter" select="$delimiter"/>
80 </xsl:call-template>
81 </xsl:when>
82 <xsl:otherwise>
83 <xsl:value-of select="$suffix"/>
84 </xsl:otherwise>
85 </xsl:choose>
86 </xsl:template>
87
88
89
90 <xsl:template name="schemalocation-for-package">
91 <xsl:param name="packgeid"/>
92 <xsl:variable name="path">
93 <xsl:call-template name="package-path">
94 <xsl:with-param name="packageid" select="$packgeid"/>
95 <xsl:with-param name="delimiter" select="'/'"/>
96 </xsl:call-template>
97 </xsl:variable>
98 <xsl:value-of select="concat($schemalocation_root,'/',$path,'.xsd')"/>
99 </xsl:template>
100
101
102
103
104 <xsl:template name="namespace-for-package">
105 <xsl:param name="packageid"/>
106 <xsl:variable name="path">
107 <xsl:call-template name="package-path">
108 <xsl:with-param name="packageid" select="$packageid"/>
109 <xsl:with-param name="delimiter" select="'/'"/>
110 </xsl:call-template>
111 </xsl:variable>
112 <xsl:value-of select="concat($targetnamespace_root,'/',$path)"/>
113 </xsl:template>
114
115
116
117 <xsl:template name="package-prefix">
118 <xsl:param name="packageid"/>
119 <xsl:variable name="rank">
120 <xsl:value-of select="count(*//package[@xmiid &lt; $packageid])+1"/>
121 </xsl:variable>
122 <xsl:value-of select="concat('p',$rank)"/>
123 </xsl:template>
124
125
126 <xsl:template match="package">
127
128 <xsl:variable name="path">
129 <xsl:call-template name="package-path">
130 <xsl:with-param name="packageid" select="@xmiid"/>
131 <xsl:with-param name="delimiter" select="'_'"/>
132 </xsl:call-template>
133 </xsl:variable>
134
135 <xsl:variable name="targetschema">
136 <xsl:call-template name="namespace-for-package">
137 <xsl:with-param name="packageid" select="./@xmiid"/>
138 </xsl:call-template>
139 </xsl:variable>
140
141
142 <xsl:variable name="file" select="concat($path,'.xsd')"/>
143 <!-- open file for the schema file corresponding to this package -->
144 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
145 <xsl:result-document href="{$file}">
146
147 <xsd:schema>
148 <xsl:attribute name="targetNamespace">
149 <xsl:value-of select="$targetschema"/>
150 </xsl:attribute>
151 <xsl:apply-templates select="depends" mode="xmlns"/>
152 <xsd:annotation>
153 <xsd:documentation>
154 <xsl:text>Generated from UML->XMI->intermediate->XSD.</xsl:text>
155 </xsd:documentation>
156 </xsd:annotation>
157
158 <xsl:apply-templates select="depends" mode="ns-import"/>
159 <xsl:apply-templates select="objectType" mode="declare"/>
160
161 </xsd:schema>
162 </xsl:result-document>
163
164 <xsl:apply-templates select="package"/>
165
166 </xsl:template>
167
168
169 <xsl:template match="depends" mode="xmlns">
170 <xsl:variable name="p">
171 <xsl:call-template name="package-prefix">
172 <xsl:with-param name="packageid" select="@xmiidref"/>
173 </xsl:call-template>
174 </xsl:variable>
175 <xsl:variable name="ns">
176 <xsl:call-template name="namespace-for-package">
177 <xsl:with-param name="packageid" select="@xmiidref"/>
178 </xsl:call-template>
179 </xsl:variable>
180 <xsl:namespace name="{$p}">
181 <xsl:value-of select="$ns"/>
182 </xsl:namespace>
183 </xsl:template>
184
185
186
187
188 <xsl:template match="objectType" mode="declare">
189 <xsd:complexType>
190 <xsl:attribute name="name">
191 <xsl:value-of select="name"/>
192 </xsl:attribute>
193 <xsd:annotation>
194 <xsd:documentation>
195 <xsl:value-of select="description"/>
196 </xsd:documentation>
197 </xsd:annotation>
198 <xsl:choose>
199 <xsl:when test="extends">
200 <xsd:complexContent>
201 <xsd:extension>
202 <xsl:attribute name="base">
203 <xsl:apply-templates select="extends" mode="XSDType"/>
204 </xsl:attribute>
205 <xsl:apply-templates select="." mode="content"/>
206 </xsd:extension>
207 </xsd:complexContent>
208 </xsl:when>
209 <xsl:otherwise>
210 <xsl:apply-templates select="." mode="content"/>
211 </xsl:otherwise>
212 </xsl:choose>
213 </xsd:complexType>
214 </xsl:template>
215
216 <xsl:template match="objectType" mode="content">
217 <xsd:sequence>
218
219 </xsd:sequence>
220 </xsl:template>
221
222
223 <xsl:template match="extends">
224 <xsl:choose>
225 <xsl:when test="@base">
226 </xsl:when>
227 </xsl:choose>
228 </xsl:template>
229
230
231
232
233
234 <!-- TODo treat anyURI and possibly more -->
235 <xsl:template match="datatype" mode="XSDType">
236 <xsl:choose>
237 <xsl:when test="@type">
238 <xsl:choose>
239 <xsl:when test="@type = 'boolean'">xsd:boolean</xsl:when>
240 <xsl:when test="@type = 'p_boolean'">xsd:boolean</xsl:when>
241 <xsl:when test="@type = 'integer'">xsd:int</xsl:when>
242 <xsl:when test="@type = 'p_integer'">xsd:int</xsl:when>
243 <xsl:when test="@type = 'long'">xsd:long</xsl:when>
244 <xsl:when test="@type = 'p_long'">xsd:long</xsl:when>
245 <xsl:when test="@type = 'datetime'">xsd:datetime</xsl:when>
246 <xsl:when test="@type = 'real'">xsd:floatt</xsl:when>
247 <xsl:when test="@type = 'p_real'">xsd:float</xsl:when>
248 <xsl:when test="@type = 'double'">xsd:double</xsl:when>
249 <xsl:when test="@type = 'p_double'">xsd:double</xsl:when>
250 <xsl:otherwise>xsd:string</xsl:otherwise>
251 </xsl:choose>
252 </xsl:when>
253 <xsl:otherwise>
254 <xsl:variable name="prefix">
255 <xsl:call-template name="package-prefix">
256 <xsl:with-param name="packageid" select="key('element',@xmiidref)/../@xmiid"/>
257 </xsl:call-template>
258 </xsl:variable>
259 <xsl:value-of select="$prefix"/>:<xsl:value-of select="@class"/>
260 </xsl:otherwise>
261 </xsl:choose>
262 </xsl:template>
263
264
265
266
267 <xsl:template match="attribute" mode="declare">
268 <xsl:variable name="type">
269 <xsl:apply-templates select="type-ref" mode="XSDType"/>
270 </xsl:variable>
271 <xsd:element>
272 <xsl:attribute name="name">
273 <xsl:value-of select="name"/>
274 </xsl:attribute>
275 <xsl:attribute name="type">
276 <xsl:value-of select="$type"/>
277 </xsl:attribute>
278 </xsd:element>
279 </xsl:template>
280
281
282
283
284
285 <xsl:template match="collection" mode="declare">
286 <xsl:variable name="type">
287 <xsl:apply-templates select="datatype" mode="JavaType"/>
288 </xsl:variable>
289 private List&lt;<xsl:value-of select="$type"/>&gt;&bl;<xsl:value-of select="name"/> = null;
290 </xsl:template>
291
292
293
294
295
296 <xsl:template match="reference" mode="declare">
297 <xsl:variable name="type">
298 <xsl:apply-templates select="datatype" mode="JavaType"/>
299 </xsl:variable>
300 private <xsl:value-of select="$type"/>&bl;<xsl:value-of select="name"/> = null;
301 </xsl:template>
302
303
304
305
306 <xsl:template match="literal" >
307 /**
308 * Value : <xsl:value-of select="value"/>
309 *
310 * Description :
311 <xsl:value-of select="description" disable-output-escaping="yes"/>
312 **/
313 <xsl:text>E_</xsl:text><xsl:call-template name="badChars">
314 <xsl:with-param name="val" select="value"/>
315 </xsl:call-template>
316 <xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>&cr;
317 </xsl:template>
318
319
320
321
322 <xsl:template name="upperCase">
323 <xsl:param name="val"/>
324 <xsl:variable name="prem" select="substring($val,1,1)"/>
325 <xsl:variable name="first" select="translate($prem,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
326 <xsl:variable name="end" select="substring($val,2,string-length($val)-1)"/>
327 <xsl:value-of select="concat($first,$end)"/>
328 </xsl:template>
329
330
331
332
333 <xsl:template name="lowerCase">
334 <xsl:param name="val"/>
335 <xsl:variable name="prem" select="substring($val,1,1)"/>
336 <xsl:variable name="first" select="translate($prem,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
337 <xsl:variable name="end" select="substring($val,2,string-length($val)-1)"/>
338 <xsl:value-of select="@package"/>.<xsl:value-of select="concat($first,$end)"/>
339 </xsl:template>
340
341
342
343
344 <xsl:template name="badChars">
345 <xsl:param name="val"/>
346 <xsl:value-of select="translate($val,'abcdefghijklmnopqrstuvwxyz.: *','ABCDEFGHIJKLMNOPQRSTUVWXYZ___N')"/>
347 </xsl:template>
348
349 </xsl:stylesheet>

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