source: mauRepo/newmoon/src/test/resources/resources/dependency/GenerateFromXSD.xsl @ 7927

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/newmoon/src/test/resources/resources/dependency/GenerateFromXSD.xsl@7927
Revision 7927, 3.9 KB checked in by mnagni, 9 years ago (diff)
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
4    xmlns:xs="http://www.w3.org/2001/XMLSchema"
5    xmlns="urn:x-auscope:xmlns:CSIRO:FullMoon:package-class-map:2.0"
6    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
7    exclude-result-prefixes="xd"
8    version="2.0">
9    <xd:doc scope="stylesheet">
10        <xd:desc>
11            <xd:p><xd:b>Created on:</xd:b> Jan 12, 2011</xd:p>
12            <xd:p><xd:b>Author:</xd:b>Rob Atkinson</xd:p>
13            <xd:p>Creates a template FulMoon ClassMap from a GML schema - creates a stub mapping for each element</xd:p>
14        </xd:desc>
15    </xd:doc>
16    <xsl:output method="xml" indent="yes"/>
17    <xsl:param name="schemaloc" select="/*/@base"></xsl:param>
18    <xsl:param name="tns"><xsl:value-of select="/xs:schema/@targetNamespace"/></xsl:param> 
19    <xsl:variable name="in-xml" select="/*"/>
20       
21    <xsl:variable name="namespace-prefix">
22        <xsl:for-each select="in-scope-prefixes($in-xml)">
23            <xsl:if test="namespace-uri-for-prefix(.,$in-xml)=$tns"><xsl:value-of select="."></xsl:value-of></xsl:if>
24        </xsl:for-each>
25    </xsl:variable>
26   
27 <xsl:template match="/xs:schema">
28 
29        <mapping  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
30
31           
32           
33            xsi:schemaLocation="urn:x-auscope:xmlns:CSIRO:FullMoon:package-class-map:2.0 http://projects.arcs.org.au/svn/fullmoon/trunk/resources/dependency-util/package-class-map.xsd"
34            id="ClassMap_{$namespace-prefix}.xml">
35             <xsl:namespace name="{$namespace-prefix}"><xsl:value-of select="$tns"></xsl:value-of></xsl:namespace>
36        <description>Provides a mapping of test classes to their XML implementation.</description>
37        <imports>
38            <schema prefix="{$namespace-prefix}" namespace="{$tns}" schemaLocation="{$schemaloc}" />
39        </imports>
40<xsl:apply-templates select="xs:element"/> 
41<xsl:apply-templates select="xs:simpleType"/>  <!-- look for CodeLists -->
42</mapping>
43</xsl:template>
44
45<xsl:template  match="xs:element">
46    <entry>
47        <umlClass><xsl:value-of select="@name"/></umlClass> 
48        <gmlObjectElement><xsl:value-of select="$namespace-prefix"/>:<xsl:value-of select="@name"/></gmlObjectElement> 
49        <gmlType><xsl:value-of select="$namespace-prefix"/>:<xsl:value-of select="@name"/>Type</gmlType> 
50        <gmlPropertyType><xsl:value-of select="$namespace-prefix"/>:<xsl:value-of select="@name"/>PropertyType</gmlPropertyType> 
51    </entry>
52</xsl:template> 
53
54<!-- handle CodeLists -->
55    <!-- TO do - handle DataTypes and Enumerations -->
56<xsl:template match="xs:simpleType">
57    <!-- remove extraneous Type - we want the classname -->
58    <xsl:variable name="umlname"><xsl:value-of select="substring(@name,0,string-length(@name)-3)"/></xsl:variable>
59    <xsl:variable name="umlcheck"><xsl:value-of select="$umlname"/>EnumerationType</xsl:variable>
60    <!-- check it is a class name - i.e. will have a *EnumerationType and *OtherType -->   
61    <xsl:if test="exists(../xs:simpleType[@name=$umlcheck])" >
62    <entry>
63        <umlClass><xsl:value-of select="$umlname"/></umlClass>
64        <umlStereotype>CodeList</umlStereotype>
65        <gmlObjectElement xsi:nil="true"/>
66        <gmlType xsi:nil="true"/>
67        <gmlPropertyType><xsl:value-of select="$namespace-prefix"/>:<xsl:value-of select="@name"/></gmlPropertyType> 
68    </entry>
69    </xsl:if>     
70    <xsl:if test="exists(xs:restriction/xs:enumeration)" >
71        <entry>
72            <umlClass><xsl:value-of select="$umlname"/></umlClass>
73            <umlStereotype>Enumeration</umlStereotype>
74            <gmlObjectElement xsi:nil="true"/>
75            <gmlType xsi:nil="true"/>
76            <gmlPropertyType><xsl:value-of select="$namespace-prefix"/>:<xsl:value-of select="@name"/></gmlPropertyType> 
77        </entry>
78    </xsl:if>     
79   
80</xsl:template>
81 
82</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.