Project

Profile

Help

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

he / tools / elements-body.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" xmlns:el="http://www.saxonica.com/ns/doc/elements"
4
    xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax"
5
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xs el e xsi"
6
    version="3.0"> 
7

    
8
    <xsl:output indent="yes"/>
9

    
10
    <!-- Designed to transform src/elements/xsl-elements-expanded.xml; also used for:
11
        src/extensions/instructions-src.xml (contains saxon-element elements)
12
        src/extensions/serialization-params-src.xml (contains element-syntax elements)
13
        src/extensions/sql-extension-src.xml (contains saxon-element elements) -->
14

    
15
    <xsl:variable name="implementation-doc"
16
                  select="doc('../src/viewer_appJS/doc/implement.xml')"
17
                  as="document-node()"/>
18
    <xsl:variable name="id" select="article/@id|section[1]/@id"/>
19

    
20
    <xsl:template match="article|section[h1]">
21
        <xsl:copy>
22
            <xsl:sequence select="@id|@title"/>
23
            <xsl:comment>Generated - <xsl:value-of select="current-dateTime()"/> 
24
                <xsl:if test="$id='xsl-elements'"> from src/elements/xsl-elements-expanded.xml, which is itself generated from src/elements/xsl-elements-src.xml (the editable version)</xsl:if>
25
                <xsl:if test="$id='instructions'"> from src/extensions/instructions-src.xml (the editable version)</xsl:if>    
26
                <xsl:if test="$id='serialization-parameters'"> from src/extensions/serialization-params-src.xml (the editable version)</xsl:if> 
27
                <xsl:if test="$id='sql-extension'"> from src/extensions/sql-extension-src.xml (the editable version)</xsl:if>
28
            </xsl:comment>
29
            <xsl:apply-templates select="*" mode="#current"/>
30
        </xsl:copy>
31
    </xsl:template>
32

    
33
    <xsl:template match="node()|@*">
34
        <xsl:copy>
35
            <xsl:apply-templates select="node()|@*" mode="#current"/>
36
        </xsl:copy>
37
    </xsl:template>
38

    
39
    <xsl:template match="el:*">
40
        <xsl:element name="{local-name()}">
41
            <xsl:apply-templates select="node()|@*" mode="#current"/>
42
        </xsl:element>
43
    </xsl:template>
44

    
45
    <xsl:template match="el:xsl-element|el:saxon-element">
46
        <xsl:variable name="MyElement" select="."/>
47
        <xsl:variable name="elemName" select="el:name"/>
48
        <xsl:variable name="default.saxon"
49
            select="$implementation-doc/implement/default[@id = $id]/@saxon"/>
50
        <h1>
51
            <xsl:if test="self::el:xsl-element">
52
                <xsl:value-of select="concat('xsl:', $elemName)"/>
53
            </xsl:if>
54
            <xsl:if test="el:name/@namespace='http://saxon.sf.net/'">
55
                <xsl:value-of select="concat('saxon:', $elemName)"/>
56
            </xsl:if>
57
            <xsl:if test="el:name/@namespace='http://saxon.sf.net/sql'">
58
                <xsl:value-of select="concat('sql:', $elemName)"/>
59
            </xsl:if>
60
            <xsl:if test="el:name/@namespace='http://icl.com/saxon'">
61
                <xsl:value-of select="concat('saxon6:', $elemName)"/>
62
            </xsl:if>
63
        </h1>
64

    
65
        <xsl:apply-templates select="el:description" mode="#current"/>
66

    
67
        <aside>
68
            <xsl:value-of select="el:specs(el:in-spec)"/>
69
            <xsl:value-of select="el:edition((el:saxon-edition,$default.saxon,'default')[1])"/>
70
        </aside>
71

    
72

    
73
        <xsl:if test="el:element-syntax/*[not(self::el:attribute)]">
74
            <xsl:apply-templates select="el:element-syntax" mode="model"/>
75
        </xsl:if>
76

    
77
        <xsl:if test="el:element-syntax/el:attribute">
78
            <h3 class="subtitle">Attributes</h3>
79
            <xsl:apply-templates select="el:element-syntax" mode="#current"/>
80
        </xsl:if>
81

    
82
        <xsl:if test="el:status">
83
            <h3 class="subtitle">Notes on the Saxon implementation</h3>
84
            <xsl:apply-templates select="el:status" mode="#current"/>
85
        </xsl:if>
86
        <!-- <status-ok> elements are ignored -->
87

    
88
        <xsl:if test="el:details">
89
            <h3 class="subtitle">Details</h3>
90
            <xsl:apply-templates select="el:details" mode="#current"/>
91
        </xsl:if>
92

    
93
        <xsl:if test="el:examples">
94
            <h3 class="subtitle">Examples</h3>
95
            <xsl:apply-templates select="el:examples" mode="#current"/>
96
        </xsl:if>
97

    
98
        <xsl:if test="el:in-spec">
99
            <h3 class="subtitle">Links to W3C specifications</h3>
100
            <xsl:apply-templates select="el:in-spec" mode="#current"/>
101
        </xsl:if>
102

    
103
        <xsl:if test="el:see-also">
104
            <h3 class="subtitle">See also</h3>
105
            <xsl:apply-templates select="el:see-also" mode="#current"/>
106
        </xsl:if>
107

    
108
    </xsl:template>
109

    
110
    <xsl:template match="el:description">
111
        <xsl:apply-templates mode="#current"/>
112
    </xsl:template>
113

    
114
    <xsl:template match="el:element-syntax">
115
        <!-- Build table of attributes with descriptions -->
116
        <table class="element-att">
117
            <xsl:for-each select="el:attribute">
118
                <tr>
119
                    <td>
120
                        <p>
121
                            <code>
122
                                <xsl:apply-templates select="."/>
123
                            </code>
124
                        </p>
125
                    </td>
126
                    <td>
127
                        <p>
128
                            <code>
129
                                <xsl:apply-templates select="* except el:desc"/>
130
                            </code>
131
                        </p>
132
                    </td>
133
                    <td>
134
                        <p>
135
                            <xsl:apply-templates select="el:desc"/>
136
                        </p>
137
                    </td>
138
                </tr>
139
            </xsl:for-each>
140
        </table>
141
    </xsl:template>
142

    
143
    <xsl:template match="el:attribute">
144
        <xsl:choose>
145
            <xsl:when test="@deprecated='yes'">
146
                <xsl:text>[</xsl:text>
147
                <xsl:value-of select="@name"/>
148
                <xsl:text>]?</xsl:text>
149
            </xsl:when>
150
            <xsl:when test="@required='yes'">
151
                <strong>
152
                    <xsl:value-of select="@name"/>
153
                </strong>
154
            </xsl:when>
155
            <xsl:when test="parent::el:element-syntax[@name eq 'output-extras']">
156
                <xsl:value-of select="@name"/>
157
            </xsl:when>
158
            <xsl:otherwise>
159
                <xsl:value-of select="@name"/>
160
                <xsl:text>?</xsl:text>
161
            </xsl:otherwise>
162
        </xsl:choose>
163
    </xsl:template>
164

    
165
    <xsl:template match="el:data-type">
166
        <xsl:if test="position()>3"> | </xsl:if>
167
        <i>
168
            <xsl:value-of select="@name"/>
169
        </i>
170
    </xsl:template>
171

    
172
    <xsl:template match="el:constant">
173
        <xsl:if
174
            test="(position()>1 and not(parent::el:attribute-value-template)) or (position()>2 and parent::el:attribute-value-template)"
175
            > | </xsl:if>
176
        <xsl:text>"</xsl:text>
177
        <xsl:value-of select="@value"/>
178
        <xsl:text>"</xsl:text>
179
    </xsl:template>
180

    
181
    <xsl:template match="el:attribute-value-template">
182
        <xsl:text>{ </xsl:text>
183
        <xsl:apply-templates/>
184
        <xsl:text> }</xsl:text>
185
    </xsl:template>
186

    
187
    <xsl:template match="el:desc">
188
        <xsl:apply-templates mode="#current"/>
189
    </xsl:template>
190

    
191

    
192
    <xsl:template match="el:in-spec">
193
        <!-- Add relevant links to XSLT specifications, using in-spec elements -->
194
        <xsl:variable name="elemName" select="../el:name"/>
195
        <xsl:if test=". = 'xslt20'">
196
            <p>
197
                <a href="http://www.w3.org/TR/xslt20/#element-{$elemName}">XSLT 2.0
198
                    Specification</a>
199
            </p>
200
        </xsl:if>
201
        <xsl:if test=". = 'xslt30'">
202
            <p>
203
                <a href="http://www.w3.org/TR/xslt-30/#element-{$elemName}">XSLT 3.0
204
                    Specification</a>
205
            </p>
206
        </xsl:if>
207
    </xsl:template>
208

    
209
    <xsl:template match="el:status">
210
        <xsl:apply-templates mode="#current"/>
211
    </xsl:template>
212

    
213
    <xsl:template match="el:details">
214
        <xsl:apply-templates mode="#current"/>
215
    </xsl:template>
216

    
217
    <xsl:template match="el:examples">
218
        <!-- List of examples (enumerated if more than one).-->
219
        <xsl:choose>
220
            <xsl:when test="el:example">
221
                <xsl:choose>
222
                    <xsl:when test="count(el:example) = 1">
223
                        <xsl:for-each select="el:example">
224
                            <xsl:apply-templates mode="#current"/>
225
                        </xsl:for-each>
226
                    </xsl:when>
227
                    <xsl:otherwise>
228
                        <xsl:iterate select="el:example">
229
                            <xsl:param name="i" select="1" as="xs:integer"/>
230
                            <xsl:variable name="new-i" select="$i + 1"/>
231
                            <h4>Example <xsl:value-of select="$i"/></h4>
232
                            <xsl:apply-templates mode="#current"/>
233
                            <xsl:next-iteration>
234
                                <xsl:with-param name="i" select="$new-i"/>
235
                            </xsl:next-iteration>
236
                        </xsl:iterate>
237
                    </xsl:otherwise>
238
                </xsl:choose>
239
            </xsl:when>
240
            <xsl:otherwise>
241
                <xsl:apply-templates mode="#current"/>
242
            </xsl:otherwise>
243
        </xsl:choose>
244
    </xsl:template>
245

    
246
    <xsl:template match="el:see-also">
247
        <!-- Give links to related xsl-elements, literal result element, functions, extensions -->
248
        <xsl:if test="@type = 'xsl-elements'">
249
            <xsl:choose>
250
                <xsl:when test="@name = 'lre'">
251
                    <p>
252
                        <a class="bodylink" href="/{@type}/{@name}">literal result elements
253
                        </a>
254
                    </p>
255
                </xsl:when>
256
                <xsl:otherwise>
257
                    <p>
258
                        <a class="bodylink" href="/{@type}/{@name}">
259
                            <xsl:value-of select="concat('xsl:', @name)"/>
260
                        </a>
261
                    </p>
262
                </xsl:otherwise>
263
            </xsl:choose>
264
        </xsl:if>
265
        <xsl:if test="@type = 'functions'">
266
            <xsl:choose>
267
                <xsl:when test="@namespace">
268
                    <p>
269
                        <a class="bodylink" href="/{@type}/{@namespace}/{@name}"><xsl:value-of
270
                                select="concat(el:namespace-prefix(@namespace),':', @name)"/>()</a>
271
                    </p>
272
                </xsl:when>
273
                <xsl:otherwise>
274
                    <p>
275
                        <a class="bodylink" href="/{@type}/fn/{@name}"><xsl:value-of
276
                                select="@name"/>()</a>
277
                    </p>
278
                </xsl:otherwise>
279
            </xsl:choose>
280
        </xsl:if>
281
        <xsl:if test="@type = 'extensions'">
282
            <p>
283
                <a class="bodylink" href="/{@type}/{@subtype}/{@name}">
284
                    <xsl:value-of select="concat(@namespace,':', @name)"/>
285
                </a>
286
            </p>
287
        </xsl:if>
288
        <xsl:if test="@type = 'sql-extension'">
289
            <p>
290
                <a class="bodylink" href="/{@type}/{@subtype}/{@name}">
291
                    <xsl:value-of select="concat('sql:', @name)"/>
292
                </a>
293
            </p>
294
        </xsl:if>
295
    </xsl:template>
296

    
297
    <!--    Model section-->
298

    
299
    <xsl:template match="el:element-syntax" mode="model">
300
        <p class="element-syntax">
301
            <xsl:apply-templates select="el:in-category"/>
302
            <xsl:apply-templates select="el:sequence|el:choice|el:model|el:content|el:text|el:empty"
303
                mode="#current"/>
304
            <xsl:apply-templates select="el:allowed-parents"/>
305
            <xsl:if test="not(el:attribute)">
306
                <xsl:call-template name="no-attributes"/>
307
            </xsl:if>
308
        </p>
309
    </xsl:template>
310

    
311
    <xsl:template match="el:in-category">
312
        <strong>Category: </strong>
313
        <xsl:value-of select="@name"/>
314
        <br/>
315
    </xsl:template>
316

    
317
    <xsl:template name="no-attributes">
318
        <br/>
319
        <strong>
320
            <i>Element has no attributes</i>
321
        </strong>
322
    </xsl:template>
323

    
324
    <xsl:template match="el:sequence|el:choice|el:model|el:content|el:text|el:empty" mode="model">
325
        <strong>Content: </strong>
326
        <xsl:apply-templates select="."/>
327
    </xsl:template>
328

    
329
    <xsl:template match="el:sequence|el:choice">
330
        <xsl:call-template name="group"/>
331
        <xsl:text>(</xsl:text>
332
        <xsl:apply-templates/>
333
        <xsl:text>)</xsl:text>
334
        <xsl:call-template name="repeat"/>
335
    </xsl:template>
336

    
337
    <xsl:template match="el:model">
338
        <xsl:call-template name="group"/>
339
        <i>
340
            <xsl:value-of select="@name"/>
341
        </i>
342
        <xsl:call-template name="repeat"/>
343
    </xsl:template>
344

    
345
    <xsl:template match="el:text">#PCDATA</xsl:template>
346

    
347
    <xsl:template match="el:empty">none</xsl:template>
348

    
349
    <xsl:template match="el:content">
350
        <xsl:call-template name="group"/>
351
        <xsl:choose>
352
            <xsl:when test="contains(@name, ':')">
353
                <xsl:value-of select="@name"/>
354
            </xsl:when>
355
            <xsl:otherwise>
356
                <a class="bodylink code" href="/xsl-elements/{@name}">
357
                    <xsl:value-of select="concat('xsl:', @name)"/>
358
                </a>
359
            </xsl:otherwise>
360
        </xsl:choose>
361
        <xsl:call-template name="repeat"/>
362
    </xsl:template>
363

    
364
    <xsl:template name="group">
365
        <xsl:if test="position()>2">
366
            <xsl:choose>
367
                <xsl:when test="parent::el:sequence">, </xsl:when>
368
                <xsl:when test="parent::el:choice"> | </xsl:when>
369
                <xsl:when test="parent::el:allowed-parents">; </xsl:when>
370
            </xsl:choose>
371
        </xsl:if>
372
    </xsl:template>
373

    
374
    <xsl:template name="repeat">
375
        <xsl:choose>
376
            <xsl:when test="@repeat='one-or-more'">
377
                <xsl:text>+</xsl:text>
378
            </xsl:when>
379
            <xsl:when test="@repeat='zero-or-more'">
380
                <xsl:text>*</xsl:text>
381
            </xsl:when>
382
            <xsl:when test="@repeat='zero-or-one'">
383
                <xsl:text>?</xsl:text>
384
            </xsl:when>
385
        </xsl:choose>
386
    </xsl:template>
387

    
388
    <xsl:template match="el:allowed-parents">
389
        <br/>
390
        <strong>Permitted parent elements: </strong>
391
        <xsl:apply-templates/>
392
        <xsl:if test="not(*)">None</xsl:if>
393
    </xsl:template>
394

    
395
    <xsl:template match="el:parent">
396
        <xsl:call-template name="group"/>
397
        <a href="/xsl-elements/{@name}" class="bodylink code">
398
            <xsl:value-of select="concat('xsl:', @name)"/>
399
        </a>
400
    </xsl:template>
401

    
402
    <xsl:template match="el:parent-category[@name='sequence-constructor']">
403
        <xsl:if test="position()>2">; </xsl:if> any XSLT element whose content model is 
404
        <i>sequence-constructor</i>; any literal result element </xsl:template>
405

    
406

    
407
    <!-- Determine text within 'Specs versions & Saxon editions' note: 
408
  Spec versions in which the elements are defined. -->
409
    <xsl:function name="el:specs" as="xs:string*">
410
        <xsl:param name="in" as="element(el:in-spec)*"/>
411
        <!-- in-spec elements should be in order such that first one $in[1] is earliest spec, to ensure the correct message. -->
412
        <xsl:value-of select="$implementation-doc/implement/spec[@value = $in[1]]"/>
413
    </xsl:function>
414

    
415
    <!-- Determine text within 'Specs versions & Saxon editions' note: Saxon editons & versions. -->
416
    <xsl:function name="el:edition" as="xs:string*">
417
        <xsl:param name="available" as="xs:string"/>
418
        <xsl:variable name="available"
419
            select="for $t in tokenize($available, '\s+') return upper-case($t)" as="xs:string*"/>
420
        <xsl:for-each select="$available">
421
            <xsl:value-of select="$implementation-doc/implement/saxon[@version = current()]"/>
422
        </xsl:for-each>
423
    </xsl:function>
424
    
425
    <!-- Get namespace conventional prefix for functions. -->
426
    <xsl:function name="el:namespace-prefix" as="xs:string">
427
        <xsl:param name="ns" as="xs:string"/>
428
        <xsl:choose>
429
            <xsl:when test="$ns = 'fn'">fn</xsl:when>
430
            <xsl:when test="$ns = 'saxon'">saxon</xsl:when>
431
            <xsl:when test="$ns = 'map'">map</xsl:when>
432
            <xsl:when test="$ns = 'math'">math</xsl:when>
433
            <xsl:when test="$ns = 'expath-archive'">arch</xsl:when>
434
            <xsl:when test="$ns = 'expath-binary'">bin</xsl:when>
435
            <xsl:when test="$ns = 'expath-file'">file</xsl:when>
436
            <xsl:when test="$ns = 'expath-zip'">zip</xsl:when>
437
            <xsl:when test="$ns = 'exslt-common'">exsl</xsl:when>
438
            <xsl:when test="$ns = 'exslt-random'">random</xsl:when>
439
            <xsl:when test="$ns = 'exslt-math'">exslt-math</xsl:when>
440
            <xsl:when test="$ns = 'exslt-sets'">set</xsl:when>
441
            <xsl:when test="$ns = 'exslt-dates-and-times'">date</xsl:when>
442
            <xsl:otherwise>
443
                <xsl:value-of select="$ns"/>
444
            </xsl:otherwise>
445
        </xsl:choose>
446
    </xsl:function>
447

    
448

    
449
</xsl:stylesheet>
(10-10/15)