File: wsdl2rdf.xsl

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (272 lines) | stat: -rw-r--r-- 10,215 bytes parent folder | download | duplicates (2)
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
<?xml version="1.0" ?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2012 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<!DOCTYPE xsl:stylesheet [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY wsdlr "http://www.w3.org/ns/wsdl-rdf#">
<!ENTITY wsdl "http://www.w3.org/2006/01/wsdl">
<!ENTITY wsoap "http://www.w3.org/ns/wsdl/soap">
]>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="&rdf;"
    xmlns:rdfs="&rdfs;"
    xmlns:wsdlr="&wsdlr;"
    xmlns:wsoap="&wsoap;"
    xmlns:wsdl="&wsdl;"
    >
    <xsl:output method="xml" indent="yes" media-type="application/rdf+xml" />
    <xsl:variable name="ns" select="/wsdl:description/@targetNamespace"/>
    <xsl:variable name="uc">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
    <xsl:variable name="lc">abcdefghijklmnopqrstuvwxyz</xsl:variable>

    <xsl:template match="wsdl:description">
	<rdf:RDF>
	    <xsl:variable name="iri"><xsl:call-template name="iri"/></xsl:variable>
	    <rdf:Description rdf:about="{$iri}">
		<rdf:type rdf:resource="&wsdlr;Description"/>
		<xsl:apply-templates mode="inner"/>
	    </rdf:Description>
	    <xsl:for-each select="wsdl:interface/wsdl:operation/wsdl:*/@element">
		<xsl:variable name="qn" select="expand-qname (0, .)"/>
		<rdf:Description rdf:about="{$qn}">
		    <rdf:type rdf:resource="&wsdlr;QName"/>
		    <wsdlr:localName><xsl:value-of select="substring-after (., ':')"/></wsdlr:localName>
		    <wsdlr:namespace rdf:resource="{substring-before($qn, concat (':', substring-after (., ':')))}"/>
		</rdf:Description>
	    </xsl:for-each>
	    <xsl:apply-templates/>
	</rdf:RDF>
    </xsl:template>

    <xsl:template match="wsdl:interface">
	<xsl:variable name="iri"><xsl:call-template name="iri"/></xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;Interface"/>
	    <rdfs:label><xsl:value-of select="@name"/></rdfs:label>
	    <xsl:apply-templates mode="intf-inner"/>
	</rdf:Description>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="wsdl:operation" mode="intf-inner">
	<wsdlr:interfaceOperation>
	    <xsl:attribute name="resource" namespace="&rdf;">
		<xsl:call-template name="op-iri"/>
	    </xsl:attribute>
	</wsdlr:interfaceOperation>
    </xsl:template>

    <xsl:template match="wsdl:operation[@name]">
	<xsl:variable name="iri"><xsl:call-template name="op-iri"/></xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;InterfaceOperation"/>
	    <rdfs:label><xsl:value-of select="@name"/></rdfs:label>
	    <wsdlr:messageExchangePattern rdf:resource="{@pattern}"/>
	    <wsdlr:operationStyle rdf:resource="{@style}"/>
	    <xsl:apply-templates mode="op-inner"/>
	</rdf:Description>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="wsdl:input|wsdl:output" mode="op-inner">
	<xsl:variable name="iri"><xsl:call-template name="msg-iri"/></xsl:variable>
	<wsdlr:interfaceMessageReference rdf:resource="{$iri}"/>
    </xsl:template>

    <xsl:template match="wsdl:input|wsdl:output">
	<xsl:variable name="iri"><xsl:call-template name="msg-iri"/></xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;InterfaceMessageReference"/>
	    <xsl:choose>
		<xsl:when test="local-name() = 'input'">
		    <rdf:type rdf:resource="&wsdlr;InputMessage"/>
		</xsl:when>
		<xsl:when test="local-name() = 'output'">
		    <rdf:type rdf:resource="&wsdlr;OutputMessage"/>
		</xsl:when>
	    </xsl:choose>
	    <wsdlr:messageLabel rdf:resource="{../@pattern}#{@messageLabel}"/>
	    <wsdlr:messageContentModel rdf:resource="&wsdlr;ElementContent"/>
	    <wsdlr:elementDeclaration rdf:resource="{expand-qname (0, @element)}"/>
	</rdf:Description>
    </xsl:template>


    <xsl:template match="wsdl:fault" mode="intf-inner">
	<wsdlr:interfaceFault>
	    <xsl:attribute name="resource" namespace="&rdf;">
		<xsl:call-template name="op-iri"/>
	    </xsl:attribute>
	</wsdlr:interfaceFault>
    </xsl:template>

    <xsl:template match="wsdl:interface|wsdl:binding|wsdl:service" mode="inner">
	<xsl:element name="{local-name(.)}" namespace="&wsdlr;">
	    <xsl:attribute name="resource" namespace="&rdf;">
		<xsl:call-template name="iri"/>
	    </xsl:attribute>
	</xsl:element>
    </xsl:template>

    <xsl:template match="wsdl:binding">
	<xsl:variable name="iri"><xsl:call-template name="iri"/></xsl:variable>
	<xsl:variable name="if-name" select="substring-after (@interface, ':')"/>
	<xsl:variable name="if-iri">
	    <xsl:apply-templates select="//wsdl:interface[@name = $if-name]" mode="get-iri"/>
	</xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;Binding"/>
	    <rdf:type rdf:resource="{@type}"/>
	    <rdfs:label><xsl:value-of select="@name"/></rdfs:label>
	    <wsdlr:binds rdf:resource="{$if-iri}"/>
	    <wsoap:protocol rdf:resource="{@wsoap:protocol}"/>
	    <wsoap:version><xsl:value-of select="@wsoap:version"/></wsoap:version>
	    <xsl:apply-templates mode="bind-inner" />
	</rdf:Description>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="wsdl:operation" mode="bind-inner">
	<xsl:variable name="iri"><xsl:call-template name="op-iri"/></xsl:variable>
	<wsdlr:bindingOperation rdf:resource="{$iri}"/>
    </xsl:template>

    <xsl:template match="wsdl:operation[@ref]">
	<xsl:variable name="op-name" select="substring-after (@ref, ':')"/>
	<xsl:variable name="op-iri">
	    <xsl:apply-templates select="//wsdl:operation[@name = $op-name]" mode="get-iri"/>
	</xsl:variable>
	<xsl:variable name="iri"><xsl:call-template name="op-iri"/></xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;BindingOperation"/>
	    <wsdlr:binds rdf:resource="{$op-iri}"/>
	</rdf:Description>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="wsdl:interface" mode="get-iri">
	<xsl:call-template name="iri"/>
    </xsl:template>

    <xsl:template match="wsdl:operation" mode="get-iri">
	<xsl:call-template name="op-iri"/>
    </xsl:template>

    <xsl:template match="wsdl:binding" mode="get-iri">
	<xsl:call-template name="iri"/>
    </xsl:template>

    <xsl:template match="wsdl:service">
	<xsl:variable name="iri"><xsl:call-template name="iri"/></xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;Service"/>
	    <rdfs:label><xsl:value-of select="@name"/></rdfs:label>
	    <xsl:apply-templates mode="svc-inner" />
	    <xsl:apply-templates select="//wsdl:interface" mode="svc-inner" />
	</rdf:Description>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="wsdl:endpoint" mode="svc-inner">
	 <xsl:variable name="iri"><xsl:call-template name="ep-iri"/></xsl:variable>
	 <wsdlr:endpoint rdf:resource="{$iri}"/>
     </xsl:template>

     <xsl:template match="wsdl:interface" mode="svc-inner">
	 <xsl:variable name="iri"><xsl:call-template name="iri"/></xsl:variable>
	 <wsdlr:implements rdf:resource="{$iri}"/>
     </xsl:template>

    <xsl:template match="wsdl:endpoint">
	<xsl:variable name="iri"><xsl:call-template name="ep-iri"/></xsl:variable>
	<xsl:variable name="bnd-name" select="substring-after (@binding, ':')"/>
	<xsl:variable name="bnd-iri">
	    <xsl:apply-templates select="//wsdl:binding[@name = $bnd-name]" mode="get-iri"/>
	</xsl:variable>
	<rdf:Description rdf:about="{$iri}">
	    <rdf:type rdf:resource="&wsdlr;Endpoint"/>
	    <rdfs:label><xsl:value-of select="@name"/></rdfs:label>
	    <wsdlr:address rdf:resource="{@address}"/>
	    <wsdlr:usesBinding rdf:resource="{$bnd-iri}"/>
	</rdf:Description>
    </xsl:template>

    <xsl:template name="msg-iri">
	<xsl:value-of select="$ns"/>
	<xsl:text>#wsdl.interfaceMessageReference</xsl:text>
	<xsl:text>(</xsl:text>
	<xsl:value-of select="../../@name"/><xsl:text>/</xsl:text>
	<xsl:value-of select="../@name"/><xsl:text>/</xsl:text>
	<xsl:value-of select="@messageLabel"/>
	<xsl:text>)</xsl:text>
    </xsl:template>

    <xsl:template name="op-iri">
	<xsl:value-of select="$ns"/>
	<xsl:text>#wsdl.</xsl:text>
	<xsl:value-of select="local-name(parent::*)"/>
	<xsl:value-of select="translate (substring (local-name(.), 1, 1), $lc, $uc)"/>
	<xsl:value-of select="substring (local-name(.), 2)"/>
	<xsl:text>(</xsl:text>
	<xsl:value-of select="../@name"/><xsl:text>/</xsl:text>
	<xsl:choose>
	    <xsl:when test="@name">
		<xsl:value-of select="@name"/>
	    </xsl:when>
	    <xsl:when test="@ref">
		<xsl:value-of select="substring-after (@ref, ':')"/>
	    </xsl:when>
	</xsl:choose>
	<xsl:text>)</xsl:text>
    </xsl:template>

    <xsl:template name="ep-iri">
	<xsl:value-of select="$ns"/>
	<xsl:text>#wsdl.</xsl:text>
	<xsl:value-of select="local-name(.)"/>
	<xsl:text>(</xsl:text>
	<xsl:value-of select="../@name"/><xsl:text>/</xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>)</xsl:text>
    </xsl:template>

    <xsl:template name="iri">
	<xsl:value-of select="$ns"/>
	<xsl:text>#wsdl.</xsl:text>
	<xsl:value-of select="local-name(.)"/>
	<xsl:text>(</xsl:text>
	<xsl:value-of select="@name"/>
	<xsl:text>)</xsl:text>
    </xsl:template>

    <xsl:template match="text()" mode="inner"/>
    <xsl:template match="text()" mode="op-inner"/>
    <xsl:template match="text()" mode="intf-inner"/>
    <xsl:template match="text()" mode="bind-inner"/>
    <xsl:template match="text()" mode="svc-inner"/>
    <xsl:template match="text()"/>

</xsl:stylesheet>