]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/docca/include/docca/base-stage1.xsl
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / docca / include / docca / base-stage1.xsl
1 <!DOCTYPE xsl:stylesheet [
2 <!-- TODO: complete this list -->
3 <!ENTITY BLOCK_LEVEL_ELEMENT "programlisting
4 | itemizedlist
5 | orderedlist
6 | parameterlist
7 | simplesect
8 | para
9 | table
10 | linebreak">
11 ]>
12 <xsl:stylesheet version="3.0"
13 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14 xmlns:xs="http://www.w3.org/2001/XMLSchema"
15 xmlns:d="http://github.com/vinniefalco/docca"
16 exclude-result-prefixes="xs d"
17 expand-text="yes">
18
19 <xsl:include href="common.xsl"/>
20
21 <xsl:output indent="yes"/>
22
23 <xsl:template match="/doxygen" priority="1">
24 <page id="{@d:page-id}" type="{@d:page-type}">
25 <xsl:apply-templates mode="index-term-atts" select="."/>
26 <title>
27 <xsl:apply-templates mode="page-title" select="."/>
28 </title>
29 <xsl:apply-templates select="@d:base-compound-refid"/>
30 <xsl:next-match/>
31 </page>
32 </xsl:template>
33
34 <xsl:template match="@d:base-compound-refid">
35 <div>(Inherited from <ref d:refid="{.}">{../@d:base-compound-name}</ref>)</div>
36 </xsl:template>
37
38 <!-- Put an index term on every page except class (compound) and overloaded-member pages -->
39 <xsl:template mode="index-term-atts" match="doxygen[@d:page-type eq 'compound' or @d:overload-position]"/>
40 <xsl:template mode="index-term-atts" match="doxygen">
41 <xsl:attribute name="primary-index-term">
42 <xsl:apply-templates mode="primary-index-term" select="."/>
43 </xsl:attribute>
44 <xsl:apply-templates mode="secondary-index-term-att" select="."/>
45 </xsl:template>
46
47 <!-- By default, use the member name as the primary term... -->
48 <xsl:template mode="primary-index-term" match="doxygen">
49 <xsl:apply-templates mode="member-name" select="."/>
50 </xsl:template>
51 <!-- ...and the compound name as the secondary term. -->
52 <xsl:template mode="secondary-index-term-att" match="doxygen">
53 <xsl:attribute name="secondary-index-term">
54 <xsl:apply-templates mode="compound-name" select="."/>
55 </xsl:attribute>
56 </xsl:template>
57
58 <!-- But with namespace members, use the fully-qualified name as the primary term... -->
59 <xsl:template mode="primary-index-term" match="doxygen[compounddef/@kind eq 'namespace']">
60 <xsl:apply-templates mode="compound-and-member-name" select="."/>
61 </xsl:template>
62 <!-- ...and no secondary term. -->
63 <xsl:template mode="secondary-index-term-att" match="doxygen[compounddef/@kind eq 'namespace']"/>
64
65 <xsl:template mode="compound-name" match="doxygen"
66 >{d:strip-doc-ns(compounddef/compoundname)}</xsl:template>
67
68 <xsl:template mode="member-name" match="doxygen"
69 >{(compounddef/sectiondef/memberdef/name)[1]}</xsl:template>
70
71 <xsl:template mode="compound-and-member-name" match="doxygen">
72 <xsl:variable name="compound-name" as="xs:string">
73 <xsl:apply-templates mode="compound-name" select="."/>
74 </xsl:variable>
75 <xsl:if test="$compound-name">{$compound-name}::</xsl:if>
76 <xsl:apply-templates mode="member-name" select="."/>
77 </xsl:template>
78
79 <xsl:template mode="page-title" match="doxygen[@d:page-type eq 'compound']">
80 <xsl:apply-templates mode="compound-name" select="."/>
81 </xsl:template>
82 <xsl:template mode="page-title" match="doxygen">
83 <xsl:apply-templates mode="compound-and-member-name" select="."/>
84 <xsl:apply-templates mode="overload-qualifier" select="."/>
85 </xsl:template>
86
87 <xsl:template mode="overload-qualifier" match="doxygen"/>
88 <xsl:template mode="overload-qualifier" match="doxygen[@d:overload-position]">
89 <xsl:text> (</xsl:text>
90 <xsl:value-of select="@d:overload-position"/>
91 <xsl:text> of </xsl:text>
92 <xsl:value-of select="@d:overload-size"/>
93 <xsl:text> overloads)</xsl:text>
94 </xsl:template>
95
96
97 <xsl:template match="/doxygen[@d:page-type eq 'compound']">
98 <xsl:apply-templates select="compounddef"/>
99 </xsl:template>
100
101 <xsl:template match="/doxygen[@d:page-type eq 'member']">
102 <xsl:apply-templates select="compounddef/sectiondef/memberdef"/> <!-- should just be one -->
103 </xsl:template>
104
105 <xsl:template match="/doxygen[@d:page-type eq 'overload-list']">
106 <xsl:apply-templates select="(compounddef/sectiondef/memberdef)[1]"/>
107 </xsl:template>
108
109 <xsl:template match="compounddef | memberdef" priority="2">
110 <xsl:next-match/>
111 <xsl:apply-templates mode="includes" select=".">
112 <xsl:with-param name="is-footer" select="true()"/>
113 </xsl:apply-templates>
114 </xsl:template>
115
116 <!-- For convenience, pre-calculate some member sequences and tunnel them through -->
117 <xsl:template match="compounddef" priority="1">
118 <xsl:next-match>
119 <xsl:with-param name="public-types"
120 select="sectiondef[@kind eq 'public-type']/memberdef
121 | innerclass[@prot eq 'public'][not(d:should-ignore-inner-class(.))]"
122 tunnel="yes"/>
123 <xsl:with-param name="friends"
124 select="sectiondef[@kind eq 'friend']/memberdef[not(type = ('friend class','friend struct'))]
125 [not(d:should-ignore-friend(.))]"
126 tunnel="yes"/>
127 </xsl:next-match>
128 </xsl:template>
129
130 <xsl:template match="compounddef">
131 <xsl:param name="public-types" tunnel="yes"/>
132 <xsl:param name="friends" tunnel="yes"/>
133
134 <xsl:apply-templates select="briefdescription"/>
135
136 <xsl:apply-templates mode="section"
137 select=".,
138
139 ( $public-types/self::memberdef/..
140 | $public-types/self::innerclass
141 )[1],
142
143 sectiondef[@kind = ( 'public-func', 'public-static-func')],
144 sectiondef[@kind = ('protected-func','protected-static-func')],
145 sectiondef[@kind = ( 'private-func', 'private-static-func')][$include-private-members],
146
147 sectiondef[@kind = ( 'public-attrib', 'public-static-attrib')],
148 sectiondef[@kind = ('protected-attrib','protected-static-attrib')],
149 sectiondef[@kind = ( 'private-attrib', 'private-static-attrib')][$include-private-members],
150
151 $friends/..,
152
153 sectiondef[@kind eq 'related'],
154
155 detaileddescription
156 "/>
157 </xsl:template>
158
159 <xsl:template match="memberdef">
160 <xsl:apply-templates select="briefdescription"/>
161 <xsl:apply-templates mode="section" select="., detaileddescription"/>
162 </xsl:template>
163
164 <xsl:template match="memberdef[@kind eq 'enum']">
165 <xsl:apply-templates select="briefdescription"/>
166 <xsl:apply-templates mode="section" select="., parent::sectiondef, detaileddescription"/>
167 </xsl:template>
168
169 <xsl:template match="memberdef[/doxygen/@d:page-type eq 'overload-list']">
170 <xsl:for-each-group select="../../sectiondef/memberdef" group-by="briefdescription">
171 <xsl:apply-templates select="briefdescription"/>
172 <xsl:apply-templates mode="overload-list" select="current-group()"/>
173 </xsl:for-each-group>
174 </xsl:template>
175
176 <xsl:template mode="overload-list" match="memberdef">
177 <overloaded-member>
178 <xsl:apply-templates mode="normalize-params" select="templateparamlist"/>
179 <xsl:apply-templates mode="modifier" select="(@explicit, @friend, @static)[. eq 'yes'],
180 @virt[. eq 'virtual']"/>
181 <xsl:apply-templates select="type"/>
182 <ref d:refid="{@d:page-refid}">{name}</ref>
183 <params>
184 <xsl:apply-templates select="param"/>
185 </params>
186 <xsl:apply-templates mode="modifier" select="@const[. eq 'yes']"/>
187 </overloaded-member>
188 </xsl:template>
189
190 <xsl:template mode="modifier" match="@*">
191 <modifier>{local-name(.)}</modifier>
192 </xsl:template>
193 <xsl:template mode="modifier" match="@virt">
194 <modifier>virtual</modifier>
195 </xsl:template>
196
197
198 <xsl:template match="type">
199 <type>
200 <xsl:value-of select="d:cleanup-type(normalize-space(.))"/>
201 </type>
202 </xsl:template>
203
204 <!-- d:cleanup-param() may not be needed, and the above may suffice. (TODO: confirm this and remove d:cleanup-param() if so)
205 <xsl:template match="param/type">
206 <type>
207 <xsl:value-of select="d:cleanup-param(.)"/>
208 </type>
209 </xsl:template>
210 -->
211
212 <!-- TODO: Should this be a custom rule or built-in? -->
213 <xsl:template mode="section" match="simplesect[matches(title,'Concepts:?')]"/>
214
215 <!-- Omit description section if it has no body -->
216 <xsl:template mode="section" match="detaileddescription[not(normalize-space(.))]" priority="1"/>
217
218 <xsl:template mode="section" match="*">
219 <section>
220 <heading>
221 <xsl:apply-templates mode="section-heading" select="."/>
222 </heading>
223 <xsl:apply-templates mode="section-body" select="."/>
224 </section>
225 </xsl:template>
226
227 <xsl:template match="simplesect | parameterlist">
228 <xsl:apply-templates mode="section" select="."/>
229 </xsl:template>
230
231 <xsl:template mode="section-heading" match="memberdef |
232 compounddef ">Synopsis</xsl:template>
233 <xsl:template mode="section-heading" match="detaileddescription">Description</xsl:template>
234
235 <xsl:template mode="section-heading" match="simplesect[@kind eq 'note' ]">Remarks</xsl:template>
236 <xsl:template mode="section-heading" match="simplesect[@kind eq 'see' ]">See Also</xsl:template>
237 <xsl:template mode="section-heading" match="simplesect[@kind eq 'return']">Return Value</xsl:template>
238 <xsl:template mode="section-heading" match="simplesect" >{title}</xsl:template>
239
240 <xsl:template mode="section-heading" match="parameterlist[@kind eq 'exception' ]">Exceptions</xsl:template>
241 <xsl:template mode="section-heading" match="parameterlist[@kind eq 'templateparam']">Template Parameters</xsl:template>
242 <xsl:template mode="section-heading" match="parameterlist ">Parameters</xsl:template>
243
244 <xsl:template mode="section-heading" match="innerclass">Types</xsl:template>
245
246 <xsl:template mode="section-heading" match="sectiondef[@kind eq 'friend' ]">Friends</xsl:template>
247 <xsl:template mode="section-heading" match="sectiondef[@kind eq 'related']">Related Functions</xsl:template>
248 <xsl:template mode="section-heading" match="sectiondef[@kind eq 'enum' ]">Values</xsl:template>
249
250 <xsl:template mode="section-heading" match="sectiondef">
251 <xsl:apply-templates mode="access-level" select="@kind"/>
252 <xsl:apply-templates mode="storage-class" select="@kind"/>
253 <xsl:apply-templates mode="member-kind" select="@kind"/>
254 </xsl:template>
255
256 <xsl:template mode="access-level" match="@kind[starts-with(.,'public-' )]"/>
257 <xsl:template mode="access-level" match="@kind[starts-with(.,'protected-')]">Protected </xsl:template>
258 <xsl:template mode="access-level" match="@kind[starts-with(.,'private-' )]">Private </xsl:template>
259
260 <xsl:template mode="storage-class" match="@*"/>
261 <xsl:template mode="storage-class" match="@kind[contains(.,'-static-')]">Static </xsl:template>
262
263 <xsl:template mode="member-kind" priority="1"
264 match="@kind[ends-with(.,'-static-attrib')]">Members</xsl:template>
265 <xsl:template mode="member-kind" match="@kind[ends-with(.,'-attrib' )]">Data Members</xsl:template>
266 <xsl:template mode="member-kind" match="@kind[ends-with(.,'-func' )]">Member Functions</xsl:template>
267 <xsl:template mode="member-kind" match="@kind[ends-with(.,'-type' )]">Types</xsl:template>
268
269
270 <xsl:template mode="section-body" match="sectiondef | innerclass | parameterlist">
271 <table>
272 <tr>
273 <th>
274 <xsl:apply-templates mode="column-1-name" select="."/>
275 </th>
276 <th>
277 <xsl:apply-templates mode="column-2-name" select="."/>
278 </th>
279 </tr>
280 <xsl:apply-templates mode="table-body" select="."/>
281 </table>
282 </xsl:template>
283
284 <xsl:template mode="column-1-name" match="*">Name</xsl:template>
285 <xsl:template mode="column-2-name" match="*">Description</xsl:template>
286
287 <xsl:template mode="column-1-name"
288 match="parameterlist[@kind = ('exception','templateparam')]">Type</xsl:template>
289
290 <xsl:template mode="column-2-name" match="parameterlist[@kind eq 'exception']">Thrown On</xsl:template>
291
292
293 <xsl:template mode="table-body" match="parameterlist">
294 <xsl:apply-templates mode="parameter-row" select="parameteritem"/>
295 </xsl:template>
296
297 <xsl:template mode="parameter-row" match="parameteritem">
298 <tr>
299 <td>
300 <code>
301 <!-- ASSUMPTION: <parameternamelist> only ever has one <parametername> child -->
302 <xsl:apply-templates select="parameternamelist/parametername/node()"/>
303 </code>
304 </td>
305 <td>
306 <xsl:apply-templates select="parameterdescription/node()"/>
307 </td>
308 </tr>
309 </xsl:template>
310
311 <xsl:template mode="table-body" match="sectiondef[@kind eq 'enum']">
312 <xsl:apply-templates mode="enum-row" select="memberdef/enumvalue"/> <!-- Use input order for enum values -->
313 </xsl:template>
314
315 <xsl:template mode="enum-row" match="enumvalue">
316 <tr>
317 <td>
318 <code>{name}</code>
319 </td>
320 <td>
321 <xsl:apply-templates select="briefdescription, detaileddescription"/>
322 </td>
323 </tr>
324 </xsl:template>
325
326 <xsl:template mode="table-body" match="sectiondef | innerclass">
327 <xsl:variable name="member-nodes" as="element()*">
328 <xsl:apply-templates mode="member-nodes" select="."/>
329 </xsl:variable>
330 <xsl:for-each-group select="$member-nodes" group-by="d:member-name(.)">
331 <xsl:sort select="current-grouping-key()"/>
332 <xsl:apply-templates mode="member-row" select="."/>
333 </xsl:for-each-group>
334 </xsl:template>
335
336 <xsl:template mode="member-nodes" match="innerclass | sectiondef[@kind eq 'public-type']">
337 <xsl:param name="public-types" tunnel="yes" select="()"/>
338 <xsl:sequence select="$public-types"/>
339 </xsl:template>
340
341 <xsl:template mode="member-nodes" match="sectiondef[@kind eq 'friend']">
342 <xsl:param name="friends" tunnel="yes"/>
343 <xsl:sequence select="$friends"/>
344 </xsl:template>
345
346 <xsl:template mode="member-nodes" match="sectiondef">
347 <!--
348 ASSUMPTION (for now): At least one member per section (table) must not be in a user-defined group.
349 Also, we may need a more robust mapping between a user-defined group's members and the sections
350 in which they belong. For now, we are using this partial test.
351 -->
352 <xsl:sequence select="memberdef,
353 ../sectiondef[@kind eq 'user-defined']/memberdef[(@kind||@prot||@static) =
354 current()/memberdef/(@kind||@prot||@static)]"/>
355 </xsl:template>
356
357
358 <xsl:function name="d:member-name">
359 <xsl:param name="element"/>
360 <xsl:apply-templates mode="member-name" select="$element"/>
361 </xsl:function>
362
363 <xsl:template mode="member-name" match="memberdef">
364 <xsl:sequence select="name"/>
365 </xsl:template>
366 <xsl:template mode="member-name" match="innerclass">
367 <xsl:sequence select="d:referenced-inner-class/compounddef/compoundname ! d:strip-ns(.)"/>
368 </xsl:template>
369
370
371 <xsl:template mode="member-row" match="*">
372 <tr>
373 <td>
374 <bold>
375 <ref d:refid="{@d:page-refid}">{current-grouping-key()}</ref>
376 <xsl:apply-templates mode="member-annotation" select="."/>
377 </bold>
378 </td>
379 <td>
380 <xsl:apply-templates mode="member-description" select="."/>
381 </td>
382 </tr>
383 </xsl:template>
384
385 <xsl:template mode="member-annotation" match="*">
386 <xsl:variable name="member-name" select="current-grouping-key()"/>
387 <xsl:variable name="is-destructor" select="starts-with($member-name, '~')"/>
388 <xsl:variable name="is-constructor" select="$member-name = d:strip-ns(/doxygen/compounddef/compoundname)"/>
389 <xsl:if test="$is-destructor or $is-constructor">
390 <xsl:text>&#160;</xsl:text>
391 <role class="silver">
392 <xsl:choose>
393 <xsl:when test="$is-destructor">[destructor]</xsl:when>
394 <xsl:otherwise >[constructor]</xsl:otherwise>
395 </xsl:choose>
396 </role>
397 </xsl:if>
398 </xsl:template>
399
400
401 <xsl:template mode="member-description" match="innerclass">
402 <xsl:apply-templates select="d:referenced-inner-class/compounddef/briefdescription"/>
403 </xsl:template>
404 <xsl:template mode="member-description" match="memberdef">
405 <xsl:variable name="descriptions" select="current-group()/briefdescription"/>
406 <!-- Pull in any overload descriptions but only if they vary -->
407 <xsl:for-each select="distinct-values($descriptions)">
408 <!-- ASSUMPTION: <briefdescription> always contains one <para> -->
409 <xsl:apply-templates select="$descriptions[. eq current()][1]/para/node()"/>
410 <xsl:if test="position() ne last()">
411 <br/>
412 <role class="silver">—</role>
413 <br/>
414 </xsl:if>
415 </xsl:for-each>
416 </xsl:template>
417
418
419 <xsl:template mode="section-body" match="detaileddescription | simplesect">
420 <xsl:apply-templates/>
421 </xsl:template>
422
423 <xsl:template mode="section-body" match="compounddef | memberdef" priority="1">
424 <xsl:apply-templates mode="includes" select="."/>
425 <xsl:next-match/>
426 </xsl:template>
427
428 <xsl:template mode="section-body" match="compounddef">
429 <compound>
430 <xsl:apply-templates mode="normalize-params" select="templateparamlist"/>
431 <kind>{@kind}</kind>
432 <name>{d:strip-ns(compoundname)}</name>
433 <xsl:for-each select="basecompoundref[not(d:should-ignore-base(.))]
434 [not(@prot eq 'private')]">
435 <base>
436 <prot>{@prot}</prot>
437 <name>{d:strip-doc-ns(.)}</name>
438 </base>
439 </xsl:for-each>
440 </compound>
441 </xsl:template>
442
443 <xsl:template mode="section-body" match="memberdef[@kind eq 'typedef']">
444 <typedef>
445 <xsl:apply-templates mode="normalize-params" select="templateparamlist"/>
446 <xsl:apply-templates select="name, type"/>
447 </typedef>
448 <!-- Nested compounddefs were derived from refs in the typedef's type -->
449 <xsl:apply-templates select="d:referenced-typedef-class/compounddef"/>
450 </xsl:template>
451
452 <!-- Suppress the display of several aspects of referenced typedef classes -->
453
454 <!-- Don't show the briefdescription -->
455 <xsl:template match="d:referenced-typedef-class/compounddef/briefdescription"/>
456
457 <!-- Don't show the Synopsis -->
458 <xsl:template mode="section" match="d:referenced-typedef-class/compounddef"/>
459
460 <!-- Exclude the "Description" heading (only show the body) -->
461 <xsl:template mode="section" match="d:referenced-typedef-class/compounddef/detaileddescription">
462 <xsl:apply-templates mode="section-body" select="."/>
463 </xsl:template>
464
465 <!-- Don't show the includes header or footer -->
466 <xsl:template mode="includes" match="d:referenced-typedef-class/compounddef"/>
467
468
469 <xsl:template mode="section-body" match="memberdef[@kind eq 'enum']">
470 <enum>
471 <xsl:apply-templates select="name"/>
472 </enum>
473 </xsl:template>
474
475 <xsl:template mode="section-body" match="memberdef[@kind eq 'variable']">
476 <variable>
477 <xsl:apply-templates mode="modifier" select="@static[. eq 'yes']"/>
478 <xsl:apply-templates select="type, name"/>
479 <xsl:apply-templates select="initializer[count(../initializer) eq 1]"/>
480 </variable>
481 </xsl:template>
482
483 <xsl:template mode="section-body" match="memberdef[@kind = ('function','friend')]">
484 <function>
485 <xsl:apply-templates mode="normalize-params" select="templateparamlist"/>
486 <xsl:apply-templates mode="modifier" select="@static[. eq 'yes'],
487 @virt [. eq 'virtual']"/>
488 <xsl:apply-templates select="type, name"/>
489 <params>
490 <xsl:apply-templates select="param"/>
491 </params>
492 <xsl:apply-templates mode="modifier" select="@const[. eq 'yes']"/>
493 </function>
494 </xsl:template>
495
496 <!-- Extract <declname> when Doxygen hides it in the <type> -->
497 <xsl:template mode="normalize-params" match="templateparamlist/param/type[not(../declname)]
498 [starts-with(.,'class ') or
499 starts-with(.,'typename ')]"
500 priority="1">
501 <type>{substring-before(.,' ')}</type>
502 <declname>{substring-after(.,' ')}</declname>
503 </xsl:template>
504
505 <!-- Flag as error if no declname value could be found (unless the type is simply "class") -->
506 <xsl:template mode="normalize-params" match="templateparamlist/param/type[not(../declname)]
507 [not(. = 'class')]">
508 <ERROR message="param neither has a declname nor a 'class ' or 'typename ' prefix in the type"/>
509 </xsl:template>
510
511 <xsl:template mode="normalize-params" match="templateparamlist/param/defname"/>
512
513
514 <!-- We only need to keep the @file attribute -->
515 <xsl:template match="location/@*[. except ../@file]"/>
516
517 <xsl:template match="briefdescription | detaileddescription">
518 <div>
519 <xsl:apply-templates/>
520 </div>
521 </xsl:template>
522
523 <xsl:template match="simplesect/title"/>
524
525 <!-- TODO: verify we don't need this; it was causing duplicate headings in simplesect sections
526 <xsl:template match="title">
527 <heading>
528 <xsl:apply-templates/>
529 </heading>
530 </xsl:template>
531 -->
532
533 <!-- By default, don't output an includes header or footer -->
534 <xsl:template mode="includes" match="*"/>
535
536 <!-- TODO: Review; this is meant to effect what the previous code did, but I'm not sure it captures the original intentions -->
537 <xsl:template mode="includes" match="compounddef
538 | memberdef[@kind eq 'friend' or ../../@kind eq 'namespace']
539 [not(/doxygen/@d:page-type eq 'overload-list')]">
540 <xsl:param name="is-footer"/>
541 <para>
542 <xsl:choose>
543 <xsl:when test="$is-footer">
544 <footer>
545 <xsl:apply-templates select="location"/>
546 </footer>
547 </xsl:when>
548 <xsl:otherwise>
549 <xsl:apply-templates select="location"/>
550 </xsl:otherwise>
551 </xsl:choose>
552 </para>
553 </xsl:template>
554
555 <!-- Strip the project namespace prefix from link display names
556 (matching the text node so this will still work with the strip-leading-space mode/process below) -->
557 <!-- TODO: figure out if we need anything like this (maybe not).
558 <xsl:template match="ref/text()[starts-with(.,$doc-ns)]">
559 <xsl:value-of select="d:strip-doc-ns(.)"/>
560 </xsl:template>
561 -->
562
563
564 <!-- When a <para> directly contains a mix of inline nodes and block-level elements, normalize its content -->
565 <xsl:template match="para[&BLOCK_LEVEL_ELEMENT;]">
566 <para>
567 <xsl:for-each-group select="* | text()" group-adjacent="d:is-inline(.)">
568 <xsl:apply-templates mode="capture-ranges" select="."/>
569 </xsl:for-each-group>
570 </para>
571 </xsl:template>
572
573 <xsl:function name="d:is-inline">
574 <xsl:param name="node"/>
575 <xsl:sequence select="not($node/../(&BLOCK_LEVEL_ELEMENT;)[. is $node])"/>
576 </xsl:function>
577
578 <!-- Process the block-level elements as usual -->
579 <xsl:template mode="capture-ranges" match="node()">
580 <xsl:apply-templates select="current-group()"/>
581 </xsl:template>
582
583 <!-- Wrap contiguous ranges of inline children in a nested <para> -->
584 <xsl:template mode="capture-ranges" match="node()[d:is-inline(.)]">
585 <xsl:choose>
586 <!-- But only if it has text or if the group has more than one node -->
587 <xsl:when test="normalize-space(.) or current-group()[2]">
588 <para>
589 <xsl:apply-templates mode="strip-leading-space" select="."/>
590 </para>
591 </xsl:when>
592 <xsl:otherwise>
593 <xsl:next-match/>
594 </xsl:otherwise>
595 </xsl:choose>
596 </xsl:template>
597
598
599 <!-- Strip leading whitespace from the nested paragraphs to prevent eventual interpretation as a code block -->
600 <xsl:template mode="strip-leading-space" match="*">
601 <xsl:copy>
602 <xsl:apply-templates mode="#current" select="@* | node()[1]"/>
603 </xsl:copy>
604 <xsl:apply-templates mode="#current" select="following-sibling::node()[1]
605 [ancestor-or-self::node() intersect current-group()]"/>
606 </xsl:template>
607
608 <xsl:template mode="strip-leading-space" match="@*">
609 <xsl:copy/>
610 </xsl:template>
611
612 <xsl:template mode="strip-leading-space" match="text()">
613 <xsl:param name="done-stripping" tunnel="yes" select="false()"/>
614 <xsl:choose>
615 <xsl:when test="$done-stripping">
616 <xsl:apply-templates select="."/>
617 </xsl:when>
618 <xsl:otherwise>
619 <xsl:sequence select="replace(.,'^\s+','')"/>
620 </xsl:otherwise>
621 </xsl:choose>
622 <xsl:apply-templates mode="#current" select="following-sibling::node()[1]
623 [ancestor-or-self::node() intersect current-group()]">
624 <xsl:with-param name="done-stripping" select="$done-stripping or normalize-space(.)" tunnel="yes"/>
625 </xsl:apply-templates>
626 </xsl:template>
627
628
629 <xsl:template mode="#default normalize-params" match="@* | node()">
630 <xsl:copy copy-namespaces="no">
631 <xsl:apply-templates mode="#current" select="@* | node()"/>
632 </xsl:copy>
633 </xsl:template>
634
635 </xsl:stylesheet>