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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 440 - (show annotations)
Sun May 11 06:09:48 2008 UTC (12 years, 6 months ago) by gerard.lemson
File MIME type: application/xml
File size: 10986 byte(s)
Updates regarding proper calculation of utypes and further refinements of TAP votables.
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 This XSLT script transforms a data model from our
4 intermediate representation to a VOTable describing the metadata
5 of a TAP-like service.
6 At the current time TAP does not exist, we make therfore certain
7 assumptions on the details of the required VOTable-s that we assume
8 are going to be used to describe the database's contents.
9
10 We use the View-s that are generated in intermediate2ddl as
11 the public contents of the database for the UML data model.
12
13 -->
14
15 <!DOCTYPE stylesheet [
16 <!ENTITY cr "<xsl:text>
17 </xsl:text>">
18 <!ENTITY bl "<xsl:text> </xsl:text>">
19 ]>
20
21 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:exsl="http://exslt.org/common"
23 extension-element-prefixes="exsl"
24 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
25 xmlns:vot="http://www.ivoa.net/xml/VOTable/v1.1">
26
27
28 <xsl:import href="common-ddl.xsl"/>
29 <xsl:import href="intermediate2ddl.xsl"/>
30 <xsl:import href="utype.xsl"/>
31
32 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
33
34 <xsl:strip-space elements="*" />
35
36 <xsl:key name="element" match="*" use="@xmiid"/>
37
38
39 <xsl:param name="lastModified"/>
40 <xsl:variable name="header">-- last modification date of the UML model <xsl:value-of select="$lastModified"/>&cr;</xsl:variable>
41
42 <xsl:variable name="votablenamespace" select="'http://www.ivoa.net/xml/VOTable/v1.1'"/>
43
44 <!-- start -->
45 <xsl:template match="/">
46 <xsl:apply-templates select="model"/>
47 </xsl:template>
48
49
50
51
52
53
54 <xsl:template match="model">
55 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
56 -- Generating TAP-metadata-like VOTables for model <xsl:value-of select="name"/> and DB vendor <xsl:value-of select="$vendor"/>.
57 <xsl:value-of select="$header"/>
58
59 <!-- CREATE TAP-type 1 votable -->
60 <xsl:variable name="file" select="concat(name,'_tap_table.xml')"/>
61 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
62 <xsl:result-document href="{$file}">
63 <xsl:apply-templates select="." mode="tap">
64 <xsl:with-param name="taptype" select="'table'"/>
65 </xsl:apply-templates>
66 </xsl:result-document>
67
68 <xsl:variable name="file" select="concat(name,'_tap_fields.xml')"/>
69 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
70 <xsl:result-document href="{$file}">
71 <xsl:apply-templates select="." mode="tap">
72 <xsl:with-param name="taptype" select="'fields'"/>
73 </xsl:apply-templates>
74 </xsl:result-document>
75 </xsl:template>
76
77
78
79
80 <!--
81 This template assumes that the public database schema is described as a collection
82 of <TABLE>-s, with the <FIELD>-s describing the columns and no <DATA> element.
83 -->
84 <xsl:template match="model" mode="tap">
85 <xsl:param name="taptype" select="fields"/>
86 <xsl:element name="VOTABLE">
87 <xsl:attribute name="xlmns" select="$votablenamespace"/>
88 <xsl:attribute name="version" select="'1.1'"/>
89 <xsl:element name="RESOURCE">
90 <xsl:attribute name="name" select="name"/>
91 <xsl:element name="DESCRIPTION">
92 <xsl:value-of select="description"/>
93 </xsl:element>
94 <xsl:apply-templates select="package[objectType]" mode="tap">
95 <xsl:with-param name="taptype" select="$taptype"/>
96 </xsl:apply-templates>
97 </xsl:element>
98 </xsl:element>
99 </xsl:template>
100
101
102
103
104 <xsl:template match="package" mode="tap">
105 <xsl:param name="taptype" select="fields"/>
106 <xsl:param name="utypeprefix"/>
107 <xsl:element name="RESOURCE">
108 <xsl:attribute name="name" select="name"/>
109 <xsl:element name="DESCRIPTION">
110 <xsl:value-of select="description"/>
111 </xsl:element>
112 <xsl:choose>
113 <xsl:when test="$taptype='fields'">
114 <xsl:apply-templates select="objectType" mode="tap_fields">
115 <xsl:sort select="name"/>
116 </xsl:apply-templates>
117 </xsl:when>
118 <xsl:otherwise>
119 <xsl:apply-templates select="objectType" mode="tap_tables">
120 <xsl:sort select="name"/>
121 </xsl:apply-templates>
122 </xsl:otherwise>
123 </xsl:choose>
124 <xsl:apply-templates select="package" mode="tap">
125 <xsl:with-param name="taptype" select="$taptype"/>
126 </xsl:apply-templates>
127 </xsl:element>
128 </xsl:template>
129
130
131
132
133
134
135 <!--
136 This template assumes that the public database schema is described as a collection
137 of <TABLE>-s, with the <FIELD>-s describing the columns and no <DATA> element.
138 -->
139
140 <xsl:template match="objectType" mode="tap_fields">
141 <xsl:variable name="utype">
142 <xsl:apply-templates select="." mode="utype"/>
143 </xsl:variable>
144
145 <xsl:element name="TABLE">
146 <xsl:attribute name="name">
147 <xsl:apply-templates select="." mode="viewName"/>
148 </xsl:attribute>
149 <xsl:element name="DESCRIPTION">
150 <xsl:value-of select="description"/>
151 </xsl:element>
152 <xsl:choose>
153 <xsl:when test="extends">
154 <xsl:apply-templates select="key('element',extends/@xmiidref)" mode="tap_fields"/>
155 </xsl:when>
156 <xsl:otherwise>
157 <xsl:element name="FIELD">
158 <xsl:attribute name="name" select="$primaryKeyColumnName"/>
159 <xsl:attribute name="datatype" select="'long'"/>
160 <xsl:attribute name="ucd" select="'TBD'"/>
161 <xsl:attribute name="utype" select="concat($utype,'.',$primaryKeyColumnName)"/>
162 <xsl:element name="DESCRIPTION">
163 <xsl:text>The unique, primary key column on this table.</xsl:text>
164 </xsl:element>
165 </xsl:element>
166 <xsl:element name="FIELD">
167 <xsl:attribute name="name" select="$discriminatorColumnName"/>
168 <xsl:attribute name="datatype" select="'char'"/>
169 <xsl:attribute name="width" select="$discriminatorColumnLength"/>
170 <xsl:attribute name="ucd" select="'TBD'"/>
171 <xsl:attribute name="utype" select="'TBD'"/>
172 <xsl:element name="DESCRIPTION">
173 <xsl:text>This column stores the name of the object type from the data model stored in the row.</xsl:text>
174 </xsl:element>
175 </xsl:element>
176 </xsl:otherwise>
177 </xsl:choose>
178 <xsl:if test="container">
179 <xsl:element name="FIELD">
180 <xsl:attribute name="name" select="'containerId'"/>
181 <xsl:attribute name="datatype" select="'long'"/>
182 <xsl:attribute name="ucd" select="'TBD'"/>
183 <xsl:attribute name="utype" select="concat($utype,'.CONTAINER')"/>
184 <xsl:element name="DESCRIPTION">
185 <xsl:text>This column is a foreign key pointing to the containing object in </xsl:text>
186 <xsl:apply-templates select="key('element',container/@xmiidref)" mode="viewName"/>
187 </xsl:element>
188 </xsl:element>
189 </xsl:if>
190 <xsl:for-each select="attribute">
191 <xsl:variable name="columns">
192 <xsl:apply-templates select="." mode="columns">
193 <xsl:with-param name="utypeprefix" select="$utype"/>
194 </xsl:apply-templates>
195 </xsl:variable>
196 <xsl:for-each select="exsl:node-set($columns)/column">
197 <xsl:element name="FIELD">
198 <xsl:attribute name="name">
199 <xsl:value-of select="name"/>
200 </xsl:attribute>
201 <xsl:variable name="votabletype">
202 <xsl:call-template name="votabletype">
203 <xsl:with-param name="type" select="type"/>
204 </xsl:call-template>
205 </xsl:variable>
206 <xsl:attribute name="datatype" select="$votabletype"/>
207 <xsl:if test="$votabletype='char'">
208 <xsl:attribute name="width">
209 <xsl:variable name ="length">
210 <xsl:call-template name="stringlength">
211 <xsl:with-param name="constraints" select="constraints"/>
212 </xsl:call-template>
213 </xsl:variable>
214 <xsl:choose>
215 <xsl:when test="number($length) &lt;= 0"><xsl:text>*</xsl:text></xsl:when>
216 <xsl:otherwise><xsl:value-of select="$length"/></xsl:otherwise>
217 </xsl:choose>
218 </xsl:attribute>
219 </xsl:if>
220 <xsl:attribute name="utype" select="utype"/>
221 <xsl:element name="DESCRIPTION" >
222 <xsl:value-of select="description"/>
223 </xsl:element>
224 </xsl:element>
225 </xsl:for-each>
226 </xsl:for-each>
227 <xsl:for-each select="reference[not(subsets)]">
228 <xsl:element name="FIELD">
229 <xsl:attribute name="name">
230 <xsl:apply-templates select="." mode="columnName"/>
231 </xsl:attribute>
232 <xsl:attribute name="datatype" select="'long'"/>
233 <xsl:attribute name="ucd" select="'TBD'"/>
234 <xsl:attribute name="utype" select="'TBD'"/>
235 <xsl:element name="DESCRIPTION">
236 <xsl:value-of select="description"/>&cr;
237 <xsl:text>This column is a foreign key pointing to the referenced object in </xsl:text>
238 <xsl:apply-templates select="key('element',datatype/@xmiidref)" mode="viewName"/><xsl:text>.
239 </xsl:text>
240 </xsl:element>
241 </xsl:element>
242 </xsl:for-each>
243 </xsl:element>
244 </xsl:template>
245
246
247
248
249 <xsl:template name="votabletype">
250 <xsl:param name="type"/>
251
252 <!--
253 Primitive types :
254 boolean
255 short
256 int
257 long
258 float
259 double
260
261 Date type :
262 datetime
263
264 Characters type :
265 string
266
267 Unsupported type (later) => string :
268 complex
269 rational
270 -->
271 <xsl:choose>
272 <xsl:when test="$type = 'boolean'">boolean</xsl:when>
273 <xsl:when test="$type = 'complex'">complex</xsl:when>
274 <xsl:when test="$type = 'short'">short</xsl:when>
275 <xsl:when test="$type = 'integer'">integer</xsl:when>
276 <xsl:when test="$type = 'long'">long</xsl:when>
277 <xsl:when test="$type = 'float'">float</xsl:when>
278 <xsl:when test="$type = 'double'">double</xsl:when>
279 <xsl:when test="$type = 'datetime'">datetime</xsl:when>
280 <xsl:otherwise>char</xsl:otherwise>
281 </xsl:choose>
282 </xsl:template>
283
284
285
286 <!-- TAP_table style -->
287 <!--
288 This template assumes that the public database schema is described as a collection
289 of <TABLE>-s, with predefined fields, possibly from the INFORMAITON_SCHEMA
290 and the columns in the <DATA> describing the columns
291 .
292 -->
293 <xsl:template match="objectType" mode="tap_tables">
294 <xsl:element name="TABLE">
295 <xsl:attribute name="name">
296 <xsl:apply-templates select="." mode="viewName"/>
297 </xsl:attribute>
298 <xsl:element name="DESCRIPTION">
299 <xsl:value-of select="description"/>
300 </xsl:element>
301 </xsl:element>&cr;&cr;
302 </xsl:template>
303
304
305
306
307
308
309
310 </xsl:stylesheet>

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