summaryrefslogtreecommitdiff
path: root/share/gcstar/xslt/createGCSValidator.xsl
blob: 2df922ac62e3659c9a65a32a42efa3e5d298e9f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : ConvertGCMtoXSD.xsl
    Created on : April 26, 2007, 9:41 PM
    Version    : The first one ;)
    Author     : toroman
    Description:
       Transforms GCM into XSD which can validate GCS files.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
        
    <xsl:output method="xml" indent="yes" />
    
    <xsl:template match="/">
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:complexType name="itemType">
                <xs:sequence>
                    <xsl:apply-templates select="/collection/fields/field" />
                </xs:sequence>
            </xs:complexType>
            <xs:element name="collection">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="information">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="name" type="xs:string" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="item" maxOccurs="unbounded" type="itemType" />
                    </xs:sequence>
                    <xs:attribute name="type" type="xs:string" />
                    <xs:attribute name="items" type="xs:integer" />
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </xsl:template>

    <xsl:template match="/collection/fields/field">
        <xsl:choose>
            <xsl:when test="@type='file'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='number'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:integer" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='options'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:integer" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='age'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:integer" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='short text'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='image'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='long text'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='button'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='yesno'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:boolean" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='date'">
                <xsl:text disable-output-escaping="yes"><![CDATA[
                <xs:element name="]]></xsl:text>
                    <xsl:value-of select="@value" /> 
                    <xsl:text disable-output-escaping="yes"><![CDATA[">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:pattern value="\d\d/\d\d/\d\d\d\d" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='single list'">
                <xsl:text disable-output-escaping="yes"><![CDATA[
                <xs:element name="]]></xsl:text>
                    <xsl:value-of select="@value" /> 
                    <xsl:text disable-output-escaping="yes"><![CDATA[">
                    <xs:complexType>
                        <xs:sequence maxOccurs="unbounded">
                            <xs:element name="line" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence minOccurs="1" maxOccurs="1">
                                        <xs:element name="col" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='double list'">
                <xsl:text disable-output-escaping="yes"><![CDATA[
                <xs:element name="]]></xsl:text>
                    <xsl:value-of select="@value" /> 
                    <xsl:text disable-output-escaping="yes"><![CDATA[">
                    <xs:complexType>
                        <xs:sequence maxOccurs="unbounded">
                            <xs:element name="line" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence minOccurs="2" maxOccurs="2">
                                        <xs:element name="col" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                ]]></xsl:text>
            </xsl:when>
            <xsl:when test="@type='history text'">
                <xsl:text disable-output-escaping="yes"><![CDATA[<xs:element name="]]></xsl:text>
                <xsl:value-of select="@value" /> 
                <xsl:text disable-output-escaping="yes"><![CDATA[" type="xs:string" />
                ]]></xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <p>
                    <xsl:text>Unknown Type - this should trigger error on XSD validation! </xsl:text> 
                    <xsl:value-of select="@type" />
                </p><![CDATA[
                ]]>                
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>