/[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 541 - (show annotations)
Mon May 26 13:16:05 2008 UTC (12 years, 6 months ago) by gerard.lemson
File MIME type: application/xml
File size: 29368 byte(s)
Added generation of VODataService-like TAP/QL metadata.
Fixed generation of TAP-tableset, taking into accountextends properly (I hope)
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 xmlns:tab="urn:astrogrid:schema:TableMetadata"
27 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
28
29
30 <xsl:import href="common-ddl.xsl"/>
31 <xsl:import href="intermediate2ddl.xsl"/>
32 <xsl:import href="utype.xsl"/>
33
34 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
35 <xsl:output name="text-format" method="text" encoding="UTF-8" indent="no" />
36 <xsl:strip-space elements="*" />
37
38 <xsl:key name="element" match="*" use="@xmiid"/>
39
40 <xsl:param name="mode" select='vodataservice'/> <!-- tap_schema, tap_table_set vodataservice -->
41 <xsl:param name="vendor" select="sql92"/> <!-- -->
42 <xsl:param name="lastModifiedText"/>
43
44 <xsl:variable name="header">-- last modification date of the UML model <xsl:value-of select="$lastModifiedText"/>&cr;</xsl:variable>
45
46 <xsl:variable name="votablenamespace" select="'http://www.ivoa.net/xml/VOTable/v1.1'"/>
47
48 <xsl:variable name="commit">
49 <xsl:choose>
50 <xsl:when test="$vendor = 'mssqlserver'">
51 <xsl:text>GO</xsl:text>
52 </xsl:when>
53 <xsl:when test="$vendor = 'postgres'">
54 <xsl:text>COMMIT</xsl:text>
55 </xsl:when>
56 <xsl:otherwise>
57 <xsl:text>COMMIT</xsl:text>
58 </xsl:otherwise>
59 </xsl:choose>
60 </xsl:variable>
61
62 <!-- start -->
63 <xsl:template match="/">
64 <xsl:choose>
65 <xsl:when test="$mode = 'tableset'">
66 <xsl:apply-templates select="model" mode="tableset"/>
67 </xsl:when>
68 <xsl:when test="$mode = 'tap_schema'">
69 <xsl:apply-templates select="model" mode="tap_schema"/>
70 </xsl:when>
71 <xsl:when test="$mode = 'vodataservice'">
72 <xsl:apply-templates select="model" mode="vodataservice"/>
73 </xsl:when>
74 <xsl:otherwise>
75 UNKNOWN TAP metadata mode <xsl:value-of select="$mode"/>
76 </xsl:otherwise>
77 </xsl:choose>
78
79 </xsl:template>
80
81
82
83
84
85
86 <!--
87 This template assumes that the public database schema is described as a collection
88 of <TABLE>-s, with the <FIELD>-s describing the columns and no <DATA> element.
89 -->
90 <xsl:template match="model" mode="tableset">
91 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
92 -- Generating TAP-tableset metadata-like VOTables for model <xsl:value-of select="name"/> and DB vendor <xsl:value-of select="$vendor"/>.
93 <xsl:value-of select="$header"/>
94
95 <!-- CREATE TAP-type 1 votable -->
96 <xsl:variable name="file" select="concat(name,'_tap_tableset.xml')"/>
97 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
98 <xsl:result-document href="{$file}">
99
100 <xsl:element name="VOTABLE">
101 <xsl:attribute name="xlmns" select="$votablenamespace"/>
102 <xsl:attribute name="version" select="'1.1'"/>
103 <xsl:element name="RESOURCE">
104 <xsl:attribute name="name" select="name"/>
105 <xsl:element name="DESCRIPTION">
106 <xsl:value-of select="description"/>
107 </xsl:element>
108 <xsl:apply-templates select="package[objectType]" mode="tableset"/>
109 </xsl:element>
110 </xsl:element>
111 </xsl:result-document>
112 </xsl:template>
113
114
115
116
117
118 <xsl:template match="package" mode="tableset">
119 <xsl:param name="utypeprefix"/>
120 <xsl:element name="RESOURCE">
121 <xsl:attribute name="name" select="name"/>
122 <xsl:element name="DESCRIPTION">
123 <xsl:value-of select="description"/>
124 </xsl:element>
125 <xsl:apply-templates select="objectType" mode="tableset">
126 <xsl:sort select="name"/>
127 </xsl:apply-templates>
128 <xsl:apply-templates select="package" mode="tableset"/>
129 </xsl:element>
130 </xsl:template>
131
132
133
134
135
136
137 <!--
138 This template assumes that the public database schema is described as a collection
139 of <TABLE>-s, with the <FIELD>-s describing the columns and no <DATA> element.
140 -->
141
142 <xsl:template match="objectType" mode="tableset">
143 <xsl:variable name="utype">
144 <xsl:apply-templates select="." mode="utype"/>
145 </xsl:variable>
146
147 <xsl:element name="TABLE">
148 <xsl:attribute name="name">
149 <xsl:apply-templates select="." mode="viewName"/>
150 </xsl:attribute>
151 <xsl:element name="DESCRIPTION">
152 <xsl:value-of select="description"/>
153 </xsl:element>
154
155 <xsl:apply-templates select="." mode="tap_fields"/>
156 </xsl:element>
157
158 </xsl:template>
159
160 <xsl:template match="objectType" mode="tap_fields">
161
162 <xsl:variable name="utype">
163 <xsl:apply-templates select="." mode="utype"/>
164 </xsl:variable>
165 <xsl:choose>
166 <xsl:when test="extends">
167 <xsl:apply-templates select="key('element',extends/@xmiidref)" mode="tap_fields"/>
168 </xsl:when>
169 <xsl:otherwise>
170 <xsl:element name="FIELD">
171 <xsl:attribute name="name" select="$primaryKeyColumnName"/>
172 <xsl:attribute name="datatype" select="'long'"/>
173 <xsl:attribute name="ucd" select="'TBD'"/>
174 <xsl:attribute name="utype" select="concat($utype,'.',$primaryKeyColumnName)"/>
175 <xsl:element name="DESCRIPTION">
176 <xsl:text>The unique, primary key column on this table.</xsl:text>
177 </xsl:element>
178 </xsl:element>
179 <xsl:element name="FIELD">
180 <xsl:attribute name="name" select="$discriminatorColumnName"/>
181 <xsl:attribute name="datatype" select="'char'"/>
182 <xsl:attribute name="width" select="$discriminatorColumnLength"/>
183 <xsl:attribute name="ucd" select="'TBD'"/>
184 <xsl:attribute name="utype" select="'TBD'"/>
185 <xsl:element name="DESCRIPTION">
186 <xsl:text>This column stores the name of the object type from the data model stored in the row.</xsl:text>
187 </xsl:element>
188 </xsl:element>
189 </xsl:otherwise>
190 </xsl:choose>
191
192
193 <xsl:if test="container">
194 <xsl:element name="FIELD">
195 <xsl:attribute name="name" select="'containerId'"/>
196 <xsl:attribute name="datatype" select="'long'"/>
197 <xsl:attribute name="ucd" select="'TBD'"/>
198 <xsl:attribute name="utype" select="concat($utype,'.CONTAINER')"/>
199 <xsl:element name="DESCRIPTION">
200 <xsl:text>This column is a foreign key pointing to the containing object in </xsl:text>
201 <xsl:apply-templates select="key('element',container/@xmiidref)" mode="viewName"/>
202 </xsl:element>
203 </xsl:element>
204 </xsl:if>
205 <xsl:for-each select="attribute">
206 <xsl:variable name="columns">
207 <xsl:apply-templates select="." mode="columns">
208 <xsl:with-param name="utypeprefix" select="$utype"/>
209 </xsl:apply-templates>
210 </xsl:variable>
211 <xsl:for-each select="exsl:node-set($columns)/column">
212 <xsl:element name="FIELD">
213 <xsl:attribute name="name">
214 <xsl:value-of select="name"/>
215 </xsl:attribute>
216 <xsl:variable name="votabletype">
217 <xsl:call-template name="votabletype">
218 <xsl:with-param name="type" select="type"/>
219 </xsl:call-template>
220 </xsl:variable>
221 <xsl:attribute name="datatype" select="$votabletype"/>
222 <xsl:if test="$votabletype='char'">
223 <xsl:attribute name="width">
224 <xsl:variable name ="length">
225 <xsl:call-template name="stringlength">
226 <xsl:with-param name="constraints" select="constraints"/>
227 </xsl:call-template>
228 </xsl:variable>
229 <xsl:choose>
230 <xsl:when test="number($length) &lt;= 0"><xsl:text>*</xsl:text></xsl:when>
231 <xsl:otherwise><xsl:value-of select="$length"/></xsl:otherwise>
232 </xsl:choose>
233 </xsl:attribute>
234 </xsl:if>
235 <xsl:attribute name="utype" select="utype"/>
236 <xsl:element name="DESCRIPTION" >
237 <xsl:value-of select="description"/>
238 </xsl:element>
239 </xsl:element>
240 </xsl:for-each>
241 </xsl:for-each>
242 <xsl:for-each select="reference[not(subsets)]">
243 <xsl:element name="FIELD">
244 <xsl:attribute name="name">
245 <xsl:apply-templates select="." mode="columnName"/>
246 </xsl:attribute>
247 <xsl:attribute name="datatype" select="'long'"/>
248 <xsl:attribute name="ucd" select="'TBD'"/>
249 <xsl:attribute name="utype" select="'TBD'"/>
250 <xsl:element name="DESCRIPTION">
251 <xsl:value-of select="description"/>&cr;
252 <xsl:text>This column is a foreign key pointing to the referenced object in </xsl:text>
253 <xsl:apply-templates select="key('element',datatype/@xmiidref)" mode="viewName"/><xsl:text>.
254 </xsl:text>
255 </xsl:element>
256 </xsl:element>
257 </xsl:for-each>
258 </xsl:template>
259
260
261
262
263 <!-- TAP_SCHEMA stype -->
264
265 <!--
266 Generates metadata for the TAP_SCHEMA approach to metadata.
267 Does this by creating a result that creates tables in the TAP_SCHEMA describing the tables and columns
268 available to users.
269 Then fills these with the metadata using imsple insert statements.
270 -->
271 <xsl:template match="model" mode="tap_schema">
272 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
273 -- Generating TAP-tap_schema like metadata for model <xsl:value-of select="name"/> and DB vendor <xsl:value-of select="$vendor"/>.
274 <xsl:value-of select="$header"/>
275
276 <xsl:variable name="file" select="concat(name,'_tap_schema.sql')"/>
277 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
278 <xsl:result-document href="{$file}" format="text-format">
279 <xsl:text>-- TAP_SCHEMA definition </xsl:text>
280 <xsl:call-template name="TAP_SCHEMA_tables"/>&cr;&cr;
281 <xsl:text>-- tables and column inserts per objecttype</xsl:text>&cr;&cr;
282 <xsl:apply-templates select=".//objectType" mode="tap_schema"/>
283
284 <xsl:value-of select="$commit"/>
285
286 </xsl:result-document>
287 </xsl:template>
288
289
290 <xsl:template name="TAP_SCHEMA_tables">
291
292 <xsl:text>
293 DROP TABLE TAP_SCHEMA.Columns
294 DROP TABLE TAP_SCHEMA.Tables
295 DROP SCHEMA TAP_SCHEMA
296 </xsl:text>
297 <xsl:value-of select="$commit"/>
298
299 <xsl:text>
300 CREATE SCHEMA TAP_SCHEMA
301 </xsl:text>
302 <xsl:value-of select="$commit"/>
303 <xsl:text>
304 CREATE TABLE TAP_SCHEMA.Tables (
305 tableName varchar(128) not null,
306 tableType varchar(16) not null,
307 description </xsl:text><xsl:value-of select="$unboundedstringtype"/><xsl:text>,
308 utype varchar(128)
309 )
310
311 CREATE TABLE TAP_SCHEMA.Columns (
312 name varchar(128) not null,
313 tableName varchar(128) not null,
314 description </xsl:text><xsl:value-of select="$unboundedstringtype"/><xsl:text>,
315 unit varchar(64),
316 ucd varchar(64),
317 utype varchar(128),
318 datatype varchar(64),
319 arraysize varchar(16),
320 "primary" char(1), -- assume T or F
321 indexed char(1), -- assume T or F
322 std char(1) -- assume T or F
323 )
324 </xsl:text>
325 <xsl:value-of select="$commit"/>
326 <xsl:text>
327
328 INSERT INTO TAP_SCHEMA.Tables VALUES('TAP_SCHEMA.Tables','base_table','the table storing metadata about the tables in this TAP service',null)
329 INSERT INTO TAP_SCHEMA.Tables VALUES('TAP_SCHEMA.Columns','base_table','the table storing metadata about the columns in this TAP service',null)
330 -- TODO add TAP_SCHEMA table columns
331 </xsl:text>
332 <xsl:value-of select="$commit"/>
333 </xsl:template>
334
335
336
337 <xsl:template match="objectType" mode="tap_schema">
338 <xsl:variable name="tap_name">
339 <xsl:apply-templates select="." mode="viewName"/>
340 </xsl:variable>
341 <xsl:variable name="utype">
342 <xsl:apply-templates select="." mode="utype"/>
343 </xsl:variable>
344
345 <xsl:text>INSERT INTO TAP_SCHEMA.Tables(tableName,tableType,description,utype)values(</xsl:text>&cr;
346 '<xsl:value-of select="$tap_name"/>'
347 , 'view'
348 , '<xsl:value-of select="replace(description,&quot;'&quot;,&quot;''&quot;)"/>'
349 , '<xsl:value-of select="$utype"/>'
350 )
351
352 <xsl:apply-templates select="." mode="tap_schema_columns">
353 <xsl:with-param name="tableName">
354 <xsl:value-of select="$tap_name"/>
355 </xsl:with-param>
356 </xsl:apply-templates>
357 </xsl:template>
358
359 <xsl:template match="objectType" mode="tap_schema_columns">
360 <xsl:param name="tableName"/>
361 <xsl:variable name="utype">
362 <xsl:apply-templates select="." mode="utype"/>
363 </xsl:variable>
364
365 <xsl:choose>
366 <xsl:when test="extends">
367 <xsl:apply-templates select="key('element',extends/@xmiidref)" mode="tap_schema_columns">
368 <xsl:with-param name="tableName" select="$tableName"/>
369 </xsl:apply-templates>
370 </xsl:when>
371 <xsl:otherwise>
372 <xsl:call-template name="insertcolumn">
373 <xsl:with-param name="name"><xsl:value-of select="$primaryKeyColumnName"/></xsl:with-param>
374 <xsl:with-param name="tableName"><xsl:value-of select="$tableName"/></xsl:with-param>
375 <xsl:with-param name="description"><xsl:text>The unique, primary key column on this table.</xsl:text></xsl:with-param>
376 <xsl:with-param name="ucd"><xsl:text>TBD</xsl:text></xsl:with-param>
377 <xsl:with-param name="utype"><xsl:value-of select="concat($utype,'.',$primaryKeyColumnName)"/></xsl:with-param>
378 <xsl:with-param name="datatype"><xsl:text>long</xsl:text></xsl:with-param>
379 </xsl:call-template>
380 <xsl:call-template name="insertcolumn">
381 <xsl:with-param name="name"><xsl:value-of select="$discriminatorColumnName"/></xsl:with-param>
382 <xsl:with-param name="tableName"><xsl:value-of select="$tableName"/></xsl:with-param>
383 <xsl:with-param name="description"><xsl:text>This column stores the name of the object type from the data model stored in the row.</xsl:text></xsl:with-param>
384 <xsl:with-param name="ucd"><xsl:text>TBD</xsl:text></xsl:with-param>
385 <xsl:with-param name="utype"><xsl:text>TBD</xsl:text></xsl:with-param>
386 <xsl:with-param name="datatype"><xsl:text>char</xsl:text></xsl:with-param>
387 <xsl:with-param name="arraysize"><xsl:value-of select="$discriminatorColumnLength"/></xsl:with-param>
388 </xsl:call-template>
389 </xsl:otherwise>
390 </xsl:choose>
391
392 <xsl:if test="container">
393 <xsl:call-template name="insertcolumn">
394 <xsl:with-param name="name"><xsl:value-of select="$containerColumnName"/></xsl:with-param>
395 <xsl:with-param name="tableName"><xsl:value-of select="$tableName"/></xsl:with-param>
396 <xsl:with-param name="description"><xsl:text>This column is a foreign key pointing to the containing object in </xsl:text>
397 <xsl:apply-templates select="key('element',container/@xmiidref)" mode="viewName"/>
398 </xsl:with-param>
399 <xsl:with-param name="ucd"><xsl:text>TBD</xsl:text></xsl:with-param>
400 <xsl:with-param name="utype"><xsl:value-of select="concat($utype,'.CONTAINER')"/></xsl:with-param>
401 <xsl:with-param name="datatype"><xsl:text>long</xsl:text></xsl:with-param>
402 </xsl:call-template>
403 </xsl:if>
404
405 <xsl:for-each select="attribute">
406 <xsl:variable name="columns">
407 <xsl:apply-templates select="." mode="columns">
408 <xsl:with-param name="utypeprefix" select="$utype"/>
409 </xsl:apply-templates>
410 </xsl:variable>
411 <xsl:for-each select="exsl:node-set($columns)/column">
412 <xsl:variable name="votabletype">
413 <xsl:call-template name="votabletype">
414 <xsl:with-param name="type" select="type"/>
415 </xsl:call-template>
416 </xsl:variable>
417
418 <xsl:call-template name="insertcolumn">
419 <xsl:with-param name="name"><xsl:value-of select="name"/></xsl:with-param>
420 <xsl:with-param name="tableName"><xsl:value-of select="$tableName"/></xsl:with-param>
421 <xsl:with-param name="description"><xsl:value-of select="description"/></xsl:with-param>
422 <xsl:with-param name="ucd"><xsl:text>TBD</xsl:text></xsl:with-param>
423 <xsl:with-param name="utype"><xsl:value-of select="utype"/></xsl:with-param>
424 <xsl:with-param name="datatype"><xsl:value-of select="$votabletype"/></xsl:with-param>
425 <xsl:with-param name="arraysize" >
426 <xsl:choose>
427 <xsl:when test="$votabletype = 'char'">
428 <xsl:variable name ="length">
429 <xsl:call-template name="stringlength">
430 <xsl:with-param name="constraints" select="constraints"/>
431 </xsl:call-template>
432 </xsl:variable>
433 <xsl:choose>
434 <xsl:when test="number($length) &lt;= 0"><xsl:text>*</xsl:text></xsl:when>
435 <xsl:otherwise><xsl:value-of select="$length"/></xsl:otherwise>
436 </xsl:choose>
437 </xsl:when>
438 <xsl:otherwise><xsl:text>1</xsl:text></xsl:otherwise>
439 </xsl:choose>
440 </xsl:with-param>
441 </xsl:call-template>
442 </xsl:for-each>
443 </xsl:for-each>
444 <xsl:for-each select="reference[not(subsets)]">
445 <xsl:call-template name="insertcolumn">
446 <xsl:with-param name="name"><xsl:apply-templates select="." mode="columnName"/></xsl:with-param>
447 <xsl:with-param name="tableName"><xsl:value-of select="$tableName"/></xsl:with-param>
448 <xsl:with-param name="description"><xsl:value-of select="description"/>&cr;
449 <xsl:text>[This column is a foreign key pointing to the referenced object in </xsl:text>
450 <xsl:apply-templates select="key('element',datatype/@xmiidref)" mode="viewName"/><xsl:text>].
451 </xsl:text></xsl:with-param>
452 <xsl:with-param name="ucd"><xsl:text>TBD</xsl:text></xsl:with-param>
453 <xsl:with-param name="utype"><xsl:text>TBD</xsl:text></xsl:with-param>
454 <xsl:with-param name="datatype"><xsl:text>long</xsl:text></xsl:with-param>
455 </xsl:call-template>
456 </xsl:for-each>
457
458 </xsl:template>
459
460 <xsl:template name="insertcolumn">
461 <xsl:param name="name"/>
462 <xsl:param name="tableName"/>
463 <xsl:param name="description"/>
464 <xsl:param name="unit"/>
465 <xsl:param name="ucd"/>
466 <xsl:param name="utype"/>
467 <xsl:param name="datatype"/>
468 <xsl:param name="arraysize" select="'1'"/>
469 <xsl:param name="primary" select="'T'"/>
470 <xsl:param name="indexed" select="'T'"/>
471 <xsl:param name="std" select="'T'"/>
472 <!-- TODO this can be simplieified, the INSERT INTO ... does not have to be repeated,
473 only comma-separated list of values (within () ) is required. More efficient as well. -->
474 <xsl:text>INSERT INTO TAP_SCHEMA.Columns(name, tableName,description,unit,ucd,utype,datatype,arraysize,"primary",indexed,std)values(</xsl:text>
475 '<xsl:value-of select="$name"/>'
476 , '<xsl:value-of select="$tableName"/>'
477 , '<xsl:value-of select="replace($description,&quot;'&quot;,&quot;''&quot;)"/>'
478 , <xsl:choose><xsl:when test="not($unit)">null</xsl:when><xsl:otherwise>'<xsl:value-of select="$unit"/>'</xsl:otherwise></xsl:choose>
479 , <xsl:choose><xsl:when test="not($ucd)">null</xsl:when><xsl:otherwise>'<xsl:value-of select="$ucd"/>'</xsl:otherwise></xsl:choose>
480 , <xsl:choose><xsl:when test="not($utype)">null</xsl:when><xsl:otherwise>'<xsl:value-of select="$utype"/>'</xsl:otherwise></xsl:choose>
481 , '<xsl:value-of select="$datatype"/>'
482 , '<xsl:value-of select="$arraysize"/>'
483 , '<xsl:value-of select="$primary"/>'
484 , '<xsl:value-of select="$indexed"/>'
485 , '<xsl:value-of select="$std"/>')&cr;
486 </xsl:template>
487
488
489
490 <!--
491 Use VOSI/VODataService specification.
492 Following example in http://wfaudata.roe.ac.uk/ukidssWorld-dsa/wsa/vosi/tables
493 as suggested in http://www.ivoa.net/internal/IVOA/TableAccess/TAP-QL-0.1.pdf
494 -->
495 <!--
496 This template assumes that the public database schema is described as a collection
497 of <table>-s, with <column>-s describing the columns.
498 -->
499 <xsl:template match="model" mode="vodataservice">
500 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
501 -- Generating VODataService like metadata for model <xsl:value-of select="name"/>.
502 <xsl:value-of select="$header"/>
503
504 <xsl:variable name="file" select="concat(name,'_vodataservice.xml')"/>
505 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
506
507 <xsl:result-document href="{$file}">
508
509 <xsl:element name="tab:tables">
510 <xsl:namespace name="vr">http://www.ivoa.net/xml/VOResource/v1.0</xsl:namespace>
511 <xsl:namespace name="vs">http://www.ivoa.net/xml/VODataService/v1.0</xsl:namespace>
512 <xsl:namespace name="tab">urn:astrogrid:schema:TableMetadata</xsl:namespace>
513 <xsl:namespace name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:namespace>
514 <xsl:attribute name="xsi:schemaLocation">
515 <xsl:text>http://www.ivoa.net/xml/VOResource/v1.0 http://software.astrogrid.org/schema/vo-resource-types/VOResource/v1.0/VOResource.xsd http://www.ivoa.net/xml/VODataService/v1.0 http://software.astrogrid.org/schema/vo-resource-types/VODataService/v1.0/VODataService.xsd urn:astrogrid:schema:TableMetadata http://wfaudata.roe.ac.uk/ukidssWorld-dsa/schema/Tables.xsd</xsl:text>
516 </xsl:attribute>
517
518 <!--
519 xsi:schemaLocation="http://www.ivoa.net/xml/VOResource/v1.0 http://software.astrogrid.org/schema/vo-resource-types/VOResource/v1.0/VOResource.xsd http://www.ivoa.net/xml/VODataService/v1.0 http://software.astrogrid.org/schema/vo-resource-types/VODataService/v1.0/VODataService.xsd urn:astrogrid:schema:TableMetadata http://wfaudata.roe.ac.uk/ukidssWorld-dsa/schema/Tables.xsd
520 -->
521 <xsl:apply-templates select="//objectType" mode="vodataservice">
522 <xsl:sort select="name"/>
523 </xsl:apply-templates>
524 </xsl:element>
525 </xsl:result-document>
526 </xsl:template>
527
528
529
530 <!--
531 This template assumes that the public database schema is described as a collection
532 of <table>-s, with <column>-s describing the columns.
533 -->
534
535 <xsl:template match="objectType" mode="vodataservice">
536 <xsl:variable name="utype">
537 <xsl:apply-templates select="." mode="utype"/>
538 </xsl:variable>
539
540 <xsl:element name="table">
541 <xsl:element name="name">
542 <xsl:apply-templates select="." mode="viewName"/>
543 </xsl:element>
544 <xsl:element name="description">
545 <xsl:value-of select="description"/>
546 </xsl:element>
547 <xsl:apply-templates select="." mode="vodataservice_columns"/>
548 </xsl:element>
549 </xsl:template>
550
551 <xsl:template match="objectType" mode="vodataservice_columns">
552 <xsl:variable name="utype">
553 <xsl:apply-templates select="." mode="utype"/>
554 </xsl:variable>
555 <xsl:choose>
556 <xsl:when test="extends">
557 <xsl:apply-templates select="key('element',extends/@xmiidref)" mode="vodataservice_columns"/>
558 </xsl:when>
559 <xsl:otherwise>
560 <xsl:call-template name="vodataservice_column">
561 <xsl:with-param name="name" select="$primaryKeyColumnName"/>
562 <xsl:with-param name="description">
563 <xsl:text>The unique, primary key column on this table.</xsl:text>
564 </xsl:with-param>
565 <xsl:with-param name="datatype" select="'long'"/>
566 <xsl:with-param name="ucd" select="'TBD'"/>
567 <xsl:with-param name="utype" select="concat($utype,'.',$primaryKeyColumnName)"/>
568 </xsl:call-template>
569
570 <xsl:call-template name="vodataservice_column">
571 <xsl:with-param name="name" select="$discriminatorColumnName"/>
572 <xsl:with-param name="description">
573 <xsl:text>This column stores the name of the object type from the data model stored in the row.</xsl:text>
574 </xsl:with-param>
575 <xsl:with-param name="datatype" select="'char'"/>
576 <xsl:with-param name="width" select="$discriminatorColumnLength"/>
577 <xsl:with-param name="ucd" select="'TBD'"/>
578 <xsl:with-param name="utype" select="concat($utype,'.CONTAINER')"/>
579 </xsl:call-template>
580
581 </xsl:otherwise>
582 </xsl:choose>
583
584 <xsl:if test="container">
585 <xsl:call-template name="vodataservice_column">
586 <xsl:with-param name="name" select="'containerId'"/>
587 <xsl:with-param name="description">
588 <xsl:text>This column is a foreign key pointing to the containing object in </xsl:text>
589 <xsl:apply-templates select="key('element',container/@xmiidref)" mode="viewName"/>
590 </xsl:with-param>
591 <xsl:with-param name="datatype" select="'long'"/>
592 <xsl:with-param name="ucd" select="'TBD'"/>
593 <xsl:with-param name="utype" select="concat($utype,'.CONTAINER')"/>
594 </xsl:call-template>
595 </xsl:if>
596 <xsl:for-each select="attribute">
597 <xsl:variable name="columns">
598 <xsl:apply-templates select="." mode="columns">
599 <xsl:with-param name="utypeprefix" select="$utype"/>
600 </xsl:apply-templates>
601 </xsl:variable>
602 <xsl:for-each select="exsl:node-set($columns)/column">
603 <xsl:variable name="votabletype">
604 <xsl:call-template name="votabletype">
605 <xsl:with-param name="type" select="type"/>
606 </xsl:call-template>
607 </xsl:variable>
608
609 <xsl:call-template name="vodataservice_column">
610 <xsl:with-param name="name" select="name"/>
611 <xsl:with-param name="description" select="description"/>
612 <xsl:with-param name="datatype" select="$votabletype"/>
613 <xsl:with-param name="ucd" select="'TBD'"/>
614 <xsl:with-param name="utype" select="utype"/>
615 </xsl:call-template>
616 </xsl:for-each>
617 </xsl:for-each>
618
619 <xsl:for-each select="reference[not(subsets)]">
620 <xsl:call-template name="vodataservice_column">
621 <xsl:with-param name="name">
622 <xsl:apply-templates select="." mode="columnName"/>
623 </xsl:with-param>
624 <xsl:with-param name="description" select="description"/>
625 <xsl:with-param name="datatype" select="'long'"/>
626 <xsl:with-param name="ucd" select="'TBD'"/>
627 <xsl:with-param name="utype" select="'TBD'"/>
628 </xsl:call-template>
629 </xsl:for-each>
630 </xsl:template>
631
632
633
634 <xsl:template name="vodataservice_column">
635 <xsl:param name="name"/>
636 <xsl:param name="tableName"/>
637 <xsl:param name="description"/>
638 <xsl:param name="unit"/>
639 <xsl:param name="ucd"/>
640 <xsl:param name="utype"/>
641 <xsl:param name="datatype"/>
642 <xsl:param name="width"/>
643
644 <xsl:element name="column">
645 <xsl:element name="name"><xsl:value-of select="$name"/></xsl:element>
646 <xsl:element name="description"><xsl:value-of select="$description"/></xsl:element>
647 <xsl:if test="$unit"><xsl:element name="unit"><xsl:value-of select="$unit"/></xsl:element></xsl:if>
648 <xsl:if test="$ucd"><xsl:element name="ucd"><xsl:value-of select="$ucd"/></xsl:element></xsl:if>
649 <xsl:if test="$utype"><xsl:element name="utype"><xsl:value-of select="$utype"/></xsl:element></xsl:if>
650 <xsl:element name="dataType"><xsl:value-of select="$datatype"/></xsl:element>
651 <xsl:if test="$width"><xsl:element name="width"><xsl:value-of select="$width"/></xsl:element></xsl:if>
652 </xsl:element>
653 </xsl:template>
654
655
656
657
658 <!-- UTIL -->
659
660 <xsl:template name="votabletype">
661 <xsl:param name="type"/>
662
663 <!--
664 Primitive types :
665 boolean
666 short
667 int
668 long
669 float
670 double
671
672 Date type :
673 datetime
674
675 Characters type :
676 string
677
678 Unsupported type (later) => string :
679 complex
680 rational
681 -->
682 <xsl:choose>
683 <xsl:when test="$type = 'boolean'">boolean</xsl:when>
684 <xsl:when test="$type = 'complex'">complex</xsl:when>
685 <xsl:when test="$type = 'short'">short</xsl:when>
686 <xsl:when test="$type = 'integer'">integer</xsl:when>
687 <xsl:when test="$type = 'long'">long</xsl:when>
688 <xsl:when test="$type = 'float'">float</xsl:when>
689 <xsl:when test="$type = 'double'">double</xsl:when>
690 <xsl:when test="$type = 'datetime'">datetime</xsl:when>
691 <xsl:otherwise>char</xsl:otherwise>
692 </xsl:choose>
693 </xsl:template>
694
695
696
697
698 </xsl:stylesheet>

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