File: soap_sch.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 (446 lines) | stat: -rw-r--r-- 17,290 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?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
 -
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:vi="http://www.openlinksw.com/wsdl/"
    xmlns:vs="http://www.openlinksw.com/virtuoso/soap"
    >
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="UTF-8"/>
  <xsl:param name="type_name" select="''"/>
  <xsl:param name="udt_struct" select="0"/>
  <xsl:param name="target_Namespace" select="''"/>
  <xsl:param name="any_type" select="0"/>
  <xsl:template match="/">
    <xsl:apply-templates select="*"/>
  </xsl:template>
  <xsl:template match="schema">
    <xsl:apply-templates select="*"/>
  </xsl:template>
  <xsl:template match="complexType">
    <complexType>
      <xsl:choose>
        <xsl:when test="@name != ''">
          <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="name"><xsl:value-of select="$type_name"/></xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <!-- keep the targetNamespace -->
      <xsl:attribute name="targetNamespace"><xsl:value-of select="@targetNamespace"/></xsl:attribute>
      <xsl:choose>
        <xsl:when test="not boolean ($udt_struct) and (count (child::*/child::*/sequence/element) &lt;= 1 or starts-with(@name,'ArrayOf') or count (child::*/element) &lt;= 1)">
          <xsl:apply-templates select="complexContent|simpleContent">
            <xsl:with-param name="min">0</xsl:with-param>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="complexContent|simpleContent">
            <xsl:with-param name="min">1</xsl:with-param>
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="group">
        <xsl:with-param name="min">1</xsl:with-param>
      </xsl:apply-templates>
      <xsl:choose>
        <xsl:when test="count (sequence/element) &lt;= 1 and not boolean ($udt_struct)">
          <xsl:apply-templates select="sequence">
            <xsl:with-param name="min">0</xsl:with-param>
            <xsl:with-param name="cmpc">1</xsl:with-param>
            <xsl:with-param name="attr">
              <xsl:copy-of select="attribute"/>
            </xsl:with-param>
            <xsl:with-param name="ext">
              <xsl:value-of select="count(attribute)"/>
            </xsl:with-param>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="sequence">
            <xsl:with-param name="min">1</xsl:with-param>
            <xsl:with-param name="cmpc">1</xsl:with-param>
            <xsl:with-param name="attr">
              <xsl:copy-of select="attribute|anyAttribute"/>
            </xsl:with-param>
            <xsl:with-param name="ext">
              <xsl:value-of select="count(attribute|anyAttribute)"/>
            </xsl:with-param>
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="choice">
        <complexContent>
	  <restriction base="enc:Struct">
	    <xsl:attribute name="choice">1</xsl:attribute>
            <xsl:apply-templates select="choice">
              <xsl:with-param name="min">1</xsl:with-param>
            </xsl:apply-templates>
	  </restriction>
	</complexContent>
      </xsl:if>
      <xsl:apply-templates select="all">
        <xsl:with-param name="min">1</xsl:with-param>
      </xsl:apply-templates>
      <xsl:if test="attribute and not local-name(*) != 'attribute'">
	  <simpleContent>
	      <extension base="string">
		  <xsl:apply-templates select="attribute" />
	      </extension>
	  </simpleContent>
      </xsl:if>
    </complexType>
  </xsl:template>
  <xsl:template match="complexContent">
    <complexContent>
      <xsl:apply-templates select="restriction">
        <xsl:with-param name="min">
          <xsl:value-of select="$min"/>
        </xsl:with-param>
      </xsl:apply-templates>
      <xsl:apply-templates select="extension">
        <xsl:with-param name="min">
          <xsl:value-of select="$min"/>
        </xsl:with-param>
      </xsl:apply-templates>
      <xsl:if test="count(sequence)>0">
        <sequence error="The 'sequence' element is not supported as child of complexContent"/>
      </xsl:if>
    </complexContent>
  </xsl:template>
  <xsl:template match="any">
    <element type="__XML__" name="" minOccurs="0" maxOccurs="unbounded" />
    <!--any error="The 'any' element is not supported"/-->
  </xsl:template>
  <xsl:template match="simpleContent">
    <xsl:copy-of select="."/>
    <!--complexContent>
  <xsl:apply-templates select="restriction">
     <xsl:with-param name="min"><xsl:value-of select="$min" /></xsl:with-param>
  </xsl:apply-templates>
  <xsl:apply-templates select="extension">
     <xsl:with-param name="min"><xsl:value-of select="$min" /></xsl:with-param>
  </xsl:apply-templates>
</complexContent-->
  </xsl:template>
  <xsl:template match="extension|restriction" mode="simple">
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:attribute name="enumeration"><xsl:value-of select="boolean(enumeration)" /></xsl:attribute>
    <xsl:copy-of select="*" />
  </xsl:copy>
  </xsl:template>
  <xsl:template match="*" mode="simple">
  </xsl:template>
  <xsl:template match="simpleType">
    <complexType>
      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
      <simpleContent>
        <xsl:apply-templates select="extension|restriction" mode="simple" />
      </simpleContent>
    </complexType>
  </xsl:template>
  <xsl:template match="group">
    <group error="The 'group' element is not supported"/>
  </xsl:template>
  <xsl:template match="choice">
    <xsl:choose>
      <xsl:when test="parent::sequence">
        <xsl:apply-templates select="element|any" />
      </xsl:when>
      <xsl:otherwise>
        <sequence>
	  <xsl:apply-templates select="element|any" />
        <!--choice error="The 'choice' element is not supported"/-->
	</sequence>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="restriction">
    <xsl:choose>
      <xsl:when test="count(sequence/element|attribute)>0">
        <restriction base="enc:Struct">
          <xsl:if test="$min!=1">
            <xsl:attribute name="base"><xsl:value-of select="@base"/></xsl:attribute>
          </xsl:if>
          <xsl:choose>
            <xsl:when test="sequence/element">
              <xsl:apply-templates select="sequence">
                <xsl:with-param name="min">
                  <xsl:value-of select="$min"/>
                </xsl:with-param>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="attribute/@arrayType">
              <sequence>
                <element name="item" type="" minOccurs="0" maxOccurs="unbounded">
                  <xsl:attribute name="type"><xsl:value-of select="normalize-space(translate(attribute/@arrayType,'[]','  '))"/></xsl:attribute>
                </element>
              </sequence>
            </xsl:when>
          </xsl:choose>
          <xsl:if test="attribute/@arrayType">
	      <attribute ref="enc:arrayType" wsdl:arrayType="">
		  <xsl:attribute name="wsdl:arrayType"><xsl:value-of select="attribute/@arrayType"/></xsl:attribute>
	      </attribute>
          </xsl:if>
          <xsl:if test="not(attribute/@arrayType) and $min=0 and @base">
            <attribute ref="enc:arrayType">
              <xsl:attribute name="wsdl:arrayType"><xsl:value-of select="sequence/element[1]/@type"/><xsl:text>[]</xsl:text></xsl:attribute>
            </attribute>
          </xsl:if>
        </restriction>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="@base">
          <restriction base="enc:Struct">
            <sequence>
              <element name="item" type="">
                <xsl:attribute name="type"><xsl:value-of select="@base"/></xsl:attribute>
              </element>
            </sequence>
          </restriction>
        </xsl:if>
        <xsl:if test="not (@base)">
          <sequence>
            <element error="No sequence/element defined or base attribute supplied"/>
          </sequence>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="extension">
    <xsl:choose>
	<xsl:when test="not boolean ($udt_struct)">
	  <xsl:variable name="ext" select="vs:getExtension (@base)"/>
	  <xsl:choose>
	      <xsl:when test="$ext//xs:element or xs:sequence/xs:element">
	  <restriction base="enc:Struct">
	      <sequence>
		  <xsl:apply-templates select="$ext//xs:element">
		      <xsl:with-param name="namespace" select="concat($ext/*/@targetNamespace,':',$ext/*/@name)"/>
		  </xsl:apply-templates>
		  <xsl:apply-templates select="xs:sequence/*"/>
	      </sequence>
	  </restriction>
      </xsl:when>
	      <xsl:when test="$ext//xs:simpleContent">
		  <restriction base="enc:Struct">
		      <xsl:apply-templates select="$ext//xs:simpleContent/xs:attribute"/>
		      <xsl:apply-templates select="xs:attribute"/>
		  </restriction>
	      </xsl:when>
	      <xsl:otherwise>
		  <xsl:message terminate="no"><xsl:copy-of select="vs:getExtension (@base)"/></xsl:message>
		  <extension>
		      <xsl:attribute name="error">The 'extension' element [<xsl:value-of select="@base"/>] can not be found when expanding <xsl:value-of select="ancestor::*[@name]/@name"/></xsl:attribute>
		  </extension>
	      </xsl:otherwise>
	  </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="@*"/>
          <xsl:apply-templates select="node()">
            <xsl:with-param name="min">1</xsl:with-param>
          </xsl:apply-templates>
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="attribute">
      <xsl:choose>
	  <xsl:when test="@arrayType">
	      <attribute ref="enc:arrayType" wsdl:arrayType="">
		  <xsl:attribute name="wsdl:arrayType"><xsl:value-of select="@arrayType"/></xsl:attribute>
	      </attribute>
	  </xsl:when>
	  <xsl:when test="@ref">
	      <xsl:copy>
		  <xsl:attribute name="name"><xsl:value-of select="vi:split-name(@ref, 1)"/></xsl:attribute>
		  <xsl:attribute name="type">string</xsl:attribute>
	      </xsl:copy>
	  </xsl:when>
	  <xsl:when test="@type and @name">
	      <xsl:copy-of select=".|@*"/>
	  </xsl:when>
      </xsl:choose>
  </xsl:template>
  <xsl:template match="sequence">
    <xsl:param name="min" select="0"/>
    <xsl:param name="cmpc" select="''"/>
    <xsl:param name="ext" select="0"/>
    <xsl:param name="attr" select="''"/>
    <xsl:if test="$cmpc!=''">
      <xsl:if test="$ext='0'">
        <complexContent>
          <restriction base="enc:Struct">
            <xsl:attribute name="base"><xsl:choose><xsl:when test="count(element) > 1 or boolean($udt_struct) or choice">http://schemas.xmlsoap.org/soap/encoding/:Struct</xsl:when><xsl:otherwise>http://schemas.xmlsoap.org/soap/encoding/:Array</xsl:otherwise></xsl:choose></xsl:attribute>
	    <xsl:if test="choice">
	      <xsl:attribute name="choice">1</xsl:attribute>
	    </xsl:if>
            <sequence>
              <xsl:apply-templates select="element|any|choice">
                <xsl:with-param name="min">
                  <xsl:value-of select="$min"/>
                </xsl:with-param>
              </xsl:apply-templates>
            </sequence>
          </restriction>
        </complexContent>
      </xsl:if>
      <xsl:if test="$ext!='0'">
        <complexContent>
          <extension base="enc:Struct">
            <sequence>
              <xsl:apply-templates select="element|any|choice">
                <xsl:with-param name="min">
                  <xsl:value-of select="$min"/>
                </xsl:with-param>
              </xsl:apply-templates>
            </sequence>
            <xsl:copy-of select="$attr"/>
          </extension>
        </complexContent>
      </xsl:if>
    </xsl:if>
    <xsl:if test="$cmpc=''">
      <sequence>
        <xsl:apply-templates select="element|any|choice">
          <xsl:with-param name="min">
            <xsl:value-of select="$min"/>
          </xsl:with-param>
        </xsl:apply-templates>
      </sequence>
    </xsl:if>
  </xsl:template>
  <xsl:template match="element">
    <xsl:param name="min" select="0"/>
    <xsl:param name="namespace" select="''"/>
    <xsl:choose>
      <xsl:when test="complexType">
        <element>
          <xsl:copy-of select="@*"/>
	  <xsl:choose>
	  <xsl:when test="$any_type and complexType/sequence/any" >
	  <xsl:attribute name="type">__ANY__</xsl:attribute>
	  </xsl:when>
          <xsl:when test="complexType">
            <xsl:choose>
              <xsl:when test="@targetNamespace != ''">
                <xsl:attribute name="type"><xsl:value-of select="@targetNamespace"/>:elementType__<xsl:value-of select="@name"/></xsl:attribute>
              </xsl:when>
              <xsl:otherwise>
                <xsl:attribute name="targetNamespace"><xsl:value-of select="$target_Namespace"/></xsl:attribute>
                <xsl:attribute name="type"><xsl:value-of select="$target_Namespace"/>:elementType__<xsl:value-of select="@name"/></xsl:attribute>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
	  </xsl:choose>
        </element>
      </xsl:when>
      <xsl:when test="simpleType/restriction[@base]">
        <element>
	    <xsl:copy-of select="@*"/>
	    <xsl:attribute name="type"><xsl:value-of select="simpleType/restriction/@base"/></xsl:attribute>
        </element>
      </xsl:when>
      <xsl:otherwise>
        <element>
	  <xsl:choose>
	    <xsl:when test="boolean (@ref)">
	      <xsl:attribute name="ref"><xsl:value-of select="@ref"/></xsl:attribute>
	    </xsl:when>
	    <xsl:otherwise>
              <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
	      <xsl:choose>
	        <xsl:when test="boolean(@type)">
                  <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
		</xsl:when>
		<xsl:otherwise>
                  <xsl:attribute name="type">__ANY__</xsl:attribute>
		</xsl:otherwise>
	      </xsl:choose>
	    </xsl:otherwise>
	  </xsl:choose>
          <xsl:if test="@form">
            <xsl:attribute name="form"><xsl:value-of select="@form"/></xsl:attribute>
	  </xsl:if>
	  <xsl:attribute name="nillable"><xsl:value-of select="boolean(@nillable = 1 or @nillable = 'true')"/></xsl:attribute>
	  <xsl:copy-of select="@minOccurs"/>
	  <xsl:copy-of select="@maxOccurs"/>
	  <xsl:if test="not @minOccurs">
	      <xsl:choose>
		  <xsl:when test="parent::*[@minOccurs]">
		      <xsl:copy-of select="parent::*/@minOccurs"/>
		  </xsl:when>
		  <xsl:when test="ancestor::*[@base='http://schemas.xmlsoap.org/soap/encoding/:Array']">
		      <xsl:attribute name="minOccurs">0</xsl:attribute>
		  </xsl:when>
		  <xsl:otherwise>
		      <xsl:attribute name="minOccurs">1</xsl:attribute>
		  </xsl:otherwise>
	      </xsl:choose>
	  </xsl:if>
	  <xsl:if test="not @maxOccurs">
	      <xsl:choose>
		  <xsl:when test="parent::*[@maxOccurs]">
		      <xsl:copy-of select="parent::*/@maxOccurs"/>
		  </xsl:when>
		  <xsl:when test="ancestor::*[@base='http://schemas.xmlsoap.org/soap/encoding/:Array']">
		      <xsl:attribute name="maxOccurs">unbounded</xsl:attribute>
		  </xsl:when>
		  <xsl:otherwise>
		      <xsl:attribute name="maxOccurs">1</xsl:attribute>
		  </xsl:otherwise>
	      </xsl:choose>
	  </xsl:if>
          <xsl:if test="./child::*">
	      <xsl:attribute name="error">The definitions cannot be implied</xsl:attribute>
	  </xsl:if>
	  <xsl:if test="$namespace != ''">
	      <xsl:attribute name="namespace"><xsl:value-of select="$namespace"/></xsl:attribute>
	  </xsl:if>
        </element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="all">
    <complexContent>
      <restriction base="enc:Struct">
        <sequence>
          <xsl:apply-templates select="element|any">
            <xsl:with-param name="min">
              <xsl:value-of select="$min"/>
            </xsl:with-param>
          </xsl:apply-templates>
        </sequence>
      </restriction>
    </complexContent>
  </xsl:template>
</xsl:stylesheet>