-
Notifications
You must be signed in to change notification settings - Fork 2
/
legacy-rdfs.xsl
281 lines (265 loc) · 16.9 KB
/
legacy-rdfs.xsl
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2024 UCAIug
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xsl:stylesheet exclude-result-prefixes="a" version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cims="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:a="http://langdale.com.au/2005/Message#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:uml="http://langdale.com.au/2005/UML#" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output xmlns:xalan="http://xml.apache.org/xslt" method="xml" omit-xml-declaration="no" indent="yes" xalan:indent-amount="4" />
<xsl:param name="copyright" />
<xsl:param name="version"/>
<xsl:param name="baseURI"/>
<xsl:param name="ontologyURI"/>
<xsl:param name="envelope">Profile</xsl:param>
<!-- The following <xsl:text> element is our newline representation where needed. -->
<xsl:param name="newline"><xsl:text>
</xsl:text></xsl:param>
<xsl:template match="a:Catalog">
<xsl:value-of select="$newline"/>
<xsl:if test="$copyright and $copyright != ''">
<xsl:comment><xsl:value-of select="$newline"/><xsl:value-of select="$copyright" disable-output-escaping="yes"/><xsl:value-of select="$newline"/></xsl:comment>
</xsl:if>
<xsl:value-of select="$newline"/>
<rdf:RDF>
<xsl:attribute name="xml:base" select="$ontologyURI"/>
<xsl:variable name="rdf" as="node()*">
<xsl:apply-templates select=".//*"/>
</xsl:variable>
<xsl:perform-sort select="$rdf">
<xsl:sort select="@rdf:about"/>
</xsl:perform-sort>
</rdf:RDF>
</xsl:template>
<!-- ============================================================================================================ -->
<!-- START SECTION: (Packages, ComplexType, Root, EnumeratedType, SimpleType, Complex, & CompoundType(s) -->
<!-- templates) i.e. All "top level" element in the XML profile definition file... -->
<!-- ============================================================================================================ -->
<xsl:template match="a:Package">
<rdf:Description rdf:about="{if (starts-with(@basePackage, $ontologyURI)) then concat('#', substring-after(@basePackage, '#')) else @basePackage }">
<xsl:for-each select="a:ParentPackage">
<cims:belongsToCategory rdf:resource="{if (starts-with(@basePackage, $ontologyURI)) then concat('#', substring-after(@basePackage, '#')) else @basePackage }"/>
</xsl:for-each>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#ClassCategory"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
</rdf:Description>
</xsl:template>
<xsl:template match="a:Root|a:ComplexType|a:EnumeratedType">
<rdf:Description rdf:about="{if (starts-with(@baseClass, $ontologyURI)) then concat('#', substring-after(@baseClass, '#')) else @baseClass }">
<cims:belongsToCategory rdf:resource="{if (starts-with(@packageURI, $ontologyURI)) then concat('#', substring-after(@packageURI, '#')) else @packageURI }"/>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<!-- For top level classes (i.e. a:Root, a:ComplexType, a:EnumeratedType) we obtain the name
of the class for the rdfs:label using the @baseClass attribute. This is different than
what appears later in this XSLT for attributes and associations where the rdfs:label is
determined using the @name attribute -->
<rdfs:label><xsl:value-of select="substring-after(@baseClass, '#')"/></rdfs:label>
<xsl:if test="a:SuperType">
<!-- The name of the superclass is determined using the @baseClass attribute
(and not the a:SuperType/@name) -->
<rdfs:subClassOf rdf:resource="{if (starts-with(a:SuperType/@baseClass, $ontologyURI)) then concat('#', substring-after(a:SuperType/@baseClass, '#')) else a:SuperType/@baseClass }"/>
</xsl:if>
</rdf:Description>
</xsl:template>
<xsl:template match="a:SimpleType">
<rdf:Description rdf:about="{if (starts-with(@dataType, $ontologyURI)) then concat('#', substring-after(@dataType, '#')) else @dataType }">
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
</rdf:Description>
</xsl:template>
<!-- ============================================================================================================ -->
<!-- END SECTION: Package, Complex, ComplexType, Root, & CompoundType(s) TYPE DEFINITION templates -->
<!-- ============================================================================================================ -->
<!-- ============================================================================================================ -->
<!-- START SECTION: (Simple, Domain, Instance, Reference attribute & association templates) -->
<!-- ============================================================================================================ -->
<xsl:template match="a:Simple">
<rdf:Description rdf:about="{if (starts-with(@baseProperty, $ontologyURI)) then concat('#', substring-after(@baseProperty, '#')) else @baseProperty }">
<cims:dataType rdf:resource="{if (starts-with(@dataType, $ontologyURI)) then concat('#', substring-after(@dataType, '#')) else @dataType }"/>
<cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:{concat(@minOccurs, '..', replace(@maxOccurs, 'unbounded', 'n'))}"/>
<!-- This conditional is a "safety check" in the event that a a:Stereotype of type #attribute doesn't already
exist. In that case we ensure we add it. This since all a:Domain elements are attributes. -->
<xsl:if test="not(a:Stereotype[contains(., '#attribute')])">
<cims:stereotype rdf:resource="http://langdale.com.au/2005/UML#attribute"/>
</xsl:if>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:domain rdf:resource="{if (starts-with(@basePropertyClass, $ontologyURI)) then concat('#', substring-after(@basePropertyClass, '#')) else @basePropertyClass }"/>
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
</rdf:Description>
</xsl:template>
<xsl:template match="a:Domain">
<rdf:Description rdf:about="{if (starts-with(@baseProperty, $ontologyURI)) then concat('#', substring-after(@baseProperty, '#')) else @baseProperty }">
<cims:dataType rdf:resource="{if (starts-with(@dataType, $ontologyURI)) then concat('#', substring-after(@dataType, '#')) else @dataType }"/>
<cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:{concat(@minOccurs, '..', replace(@maxOccurs, 'unbounded', 'n'))}"/>
<!-- This conditional is a "safety check" in the event that a a:Stereotype of type #attribute doesn't already
exist. In that case we ensure we add it. This since all a:Domain elements are attributes. -->
<xsl:if test="not(a:Stereotype[contains(., '#attribute')])">
<cims:stereotype rdf:resource="http://langdale.com.au/2005/UML#attribute"/>
</xsl:if>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:domain rdf:resource="{if (starts-with(@basePropertyClass, $ontologyURI)) then concat('#', substring-after(@basePropertyClass, '#')) else @basePropertyClass }"/>
<!-- Note: this is intentionally using the @name attribute to source the label for a
domain attribute defined for the class. -->
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
</rdf:Description>
</xsl:template>
<!-- ======================================================================= -->
<!-- Elements of type a:Instance are always associations and not attributes. -->
<!-- ======================================================================= -->
<xsl:template match="a:Instance">
<!-- Create the association -->
<rdf:Description rdf:about="{if (starts-with(@baseProperty, $ontologyURI)) then concat('#', substring-after(@baseProperty, '#')) else @baseProperty }">
<cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:{concat(@minOccurs, '..', replace(@maxOccurs, 'unbounded', 'n'))}"/>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:domain rdf:resource="{if (starts-with(@inverseBasePropertyClass, $ontologyURI)) then concat('#', substring-after(@inverseBasePropertyClass, '#')) else @inverseBasePropertyClass }"/>
<!-- Note: this is intentionally using the @name attribute to source the label for an
association or attribute within the class. -->
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
<rdfs:range rdf:resource="#{@type}"/>
</rdf:Description>
</xsl:template>
<xsl:template match="a:Reference">
<!-- Create the association -->
<rdf:Description rdf:about="{if (starts-with(@baseProperty, $ontologyURI)) then concat('#', substring-after(@baseProperty, '#')) else @baseProperty }">
<cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:{concat(@minOccurs, '..', replace(@maxOccurs, 'unbounded', 'n'))}"/>
<!-- When an @inverseBaseProperty is missing it is a clear indicator that this is not actually an association but
rather is an attribute that the end user has not pulled in the type for in CIMTool while constructing
the profile. When that happens it appears as an a:Reference element and therefore the below conditional is
required.
-->
<xsl:if test="not(@inverseBaseProperty) and not(a:Stereotype[contains(., '#attribute')])">
<cims:stereotype rdf:resource="http://langdale.com.au/2005/UML#attribute"/>
</xsl:if>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:domain rdf:resource="{if (starts-with(@inverseBasePropertyClass, $ontologyURI)) then concat('#', substring-after(@inverseBasePropertyClass, '#')) else @inverseBasePropertyClass }"/>
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
<rdfs:range rdf:resource="#{@type}"/>
</rdf:Description>
</xsl:template>
<xsl:template match="a:Enumerated">
<rdf:Description rdf:about="{if (starts-with(@baseProperty, $ontologyURI)) then concat('#', substring-after(@baseProperty, '#')) else @baseProperty }">
<cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:{concat(@minOccurs, '..', replace(@maxOccurs, 'unbounded', 'n'))}"/>
<xsl:if test="not(a:Stereotype[contains(., '#attribute')])">
<cims:stereotype rdf:resource="http://langdale.com.au/2005/UML#attribute"/>
</xsl:if>
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:domain rdf:resource="{if (starts-with(@basePropertyClass, $ontologyURI)) then concat('#', substring-after(@basePropertyClass, '#')) else @basePropertyClass }"/>
<!-- Note: this is intentionally using the @name attribute to source the label for an
enumerated attribute within a class. -->
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
<rdfs:range rdf:resource="#{@type}"/>
</rdf:Description>
</xsl:template>
<xsl:template match="a:EnumeratedValue">
<rdf:Description rdf:about="{if (starts-with(@baseResource, $ontologyURI)) then concat('#', substring-after(@baseResource, '#')) else @baseResource }">
<xsl:for-each select="a:Stereotype">
<xsl:sort select="." order="ascending" />
<xsl:variable name="stereotype" select="."/>
<cims:stereotype rdf:resource="{$stereotype}"/>
</xsl:for-each>
<rdf:type rdf:resource="{if (starts-with(@baseResource, $ontologyURI)) then concat('#', substring-before(substring-after(@baseResource, '#'), '.')) else @baseResource }"/>
<xsl:if test="a:Comment|a:Note"><rdfs:comment><xsl:apply-templates select="." mode="comments"/></rdfs:comment></xsl:if>
<rdfs:label><xsl:value-of select="@name"/></rdfs:label>
</rdf:Description>
</xsl:template>
<!-- ============================================================================================================ -->
<!-- END SECTION: (ComplexType, Root, and EnumeratedType attribute & association templates) -->
<!-- ============================================================================================================ -->
<!--
<xsl:template match="a:Complex">
<xs:element name="{@name}" minOccurs="{@minOccurs}" maxOccurs="{@maxOccurs}" sawsdl:modelReference="{@baseProperty}">
<xsl:call-template name="annotate"/>
<xs:complexType sawsdl:modelReference="{@baseClass}">
<xsl:call-template name="type_body"/>
</xs:complexType>
</xs:element>
</xsl:template>
<xsl:template match="a:Choice[a:Stereotype='http://langdale.com.au/2005/UML#preserve']">
<xs:element name="{@name}" minOccurs="{@minOccurs}" maxOccurs="{@maxOccurs}" sawsdl:modelReference="{@baseProperty}">
<xsl:call-template name="annotate"/>
<xs:complexType>
<xs:choice>
<xsl:apply-templates/>
</xs:choice>
</xs:complexType>
</xs:element>
</xsl:template>
<xsl:template match="a:SimpleEnumerated">
<xs:element name="{@name}" minOccurs="{@minOccurs}" maxOccurs="{@maxOccurs}" sawsdl:modelReference="{@baseProperty}">
<xsl:call-template name="annotate"/>
<xs:simpleType sawsdl:modelReference="{@baseClass}">
<xs:restriction base="xs:string">
<xsl:apply-templates/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xsl:template>
<xsl:template match="a:CompoundType" mode="declare">
<xs:complexType name="{@name}" sawsdl:modelReference="{@baseClass}">
<xsl:call-template name="annotate"/>
<xsl:call-template name="type_body"/>
</xs:complexType>
</xsl:template>
-->
<xsl:template match="." mode="comments">
<xsl:for-each select="a:Comment|a:Note">
<xsl:value-of select="."/><xsl:if test="position()!=last()"><xsl:value-of select="$newline"/></xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()">
<!-- dont pass text through -->
</xsl:template>
</xsl:stylesheet>