Project

Profile

Help

How to connect?
Download (18.1 KB) Statistics
| Branch: | Tag: | Revision:

he / tools / dotnet / convert-to-jel-package.xsl @ 5d25f10d

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
    xmlns:f="urn:local"
5
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
6
    exclude-result-prefixes="xs f map"
7
    version="3.0">
8
    
9
    <!-- Convert the .NET api documentation from the merged.xml format into the format generated by the jeldoclet for Java APIs.
10
    Note that we're assuming there is only one package. -->
11
    
12
    <xsl:output method="xml" indent="yes"/>
13
    
14
    <xsl:template match="package">
15
        <package id="{@name}">
16
            <xsl:apply-templates>
17
                <xsl:sort select="lower-case(@name)"/>
18
            </xsl:apply-templates>
19
        </package>
20
        <xsl:result-document href="../packages.xml">
21
            <article id="dotnetdoc-packages">
22
                <section id="Saxon.Api">
23
                    <div>
24
                        <p>This namespace contains Saxon's application programming interfaces for using XSLT, XQuery,
25
                            XPath and XSD on .NET.</p>
26
                        <p>The top-level object is the <a class="javalink" href="Saxon.Api.Processor">Processor</a>;
27
                            this allows creation of factory classes for using each of the different processing
28
                            languages.</p>
29
                    </div>
30
                </section>
31
            </article>
32
        </xsl:result-document>
33
        <xsl:result-document href="../types.xml">
34
            <packages title="Search Data">
35
                <j id="Saxon.Api" in="p">
36
                    <xsl:for-each select="*">
37
                        <!--<xsl:sort select="@name != 'Processor'"/>
38
                        <xsl:sort select="index-of(('class', 'interface', 'enum'), name())"/>-->
39
                        <xsl:sort select="lower-case(@name)"/>
40
                        <j id="{@name}" in="c" qy="{lower-case(@name)}">
41
                            <xsl:for-each select="property">
42
                                <j id="{@name}" in="y" qy="{lower-case(@name)}"/>
43
                            </xsl:for-each>
44
                            <xsl:for-each select="field">
45
                                <j id="{@name}" in="f" qy="{lower-case(@name)}"/>
46
                            </xsl:for-each>
47
                            <xsl:for-each select="method">
48
                                <j id="{@name}" in="m" qy="{lower-case(@name)}"/>
49
                            </xsl:for-each>
50
                        </j>
51
                    </xsl:for-each>
52
                </j>
53
            </packages>
54
        </xsl:result-document>
55
        <xsl:result-document href="../tree.xml">
56
            <packages id="dotnetdoc" title=".NET API">
57
                <j id="Saxon.Api" in="p">
58
                    <xsl:for-each select="*">
59
                        <!--<xsl:sort select="@name != 'Processor'"/>
60
                        <xsl:sort select="index-of(('class', 'interface', 'enum'), name())"/>-->
61
                        <xsl:sort select="lower-case(@name)"/>
62
                        <j id="{@name}" in="c">
63
                            <xsl:for-each select="class">
64
                                <j id="{substring-after(@name, '.')}" in="c"/>
65
                            </xsl:for-each>
66
                        </j>
67
                    </xsl:for-each>
68
                </j>
69
            </packages>
70
        </xsl:result-document>
71
    </xsl:template>
72
    
73
    <xsl:template match="class">
74
        <xsl:variable name="superclasses" select="tokenize(@base, ', ', 'q')"/>
75
        <class id="{@name}" fulltype="{concat('Saxon.Api.',@name)}"
76
            visibility="{if (@public='true') then 'public' else 'protected'}"
77
            superclass="{string-join($superclasses!f:shortName(.), ', ')}"
78
            superclassfulltype="{string-join($superclasses!f:fullName(.), ', ')}">
79
            <!-- f:fullName still needed here because generic types have not already been resolved -->
80
            
81
            <xsl:copy-of select="@abstract[.='true']"/>
82
            <!--<xsl:message>processing <xsl:value-of select="@name"/></xsl:message>-->
83
            
84
            <!-- possible children: extends, implements, comments, method, constructor, property, field, class, paramtypes -->
85
            <xsl:apply-templates select="* except (property|method|constructor|field)"/>
86
            <xsl:apply-templates select="property">
87
                <xsl:sort select="lower-case(@name)"/>
88
            </xsl:apply-templates>
89
            <xsl:if test="constructor | method">
90
                <methods>
91
                    <xsl:apply-templates select="constructor"/>
92
                    <xsl:apply-templates select="method">
93
                        <xsl:sort select="lower-case(@name)"/>
94
                    </xsl:apply-templates>
95
                </methods>
96
            </xsl:if>
97
            <xsl:if test="field">
98
                <fields>
99
                    <xsl:apply-templates select="field">
100
                        <xsl:sort select="lower-case(@name)"/>
101
                    </xsl:apply-templates>
102
                </fields>
103
            </xsl:if>
104
            <xsl:call-template name="subclasses"/>
105
        </class>
106
    </xsl:template>
107
    
108
    <xsl:template match="interface">
109
        <interface id="{@name}" fulltype="{../@name}.{@name}"
110
            visibility="{if (@public='true') then 'public' else 'protected'}"
111
            superclass="{f:shortName(@base)}"
112
            superclassfulltype="{f:fullName(@base)}">
113
            <xsl:apply-templates select="* except (property|method)"/>
114
            <xsl:apply-templates select="property">
115
                <xsl:sort select="lower-case(@name)"/>
116
            </xsl:apply-templates>
117
            <methods>
118
                <xsl:apply-templates select="method">
119
                    <xsl:sort select="lower-case(@name)"/>
120
                </xsl:apply-templates>
121
            </methods>
122
            <xsl:call-template name="classes-implemented-by-interface"/>
123
        </interface>
124
    </xsl:template>
125
    
126
    <xsl:template name="classes-implemented-by-interface">
127
        <xsl:if test="exists(key('class-by-base',./@name))">
128
            <implemented-by>
129
                <xsl:for-each select="key('class-by-base',./@name)">
130
                    <xsl:sort select="lower-case(@name)"/>
131
                    <class fulltype="{f:fullName(./@name)}" type="{./@name}"/>
132
                </xsl:for-each>
133
            </implemented-by>
134
        </xsl:if>
135
    </xsl:template>
136
    
137
    <!-- Used for classes which implement an interface, and subclasses of a class -->
138
    <xsl:key name="class-by-base" match="class | interface | enum" 
139
        use="tokenize(@base, ', ', 'q')"/>
140
    
141
    <xsl:template name="subclasses">
142
        <xsl:if test="exists(key('class-by-base',./@name))">
143
            <subclasses>
144
                <xsl:for-each select="key('class-by-base',./@name)">
145
                    <xsl:sort select="lower-case(@name)"/>
146
                    <class fulltype="{f:fullName(./@name)}" type="{./@name}"/>
147
                </xsl:for-each>
148
            </subclasses>
149
        </xsl:if>
150
    </xsl:template>
151
    
152
    <xsl:template match="enum">
153
        <enum id="{@name}" fulltype="{../@name}.{@name}"
154
            visibility="{if (@public='true') then 'public' else 'protected'}"
155
            superclass="{f:shortName(@base)}"
156
            superclassfulltype="{f:fullName(@base)}">
157
            <xsl:apply-templates select="comments"/>
158
            <fields>
159
                <xsl:apply-templates select="field">
160
                    <xsl:sort select="lower-case(@name)"/>
161
                </xsl:apply-templates>
162
            </fields>
163
        </enum>
164
    </xsl:template>
165
    
166
    <xsl:template match="constructor">
167
        <constructor id="{@name}" visibility="public">
168
            <xsl:call-template name="gen-params"/>  
169
            <xsl:apply-templates select="* except param"/>
170
        </constructor>
171
    </xsl:template>
172
    
173
    <xsl:template match="method">
174
        <method id="{@name}" 
175
            visibility="{if (@public='true') then 'public' else 'protected'}"
176
            type="{f:shortName(@type)}" fulltype="{f:fullName(@type)}">
177
            <xsl:copy-of select="@static[.='true']"/>
178
            <xsl:copy-of select="@abstract[.='true']"/>
179
            <xsl:apply-templates select="type"/>
180
            <xsl:apply-templates select="paramtypes"/>
181
            <xsl:apply-templates select="comments"/>
182
            <xsl:call-template name="gen-params"/>           
183
        </method>
184
    </xsl:template>
185
    
186
    <xsl:template name="gen-params">
187
        <xsl:if test="param">
188
            <params>
189
                <xsl:variable name="this" select="."/>
190
                <xsl:for-each select="param">
191
                    <param fulltype="{f:fullName(@type)}" type="{f:shortName(@type)}">
192
                        <xsl:variable name="which" select="position()"/>
193
                        <xsl:variable name="notes" select="$this/comments/param[$which]"/>
194
                        <xsl:choose>
195
                            <xsl:when test="@name">
196
                                <xsl:attribute name="name" select="@name"/>
197
                            </xsl:when>
198
                            <xsl:otherwise>
199
                                <xsl:copy-of select="$notes/@name"/>
200
                            </xsl:otherwise>
201
                        </xsl:choose>
202
                        <xsl:apply-templates select="type"/>
203
                        <xsl:if test="$notes/node()">
204
                            <body>
205
                                <div><xsl:apply-templates select="$notes/node()"/></div>
206
                            </body>
207
                        </xsl:if>
208
                    </param>
209
                </xsl:for-each>
210
            </params>
211
        </xsl:if>
212
        <xsl:if test="comments/exception">
213
            <exceptions>
214
                <xsl:apply-templates select="comments/exception"/>
215
            </exceptions>
216
        </xsl:if>
217
    </xsl:template>
218
    
219
    <xsl:template match="property">
220
        <property id="{@name}"
221
            type="{f:shortName(@type)}"
222
            fulltype="{f:fullName(@type)}">
223
            <xsl:copy-of select="@static[.='true']"/>
224
            <xsl:copy-of select="@abstract[.='true']"/>
225
            <xsl:copy-of select="@get[.='true']"/>
226
            <xsl:copy-of select="@set[.='true']"/>
227
            <xsl:apply-templates/>
228
        </property>
229
    </xsl:template>
230
    
231
    <xsl:template match="field">
232
        <field id="{@name}"
233
            type="{if (@type) then f:shortName(@type) else ''}"
234
            fulltype="{if (@type) then f:fullName(@type) else ''}"
235
            visibility="{if (@public='true') then 'public' else 'protected'}">
236
            <xsl:copy-of select="@static[.='true']"/>
237
            <xsl:copy-of select="@abstract[.='true']"/>
238
            <xsl:apply-templates/>
239
        </field>
240
    </xsl:template>
241
    
242
    <xsl:template match="paramtypes | type[@name]">
243
        <xsl:copy-of select="."/>
244
    </xsl:template>
245
    
246
    <xsl:template match="extends | implements">
247
        <!-- Similar to javadoc, only include extends child if the interface is not 'System.Object'.
248
            In fact, previous step merge.xsl should no longer produce these. -->
249
        <xsl:if test="string(interface[1]/@type) ne 'System.Object'">
250
            <xsl:copy>
251
                <xsl:apply-templates mode="extends"/>
252
            </xsl:copy>
253
        </xsl:if>
254
    </xsl:template>
255
    
256
    <xsl:template match="interface" mode="extends">
257
        <xsl:copy>
258
            <xsl:attribute name="fulltype" select="f:fullName(@type)"/>
259
            <xsl:attribute name="type" select="f:shortName(@type)"/>
260
            <xsl:apply-templates/>
261
        </xsl:copy>
262
    </xsl:template>
263
    
264
    <xsl:template match="type">
265
        <type fulltype="{f:fullName(@type)}" type="{f:shortName(@type)}">
266
            <xsl:copy-of select="@extendby"/>
267
            <xsl:copy-of select="@super"/>
268
        </type>
269
    </xsl:template>
270
    
271
    <xsl:template match="comments[normalize-space()]">
272
        <comment>
273
            <xsl:apply-templates select="node() except (param|exception)"/><!-- TODO handle comments/attribute, @since -->
274
        </comment>
275
    </xsl:template>
276
    
277
    <xsl:template match="comments"/>
278
    
279
    <xsl:template match="obsolete">
280
        <attribute name="@deprecated">
281
            <body>
282
                <div><xsl:value-of select="."/></div>
283
            </body>
284
        </attribute>
285
    </xsl:template>
286
    
287
    <xsl:template match="example"><!-- TODO what becomes of examples??? -->
288
        <div class="example">
289
            <xsl:apply-templates/>
290
        </div>
291
    </xsl:template>
292
    
293
    <xsl:template match="summary">
294
        <sentence>
295
            <xsl:apply-templates/>
296
        </sentence>
297
    </xsl:template>
298
    
299
    <xsl:template match="returns">
300
        <return>
301
            <body>
302
                <div>
303
                    <xsl:apply-templates/>
304
                </div>
305
            </body>
306
        </return>
307
    </xsl:template>
308
    
309
    <xsl:template match="exception">
310
        <exception id="{@name}" fulltype="{f:fullName(@name)}">
311
            <sentence>
312
                <xsl:apply-templates/>
313
            </sentence>
314
        </exception>
315
    </xsl:template>
316
    
317
    <xsl:template match="summary[@inherit='yes']"/>
318
    
319
    <xsl:template match="remarks[text()]" priority="3">
320
        <body>
321
            <div>
322
                <p><xsl:apply-templates select="preceding-sibling::summary/node()"/></p>
323
                <p><xsl:apply-templates select="node()"/></p>
324
            </div>
325
        </body>
326
    </xsl:template>
327
    
328
    <xsl:template match="remarks[para]" priority="4">
329
        <body>
330
            <div>
331
                <p><xsl:apply-templates select="preceding-sibling::summary/node()"/></p>
332
                <xsl:apply-templates/>
333
            </div>
334
        </body>
335
    </xsl:template>
336
    
337
    <xsl:template match="para | p">
338
        <p>
339
            <xsl:apply-templates/>
340
        </p>
341
    </xsl:template>
342
    
343
    <xsl:template match="c | code">
344
        <code>
345
            <xsl:apply-templates/>
346
        </code>
347
    </xsl:template>
348
    
349
    <xsl:template match="i | em | b">
350
        <xsl:copy>
351
            <xsl:apply-templates/>
352
        </xsl:copy>
353
    </xsl:template>
354
    
355
    <xsl:template match="link">
356
        <xsl:apply-templates/>
357
    </xsl:template>
358
    
359
    <xsl:template match="list">
360
        <ul>
361
            <xsl:apply-templates/>
362
        </ul>
363
    </xsl:template>
364
    
365
    <xsl:template match="list[@type='number']">
366
        <ol>
367
            <xsl:apply-templates/>
368
        </ol>
369
    </xsl:template>
370
    
371
    <xsl:template match="item">
372
        <li>
373
            <xsl:apply-templates/>
374
        </li>
375
    </xsl:template>
376
    
377
    <xsl:template match="tag | span">
378
        <xsl:copy>
379
            <xsl:copy-of select="@*"/>
380
            <xsl:apply-templates/>
381
        </xsl:copy>
382
    </xsl:template>
383
    
384
    <xsl:template match="*">
385
        <xsl:message>*** No template found for <xsl:value-of select="name()"/></xsl:message>
386
    </xsl:template>
387
    
388
    <xsl:function name="f:fullName" as="xs:string">
389
        <xsl:param name="shortName" as="xs:string"/>
390
        <xsl:variable name="isArray" as="xs:boolean" select="ends-with($shortName, '[]')"/>
391
        <xsl:variable name="shortName2" select="if ($isArray) then translate($shortName, '[]','')
392
            else $shortName"/>
393
        <xsl:variable name="end" select="if ($isArray) then '[]' else ''"/>
394
        <xsl:variable name="class" select="key('class-by-name', $shortName2, $root)"/>
395
        <xsl:choose>
396
            <xsl:when test="starts-with($shortName, 'net.sf.saxon.') or starts-with($shortName, 'com.saxonica.')
397
                or starts-with($shortName, 'Saxon.Api.') or starts-with($shortName, 'System.')">
398
                <xsl:value-of select="$shortName"/>
399
            </xsl:when>
400
            <xsl:when test="exists($class)">
401
                <xsl:value-of select="concat('Saxon.Api.', $class/@name)"/>
402
            </xsl:when>
403
            <xsl:otherwise>
404
                <xsl:if test="not($shortName = ('void', 'T')) and not(starts-with($shortName, 'java.') or
405
                    starts-with($shortName, 'javax.'))">
406
                    <xsl:message>Unresolved name <xsl:value-of select="$shortName"/></xsl:message>
407
                    <!-- Note some irrelevant unresolved System or Java types may appear in @base on class or interface. -->
408
                </xsl:if>
409
                <xsl:value-of select="$shortName"/>
410
            </xsl:otherwise>
411
        </xsl:choose>
412
    </xsl:function>
413
    
414
    <xsl:variable name="root" select="/"/>
415
    
416
    <xsl:key name="class-by-name" match="class | interface | enum" 
417
        use="if (contains(@name,'.')) then tokenize(@name, '\.')[last()] else @name"/>
418
    
419
    <!-- Get short name for type: use abbreviated name for relevant System types, 
420
        and nested name for nested classes. -->
421
    <xsl:function name="f:shortName" as="xs:string">
422
        <xsl:param name="type" as="xs:string"/>
423
        <xsl:choose>
424
            <xsl:when test="not(contains($type, '.'))">
425
                <xsl:value-of select="$type"/>
426
            </xsl:when>
427
            <xsl:when test="starts-with($type, 'System.') and map:contains($typeAbbreviationsMap, $type)">
428
                <xsl:value-of select="map:get($typeAbbreviationsMap, $type)"/>
429
            </xsl:when>
430
            <xsl:when test="starts-with($type, 'System.')">
431
                <xsl:value-of select="tokenize($type, '\.')[last()]"/>
432
            </xsl:when>
433
            <xsl:when test="starts-with($type, 'Saxon.Api.')">
434
                <xsl:value-of select="substring-after($type, 'Saxon.Api.')"/>
435
            </xsl:when>
436
            <xsl:otherwise>
437
                <!-- For Java types, want the parts of $type beginning with a capital letter -->
438
                <xsl:value-of select="tokenize($type, '\.')[matches(., '^[A-Z]')] => string-join('.')"/>
439
            </xsl:otherwise>
440
        </xsl:choose>
441
    </xsl:function>
442
    
443
    <!-- Get abbreviations for relevant System types in tohtml.xsl and convert-to-jel-package.xsl -->
444
    <xsl:variable name="typeAbbreviationsMap" as="map(xs:string, xs:string)"
445
        select="map{
446
        'System.Boolean':'bool',
447
        'System.Char':'char',
448
        'System.Decimal':'decimal',
449
        'System.Double':'double',
450
        'System.Single':'float',
451
        'System.Int32':'int',
452
        'System.Int64':'long',
453
        'System.Object':'object',
454
        'System.String':'string'
455
        }"/>
456
    
457
</xsl:stylesheet>
(1-1/7)