more compact comments for __version_info__
[docutils.git] / sandbox / xml2rst / xml2rstlib / xml2rst.xsl
blobe262f704679c9abc60867694f6ecc1c5d301d068
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY CR "&#x0A;">
4 <!-- "xml:space='preserve'" is needed for use with libxslt -->
5 <!-- "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'" is needed for
6 use with xsltproc -->
7 <!-- Used to create a blank line -->
8 <!ENTITY tCR "<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xml:space='preserve'>&CR;</xsl:text>">
9 <!-- Used when the line before must be ended -->
10 <!ENTITY tEOL "<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xml:space='preserve'>&CR;</xsl:text>">
11 <!ENTITY tSP "<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xml:space='preserve'> </xsl:text>">
14 <!--
15 Copyright (C) 2005, 2006 Stefan Merten, David Priest
16 Copyright (C) 2009, 2010, 2011 Stefan Merten
18 xml2rst.xsl is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published
20 by the Free Software Foundation; either version 2 of the License,
21 or (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 02111-1307, USA.
32 -->
34 <!-- ********************************************************************** -->
35 <!-- ********************************************************************** -->
37 <!-- These elements in the DTD need support:
39 - ``colspec`` has attribute "stub %yesorno; #IMPLIED"
41 - ``document`` has attribute "title CDATA #IMPLIED"
43 Probably rendered by the `.. title::` directive
45 -->
47 <!--
48 Set namespace extensions. These are used as [shortname]:[tag] throughout the
49 XSL-FO files.
50 xsl: eXtensible Stylesheet Language
51 u: user extensions (indicates utility 'call-template' routines defined in
52 these XSL files)
53 data: Data elements used by the stylesheet
54 -->
55 <xsl:stylesheet
56 version="1.0"
57 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
58 xmlns:u="u"
59 xmlns:data="a"
60 exclude-result-prefixes="data"
61 xmlns:str="http://exslt.org/strings"
62 xmlns:dyn="http://exslt.org/dynamic"
63 xmlns:math="http://exslt.org/math"
64 xmlns:rst="http://www.merten-home.de/xml2rst"
65 extension-element-prefixes="str dyn math rst">
67 <!-- xmlns:regexp="http://exslt.org/regular-expressions" not supported :-( -->
69 <xsl:output
70 method="text"
71 omit-xml-declaration="yes"
72 indent="no"/>
74 <!-- ******************************************************************** -->
75 <!-- ******************************************************************** -->
77 <!-- Parameter to configure title markup; see manual page for description -->
78 <xsl:param
79 name="adornment"
80 select="'o=o-u=u-u~u`u,u.'"/>
82 <!-- Parameter for folding long lines; see manual page for description -->
83 <xsl:param
84 name="fold"
85 select="0"/>
87 <!-- ******************************************************************** -->
88 <!-- ******************************************************************** -->
90 <xsl:variable
91 name="apos"
92 select='"&apos;"'/>
94 <xsl:variable
95 name="structural_elements"
96 select="'*document*section*topic*sidebar*'"/>
98 <xsl:variable
99 name="structural_subelements"
100 select="'*title*subtitle*docinfo*decoration*transition*'"/>
102 <xsl:variable
103 name="bibliographic_elements"
104 select="'*address*author*authors*contact*copyright*date*field*organization*revision*status*version*'"/>
106 <xsl:variable
107 name="decorative_elements"
108 select="'*footer*header*'"/>
110 <xsl:variable
111 name="simple_body_elements_no_substitution"
112 select="'*comment*doctest_block*image*literal_block*paragraph*pending*raw*rubric*target*'"/>
114 <xsl:variable
115 name="folding_elements"
116 select="concat('*comment*paragraph*rubric*attribution*caption*line*', substring-after($bibliographic_elements, '*'))"/>
118 <xsl:variable
119 name="simple_body_elements"
120 select="concat($simple_body_elements_no_substitution, 'substitution_definition*')"/>
122 <xsl:variable
123 name="compound_body_elements"
124 select="'*admonition*attention*block_quote*bullet_list*caution*citation*compound*danger*definition_list*enumerated_list*error*field_list*figure*footnote*hint*important*line_block*note*option_list*system_message*table*tip*warning*container*'"/>
126 <xsl:variable
127 name="body_elements"
128 select="concat($simple_body_elements, substring-after($compound_body_elements, '*'))"/>
130 <xsl:variable
131 name="admonitions"
132 select="'*admonition*attention*caution*danger*error*hint*important*note*tip*warning*'"/>
134 <xsl:variable
135 name="simple_body_subelements"
136 select="'*attribution*caption*classifier*colspec*field_name*label*line*option_argument*option_string*term*'"/>
138 <xsl:variable
139 name="compound_body_subelements"
140 select="'*definition*definition_list_item*description*entry*field*field_body*legend*list_item*option*option_group*option_list_item*row*tbody*tgroup*thead*'"/>
142 <xsl:variable
143 name="inline_elements"
144 select="'*abbreviation*acronym*citation_reference*emphasis*footnote_reference*generated*image*inline*literal*problematic*reference*strong*subscript*substitution_reference*superscript*target*title_reference*raw*'"/>
146 <xsl:variable
147 name="inline_containers"
148 select="concat($simple_body_elements_no_substitution, substring-after($inline_elements, '*'))"/>
150 <xsl:variable
151 name="directives"
152 select="'*admonition*attention*caution*comment*danger*error*footnote*hint*important*note*tip*warning*image*figure*topic*sidebar*rubric*meta*raw*citation*compound*substitution_definition*container*'"/>
154 <xsl:variable
155 name="titled_elements"
156 select="'*sidebar*topic*admonition*'"/>
158 <xsl:variable
159 name="blank_after"
160 select="concat($structural_elements, substring-after($structural_subelements, '*'), substring-after($body_elements, '*'))"/>
162 <xsl:variable
163 name="adornment_characters"
164 select="concat($apos, '!&quot;#$%&amp;()*+,-./:;&lt;=&gt;?@[\]^_`{|}~')"/>
166 <!-- ******************************************************************** -->
167 <!-- ******************************************************************** -->
169 <!--
170 Content Model: ((title, subtitle?)?, docinfo?, decoration?,
171 %structure.model;)
173 Attributes: The document element contains only the common attributes: ids,
174 names, dupnames, source, and classes.
176 Depending on the source of the data and the stage of processing, the
177 "document" may not initially contain a "title". A document title is not
178 directly representable in reStructuredText. Instead, a lone top-level section
179 may have its title promoted to become the document title, and similarly for a
180 lone second-level (sub)section's title to become the document subtitle. The
181 "docinfo" may be transformed from an initial field_list, and "decoration" is
182 usually constructed programmatically.
184 <!-- == structural_element -->
185 <xsl:template
186 match="document">
187 <xsl:if
188 test="//generated[@classes = 'sectnum']">
189 <xsl:text>.. section-numbering::</xsl:text>
190 &tEOL;
191 &tCR;
192 </xsl:if>
193 <xsl:call-template
194 name="u:outputClass">
195 <xsl:with-param
196 name="blankAfter"
197 select="true()"/>
198 </xsl:call-template>
199 <xsl:apply-templates/>
200 </xsl:template>
202 <!-- ******************************************************************** -->
204 <!--
205 Content Model: (title, %structure.model;)
206 Attributes: The section element contains only the common attributes: ids,
207 names, dupnames, source, and classes.
209 <!-- == structural_element -->
210 <xsl:template
211 match="section">
212 <xsl:call-template
213 name="u:outputClass"/>
214 <xsl:call-template
215 name="u:blank"/>
216 <xsl:apply-templates/>
217 </xsl:template>
219 <!-- == structural_element -->
220 <xsl:template
221 match="section[@classes = 'system-messages']"/>
222 <!-- Ignore system messages completely -->
223 <!-- This should be really in `generated' -->
225 <!-- ******************************************************************** -->
227 <!--
228 Content Model: (title, subtitle?, (%body.elements;)+)
229 Attributes: The sidebar element contains only the common attributes: ids,
230 names, dupnames, source, and classes.
232 <!-- == structural_element == directive -->
233 <xsl:template
234 match="sidebar">
235 <xsl:call-template
236 name="u:BandI"/>
237 <xsl:text>.. sidebar:: </xsl:text>
238 <xsl:value-of
239 select="title"/>
240 &tEOL;
241 <xsl:if
242 test="subtitle">
243 <xsl:call-template
244 name="u:param">
245 <xsl:with-param
246 name="name"
247 select="'subtitle'"/>
248 <xsl:with-param
249 name="value"
250 select="subtitle"/>
251 <xsl:with-param
252 name="ancestors"
253 select="ancestor-or-self::*"/>
254 </xsl:call-template>
255 </xsl:if>
256 <xsl:call-template
257 name="u:params"/>
258 <!-- Always blank line after parameter block -->
259 &tCR;
260 <xsl:apply-templates
261 select="*[not(self::title) and not(self::subtitle)]"/>
262 </xsl:template>
264 <!-- ******************************************************************** -->
266 <!--
267 Content Model: (title?, (%body.elements;)+)
268 Attributes: The topic element contains only the common attributes: ids,
269 names, dupnames, source, and classes.
271 <!-- == structural_element == directive -->
272 <xsl:template
273 match="topic">
274 <xsl:call-template
275 name="u:BandI"/>
276 <xsl:text>.. topic:: </xsl:text>
277 <xsl:value-of
278 select="title"/>
279 &tEOL;
280 <xsl:call-template
281 name="u:params"/>
282 <xsl:apply-templates
283 select="*[not(self::title)]"/>
284 </xsl:template>
286 <!-- == structural_element == directive -->
287 <xsl:template
288 match="topic[starts-with(@classes, 'contents')]">
289 <xsl:call-template
290 name="u:BandI"/>
291 <xsl:text>.. contents:: </xsl:text>
292 <xsl:apply-templates
293 select="title"/>
294 &tEOL;
295 <xsl:call-template
296 name="u:params">
297 <xsl:with-param
298 name="params"
299 select="@*[name() != 'ids' and name() != 'names' and name() != 'classes']"/>
300 </xsl:call-template>
301 <xsl:variable
302 name="isLocal"
303 select="substring-before(@classes, ' local')"/>
304 <xsl:variable
305 name="realClassesLocal"
306 select="normalize-space(substring-after(@classes, 'contents'))"/>
307 <xsl:variable
308 name="realClassesNode">
309 <xsl:choose>
310 <xsl:when
311 test="$isLocal">
312 <xsl:value-of
313 select="normalize-space(substring-before($realClassesLocal, 'local'))"/>
314 </xsl:when>
315 <xsl:otherwise>
316 <xsl:value-of
317 select="$realClassesLocal"/>
318 </xsl:otherwise>
319 </xsl:choose>
320 </xsl:variable>
321 <xsl:variable
322 name="realClasses"
323 select="string($realClassesNode)"/>
324 <xsl:if
325 test="$isLocal">
326 <xsl:call-template
327 name="u:param">
328 <xsl:with-param
329 name="name"
330 select="'local'"/>
331 <xsl:with-param
332 name="value"
333 select="''"/>
334 <xsl:with-param
335 name="ancestors"
336 select="ancestor-or-self::*"/>
337 </xsl:call-template>
338 </xsl:if>
339 <xsl:if
340 test="$realClasses">
341 <xsl:call-template
342 name="u:param">
343 <xsl:with-param
344 name="name"
345 select="'class'"/>
346 <xsl:with-param
347 name="value"
348 select="$realClasses"/>
349 <xsl:with-param
350 name="ancestors"
351 select="ancestor-or-self::*"/>
352 </xsl:call-template>
353 </xsl:if>
354 <!-- Autogenerated content is discarded -->
355 &tCR;
356 </xsl:template>
358 <!-- == structural_element == directive -->
359 <xsl:template
360 match="topic[@classes='dedication' or @classes='abstract']">
361 <xsl:call-template
362 name="u:BandI"/>
363 <xsl:text>:</xsl:text>
364 <xsl:apply-templates
365 select="title"/>
366 <xsl:text>: </xsl:text>
367 &tEOL;
368 <xsl:apply-templates
369 select="*[not(self::title)]"/>
370 </xsl:template>
372 <!-- ******************************************************************** -->
374 <!--
375 Content Model: (title, (%body.elements;)+)
376 Attributes: The admonition element contains only the common attributes:
377 ids, names, dupnames, source, and classes.
379 <!-- == compound_body_element == directive -->
380 <xsl:template
381 match="admonition">
382 <xsl:call-template
383 name="u:BandI"/>
384 <xsl:text>.. admonition:: </xsl:text>
385 <xsl:apply-templates
386 select="title"/>
387 &tEOL;
388 <xsl:call-template
389 name="u:params">
390 <xsl:with-param
391 name="params"
392 select="@*[name() != 'classes' or not(starts-with(., 'admonition-'))]"/>
393 </xsl:call-template>
394 <xsl:call-template
395 name="u:indent"/>
396 <xsl:apply-templates
397 select="*[not(self::title)]"/>
398 </xsl:template>
400 <!-- ******************************************************************** -->
402 <!--
403 Content Model: (%body.elements;)+
404 Attributes: The note element contains only the common attributes: ids,
405 names, dupnames, source, and classes.
407 <!-- == compound_body_element == directive -->
408 <xsl:template
409 match="attention | caution | danger | error | hint | important | note | tip | warning">
410 <xsl:call-template
411 name="u:outputClass"/>
412 <xsl:call-template
413 name="u:BandI"/>
414 <xsl:text>.. </xsl:text>
415 <xsl:value-of
416 select="name()"/>
417 <xsl:text>:: </xsl:text>
418 <xsl:call-template
419 name="u:params">
420 <xsl:with-param
421 name="params"
422 select="@*[name() != 'classes']"/>
423 </xsl:call-template>
424 <xsl:apply-templates/>
425 </xsl:template>
427 <!-- ******************************************************************** -->
429 <!--
430 Content Model: (header?, footer?)
431 Attributes: The decoration element contains only the common attributes:
432 ids, names, dupnames, source, and classes.
434 Although the content model doesn't specifically require contents, no empty
435 decoration elements are ever created.
437 <!-- == structural_subelement -->
438 <xsl:template
439 match="//document/decoration">
440 <xsl:apply-templates/>
441 </xsl:template>
443 <!-- TODO To be rendered as `.. header::` directive -->
444 <!-- == decorative_element -->
445 <xsl:template
446 match="//document/decoration/header">
447 <xsl:apply-templates/>
448 </xsl:template>
450 <!-- TODO To be rendered as `.. footer::` directive -->
451 <!-- == decorative_element -->
452 <xsl:template
453 match="//document/decoration/footer">
454 <xsl:apply-templates/>
455 </xsl:template>
457 <!-- ******************************************************************** -->
459 <!--
460 Content Model: (%bibliographic.elements;)+
461 Attributes: The docinfo element contains only the common attributes: ids,
462 names, dupnames, source, and classes.
464 <!-- == structural_subelement -->
465 <xsl:template
466 match="docinfo">
467 <xsl:call-template
468 name="u:outputClass"/>
469 <xsl:call-template
470 name="u:blank"/>
471 <xsl:apply-templates/>
472 <xsl:call-template
473 name="u:blank"/>
474 </xsl:template>
476 <!-- ******************************************************************** -->
478 <!--
479 Content Model: ((author, organization?, address?, contact?)+)
480 Attributes: The authors element contains only the common attributes: ids,
481 names, dupnames, source, and classes.
483 In reStructuredText, multiple author's names are separated with semicolons
484 (";") or commas (","); semicolons take precedence. There is currently no way
485 to represent the author's organization, address, or contact in a
486 reStructuredText "Authors" field.
488 <!-- == bibliographic_element == folding_element -->
489 <xsl:template
490 match="docinfo/authors">
491 <xsl:call-template
492 name="u:outputFolding">
493 <xsl:with-param
494 name="prefix">
495 <xsl:text>:</xsl:text>
496 <xsl:value-of
497 select="name()"/>
498 <xsl:text>: </xsl:text>
499 </xsl:with-param>
500 </xsl:call-template>
501 </xsl:template>
503 <!--
504 Content Model: %text.model;
505 Attributes: All docinfo elements contains the common attributes (ids,
506 names, dupnames, source, and classes)
507 Some docinfo elements also have xml:space.
509 <xsl:template
510 match="docinfo/authors/*">
511 <xsl:apply-templates/>
512 <!-- no semicolon after final author -->
513 <xsl:if
514 test="generate-id(current()) != generate-id(../*[last()])">
515 <xsl:text>; </xsl:text>
516 </xsl:if>
517 </xsl:template>
519 <!--
520 Content Model: (field_name, field_body)
521 Attributes: The field element contains only the common attributes: ids,
522 names, dupnames, source, and classes.
524 <!-- == bibliographic_element -->
525 <xsl:template
526 match="docinfo/field">
527 <!-- contents handled by ordinary field lists -->
528 <xsl:apply-templates/>
529 <!-- Supply an EOL because following elements do not recognize this -->
530 &tEOL;
531 </xsl:template>
533 <!--
534 Content Model: %text.model;
535 Attributes: All docinfo elements contains the common attributes (ids,
536 names, dupnames, source, and classes)
537 Some docinfo elements also have xml:space.
539 <!-- == bibliographic_element == folding_element -->
540 <xsl:template
541 match="docinfo/*[name()!='authors' and name()!='field']">
542 <xsl:call-template
543 name="u:outputFolding">
544 <xsl:with-param
545 name="prefix">
546 <xsl:text>:</xsl:text>
547 <xsl:value-of
548 select="name()"/>
549 <xsl:text>: </xsl:text>
550 </xsl:with-param>
551 </xsl:call-template>
552 </xsl:template>
554 <!-- ******************************************************************** -->
556 <!--
557 Content Model: EMPTY
558 Attributes: The transition element contains only the common attributes:
559 ids, names, dupnames, source, and classes.
561 <!-- == structural_subelement -->
562 <xsl:template
563 match="transition">
564 <xsl:call-template
565 name="u:outputClass"/>
566 &tCR; <!-- req: blank line before -->
567 <xsl:text>-----</xsl:text>
568 &tEOL;
569 <!-- Add a required blank line after unless class follows immediately -->
570 <xsl:if
571 test="not(following-sibling::*[1]/@classes)">
572 &tCR;
573 </xsl:if>
574 </xsl:template>
576 <!-- ******************************************************************** -->
577 <!-- ******************************************************************** -->
579 <!--
580 IFF there is a /document/title element, it is the publication's title. All
581 other titles will appear within sections.
583 Content Model: %text.model;
584 Attributes: The title element contains the common attributes (ids, names,
585 dupnames, source, and classes), plus refid and auto.
586 refid is used as a backlink to a table of contents entry.
587 auto is used to indicate (with value "1") that the title has been
588 numbered automatically.
590 <!-- == structural_subelement -->
591 <xsl:template
592 match="//document/title">
593 <xsl:call-template
594 name="u:outputClass"/>
595 <xsl:variable
596 name="textWS">
597 <!-- Catch the title text as it is rendered so its length can be
598 determined -->
599 <xsl:apply-templates/>
600 </xsl:variable>
601 <xsl:variable
602 name="text"
603 select="normalize-space($textWS)"/>
604 <xsl:variable
605 name="length"
606 select="string-length($text)"/>
607 <xsl:call-template
608 name="u:overline">
609 <xsl:with-param
610 name="length"
611 select="$length"/>
612 <xsl:with-param
613 name="depth"
614 select="1"/>
615 </xsl:call-template>
616 <xsl:value-of
617 select="$text"/>
618 &tEOL;
619 <xsl:call-template
620 name="u:underline">
621 <xsl:with-param
622 name="length"
623 select="$length"/>
624 <xsl:with-param
625 name="depth"
626 select="1"/>
627 </xsl:call-template>
628 </xsl:template>
630 <!-- ******************************************************************** -->
632 <!--
633 Title Underlines are defined by their position within the tree.
635 Content Model: %text.model;
636 Attributes: The title element contains the common attributes (ids, names,
637 dupnames, source, and classes), plus refid and auto.
638 refid is used as a backlink to a table of contents entry.
639 auto is used to indicate (with value "1") that the title has been
640 numbered automatically.
642 <!-- == structural_subelement -->
643 <xsl:template
644 match="section/title">
645 <xsl:call-template
646 name="u:outputClass"/>
647 <xsl:variable
648 name="textWS">
649 <!-- catch the title text as it is rendered -->
650 <xsl:apply-templates/>
651 </xsl:variable>
652 <xsl:variable
653 name="text"
654 select="normalize-space($textWS)"/>
655 <xsl:variable
656 name="length"
657 select="string-length($text)"/>
658 <xsl:variable
659 name="depth"
660 select="count(ancestor::section)"/>
661 <xsl:call-template
662 name="u:overline">
663 <xsl:with-param
664 name="length"
665 select="$length"/>
666 <xsl:with-param
667 name="depth"
668 select="$depth + 2"/>
669 </xsl:call-template>
670 <xsl:value-of
671 select="$text"/>
672 &tEOL;
673 <xsl:call-template
674 name="u:underline">
675 <xsl:with-param
676 name="length"
677 select="$length"/>
678 <xsl:with-param
679 name="depth"
680 select="$depth + 2"/>
681 </xsl:call-template>
682 <!-- Add a blank line after unless structure follows immediately -->
683 <xsl:if
684 test="not(contains(concat($structural_elements, $compound_body_elements), concat('*', name(following-sibling::*[1]), '*')) or following-sibling::*[1]/@classes)">
685 &tCR;
686 </xsl:if>
687 </xsl:template>
689 <!-- ******************************************************************** -->
691 <!--
692 Content Model: %text.model;
693 Attributes: The title element contains the common attributes (ids, names,
694 dupnames, source, and classes), plus refid and auto.
695 refid is used as a backlink to a table of contents entry.
696 auto is used to indicate (with value "1") that the title has been
697 numbered automatically.
699 <!-- == structural_subelement -->
700 <xsl:template
701 match="title">
702 <xsl:call-template
703 name="u:outputClass">
704 <xsl:with-param
705 name="alreadyBlanked"
706 select="true()"/>
707 </xsl:call-template>
708 <!-- blank line provided by parent -->
709 <xsl:apply-templates/>
710 <!-- no EOL: provided by parent -->
711 </xsl:template>
713 <!-- ******************************************************************** -->
715 <!--
716 IFF there is a /document/title element, it is the publication's title. All
717 other titles will appear within sections.
719 Content Model: %text.model;
720 Attributes: The subtitle element contains only the common attributes:
721 ids, names, dupnames, source, and classes.
723 <!-- == structural_subelement -->
724 <xsl:template
725 match="//document/subtitle">
726 <xsl:call-template
727 name="u:outputClass"/>
728 <xsl:variable
729 name="textWS">
730 <!-- Catch the title text as it is rendered -->
731 <xsl:apply-templates/>
732 </xsl:variable>
733 <xsl:variable
734 name="text"
735 select="normalize-space($textWS)"/>
736 <xsl:variable
737 name="length"
738 select="string-length($text)"/>
740 <!-- always a blank line above -->
741 &tCR;
742 <xsl:call-template
743 name="u:overline">
744 <xsl:with-param
745 name="length"
746 select="$length"/>
747 <xsl:with-param
748 name="depth"
749 select="2"/>
750 </xsl:call-template>
751 <xsl:value-of
752 select="$text"/>
753 &tEOL;
754 <xsl:call-template
755 name="u:underline">
756 <xsl:with-param
757 name="length"
758 select="$length"/>
759 <xsl:with-param
760 name="depth"
761 select="2"/>
762 </xsl:call-template>
763 </xsl:template>
765 <!-- ******************************************************************** -->
767 <!--
768 Content Model: %text.model;
769 Attributes: The subtitle element contains only the common attributes: ids,
770 names, dupnames, source, and classes.
772 <!-- == structural_subelement -->
773 <xsl:template
774 match="sidebar/subtitle">
775 <xsl:call-template
776 name="u:outputClass"/>
777 <xsl:call-template
778 name="u:indent"/>
779 <xsl:apply-templates/>
780 &tEOL;
781 &tCR;
782 </xsl:template>
784 <!-- ******************************************************************** -->
785 <!-- ******************************************************************** -->
787 <!--
788 Content Model: %text.model;
789 Attributes: The comment element contains only the common attributes: ids,
790 names, dupnames, source, and classes.
792 <!-- == simple_body_element == folding_element == directive -->
793 <xsl:template
794 match="comment">
795 <xsl:call-template
796 name="u:BandI"/>
797 <xsl:call-template
798 name="u:outputFolding">
799 <xsl:with-param
800 name="prefix">
801 <xsl:text>.. </xsl:text>
802 </xsl:with-param>
803 </xsl:call-template>
804 </xsl:template>
806 <!-- ******************************************************************** -->
808 <!--
809 Content Model: %text.model;
810 Attributes: The doctest_block element contains the common attributes (ids,
811 names, dupnames, source, and classes), plus xml:space.
813 <!-- == simple_body_element -->
814 <xsl:template
815 match="doctest_block">
816 <xsl:call-template
817 name="u:outputClass"/>
818 <xsl:call-template
819 name="u:BandI"/>
820 <xsl:apply-templates/>
821 &tEOL;
822 </xsl:template>
824 <!-- ******************************************************************** -->
826 <!-- An image element can have various roles; they are all covered here -->
827 <!-- == simple_body_element == inline_element == directive -->
828 <xsl:template
829 match="image">
830 <xsl:choose>
831 <xsl:when
832 test="contains($inline_containers, concat('*', name(..), '*')) and @alt">
833 <!-- An inline image with an `@alt' - must be a substitution
834 reference -->
835 <xsl:text>|</xsl:text>
836 <!-- Original text is lost - use what we have -->
837 <xsl:value-of
838 select="@alt"/>
839 <xsl:text>|</xsl:text>
840 </xsl:when>
841 <xsl:otherwise>
842 <!-- A directive -->
843 <xsl:if
844 test="not(parent::figure)">
845 <xsl:if
846 test="not(parent::substitution_definition)">
847 <xsl:call-template
848 name="u:BandI"/>
849 <xsl:text>.. </xsl:text>
850 </xsl:if>
851 <xsl:text>image:: </xsl:text>
852 </xsl:if>
853 <xsl:value-of
854 select="@uri"/>
855 &tEOL;
856 <xsl:choose>
857 <xsl:when
858 test="parent::figure">
859 <!-- `@classes' is special because it is in the parent -->
860 <xsl:if
861 test="../@classes">
862 <xsl:call-template
863 name="u:param">
864 <xsl:with-param
865 name="name"
866 select="'figclass'"/>
867 <xsl:with-param
868 name="value"
869 select="../@classes"/>
870 <xsl:with-param
871 name="ancestors"
872 select="ancestor::*"/>
873 </xsl:call-template>
874 </xsl:if>
875 <!-- `@align' is special because it is in the parent -->
876 <xsl:if
877 test="../@align">
878 <xsl:call-template
879 name="u:param">
880 <xsl:with-param
881 name="name"
882 select="'align'"/>
883 <xsl:with-param
884 name="value"
885 select="../@align"/>
886 <xsl:with-param
887 name="ancestors"
888 select="ancestor::*"/>
889 </xsl:call-template>
890 </xsl:if>
891 <xsl:call-template
892 name="u:params">
893 <!-- `figure' would add one level of indentation -->
894 <xsl:with-param
895 name="ancestors"
896 select="ancestor::*"/>
897 </xsl:call-template>
898 </xsl:when>
899 <xsl:when
900 test="parent::substitution_definition">
901 <xsl:call-template
902 name="u:params">
903 <!-- `@alt' only for the real images -->
904 <xsl:with-param
905 name="params"
906 select="@*[name() != 'alt']"/>
907 </xsl:call-template>
908 </xsl:when>
909 <xsl:otherwise>
910 <xsl:call-template
911 name="u:params">
912 <xsl:with-param
913 name="params"
914 select="@*[name() != 'ids' and name() != 'names']"/>
915 </xsl:call-template>
916 </xsl:otherwise>
917 </xsl:choose>
918 <xsl:if
919 test="parent::reference">
920 <!-- A clickable image -->
921 <xsl:call-template
922 name="u:param">
923 <xsl:with-param
924 name="name"
925 select="'target'"/>
926 <xsl:with-param
927 name="value">
928 <xsl:choose>
929 <xsl:when
930 test="../@name">
931 <!-- An internal link -->
932 <xsl:call-template
933 name="u:inlineReference">
934 <xsl:with-param
935 name="text"
936 select="../@refid"/>
937 </xsl:call-template>
938 </xsl:when>
939 <xsl:otherwise>
940 <!-- An external link -->
941 <xsl:value-of
942 select="../@refuri"/>
943 </xsl:otherwise>
944 </xsl:choose>
945 </xsl:with-param>
946 <xsl:with-param
947 name="ancestors"
948 select="ancestor-or-self::*"/>
949 </xsl:call-template>
950 </xsl:if>
951 <!-- Always blank line after parameter block -->
952 &tCR;
953 </xsl:otherwise>
954 </xsl:choose>
955 </xsl:template>
957 <!-- ******************************************************************** -->
959 <!--
960 Content Model: (line_block | line)+
961 Attributes: The line_block element contains the common attributes (ids,
962 names, dupnames, source, and classes), plus xml:space.
964 <!-- == compound_body_element -->
965 <xsl:template
966 match="line_block">
967 <xsl:call-template
968 name="u:outputClass"/>
969 <xsl:variable
970 name="isEmbedded"
971 select="name(..) = 'line_block'"/>
972 <xsl:if
973 test="not($isEmbedded)">
974 <xsl:call-template
975 name="u:blank"/>
976 </xsl:if>
977 <xsl:apply-templates/>
978 </xsl:template>
980 <!-- ******************************************************************** -->
982 <!--
983 Content Model: %text.model;
984 Attributes: The line element contains the common attributes (ids,
985 names, dupnames, source, and classes).
987 <!-- == simple_body_subelement == folding_element -->
988 <xsl:template
989 match="line">
990 <xsl:call-template
991 name="u:outputClass"/>
992 <xsl:variable
993 name="indent">
994 <xsl:call-template
995 name="u:indent"/>
996 </xsl:variable>
997 <xsl:value-of
998 select="$indent"/>
999 <xsl:choose>
1000 <xsl:when
1001 test="node()">
1002 <!-- Only for non-empty lines -->
1003 <xsl:variable
1004 name="lineBlockIndent">
1005 <!-- Very special indendation for nested `line_block's -->
1006 <xsl:for-each
1007 select="ancestor::line_block[position() > 1]">
1008 <xsl:value-of
1009 select="str:padding(4)"/>
1010 </xsl:for-each>
1011 </xsl:variable>
1012 <xsl:call-template
1013 name="u:outputFolding">
1014 <xsl:with-param
1015 name="prefix">
1016 <xsl:text>| </xsl:text>
1017 <xsl:value-of
1018 select="$lineBlockIndent"/>
1019 </xsl:with-param>
1020 <xsl:with-param
1021 name="indent"
1022 select="concat($indent, ' ', $lineBlockIndent)"/>
1023 </xsl:call-template>
1024 </xsl:when>
1025 <xsl:otherwise>
1026 <xsl:text>|</xsl:text>
1027 &tEOL;
1028 </xsl:otherwise>
1029 </xsl:choose>
1030 </xsl:template>
1032 <!-- ******************************************************************** -->
1034 <!--
1035 Content Model: %text.model;
1036 Attributes: The literal_block element contains the common attributes (ids,
1037 names, dupnames, source, and classes), plus xml:space.
1039 <!-- == simple_body_element == directive -->
1040 <xsl:template
1041 match="literal_block">
1042 <!-- If it contains inline elements this is a parsed-literal -->
1043 <xsl:variable
1044 name="isParsedLiteral"
1045 select=".//*[contains($inline_elements, concat('*', name(), '*'))]"/>
1046 <xsl:choose>
1047 <xsl:when
1048 test="$isParsedLiteral">
1049 <xsl:call-template
1050 name="u:BandI"/>
1051 <xsl:text>.. parsed-literal::</xsl:text>
1052 &tEOL;
1053 <xsl:call-template
1054 name="u:params"/>
1055 &tCR;
1056 </xsl:when>
1057 <xsl:otherwise>
1058 <xsl:call-template
1059 name="u:outputClass"/>
1060 <!-- TODO Support for the (fully) minimized style would be nice but
1061 is difficult to accomplish because there is a linefeed
1062 already when we arrive here :-( -->
1063 <xsl:call-template
1064 name="u:BandI"/>
1065 <xsl:text>::</xsl:text>
1066 &tEOL;
1067 &tCR;
1068 </xsl:otherwise>
1069 </xsl:choose>
1070 <xsl:variable
1071 name="isQuotedLiteral">
1072 <xsl:call-template
1073 name="u:isQuotedLiteral"/>
1074 </xsl:variable>
1075 <!-- Indent correctly depending on quoted literal or not -->
1076 <xsl:choose>
1077 <xsl:when
1078 test="string-length($isQuotedLiteral)">
1079 <xsl:call-template
1080 name="u:indent">
1081 <xsl:with-param
1082 name="ancestors"
1083 select="ancestor::*"/>
1084 </xsl:call-template>
1085 <xsl:apply-templates
1086 mode="quotedLiteral"/>
1087 </xsl:when>
1088 <xsl:otherwise>
1089 <xsl:call-template
1090 name="u:indent">
1091 <xsl:with-param
1092 name="ancestors"
1093 select="ancestor-or-self::*"/>
1094 </xsl:call-template>
1095 <xsl:choose>
1096 <xsl:when
1097 test="$isParsedLiteral">
1098 <xsl:apply-templates/>
1099 </xsl:when>
1100 <xsl:otherwise>
1101 <xsl:apply-templates
1102 mode="inLiteral"/>
1103 </xsl:otherwise>
1104 </xsl:choose>
1105 </xsl:otherwise>
1106 </xsl:choose>
1107 &tEOL;
1108 </xsl:template>
1110 <!-- Indent a text of a quoted literal containing line feeds correctly -->
1111 <xsl:template
1112 match="text()"
1113 mode="quotedLiteral">
1114 <xsl:call-template
1115 name="u:indentLF">
1116 <xsl:with-param
1117 name="indent">
1118 <xsl:call-template
1119 name="u:indent">
1120 <xsl:with-param
1121 name="ancestors"
1122 select="ancestor::*[position() > 1]"/>
1123 </xsl:call-template>
1124 </xsl:with-param>
1125 <xsl:with-param
1126 name="literal"
1127 select="true()"/>
1128 </xsl:call-template>
1129 </xsl:template>
1131 <!-- Determine whether `$text' is a quoted literal and return the quote
1132 character if so -->
1133 <xsl:template
1134 name="u:isQuotedLiteral">
1135 <xsl:param
1136 name="text"
1137 select="text()"/>
1138 <xsl:param
1139 name="quote"
1140 select="substring($text, 1, 1)"/>
1141 <xsl:if
1142 test="contains($adornment_characters, $quote) and substring($text, 1, 1) = $quote">
1143 <!-- Given quote is an adornment character and first character is this
1144 quote -->
1145 <xsl:choose>
1146 <xsl:when
1147 test="contains($text, '&#xA;')">
1148 <!-- Test the remaining lines -->
1149 <xsl:call-template
1150 name="u:isQuotedLiteral">
1151 <xsl:with-param
1152 name="text"
1153 select="substring-after($text, '&#xA;')"/>
1154 <xsl:with-param
1155 name="quote"
1156 select="$quote"/>
1157 </xsl:call-template>
1158 </xsl:when>
1159 <xsl:otherwise>
1160 <!-- No more lines to test so this is a quoted literal -->
1161 <xsl:value-of
1162 select="$quote"/>
1163 </xsl:otherwise>
1164 </xsl:choose>
1165 </xsl:if>
1166 </xsl:template>
1168 <!-- ******************************************************************** -->
1170 <!--
1171 Content Model: %text.model;
1172 Attributes: The paragraph element contains only the common attributes:
1173 ids, names, dupnames, source, and classes.
1175 <!-- == simple_body_element == folding_element -->
1176 <xsl:template
1177 match="paragraph">
1178 <xsl:variable
1179 name="previous"
1180 select="preceding-sibling::*[1]"/>
1181 <!-- Do indent except first element in some compound elements -->
1182 <xsl:variable
1183 name="needsIndent"
1184 select="($previous or not(parent::list_item or parent::field_body or contains($admonitions, concat('*', name(..), '*')))) and name($previous) != 'label'"/>
1185 <!-- Blank line in front if following a body element, except first
1186 elements in some compound elements -->
1187 <xsl:variable
1188 name="needsBlank"
1189 select="($previous or not(parent::list_item or ../parent::option_list_item or parent::field_body or parent::document or contains($admonitions, concat('*', name(..), '*')))) and (not($previous) or contains($body_elements, concat('*', name($previous), '*')) or name($previous) = 'title' and contains($titled_elements, concat('*', name(..), '*')) or name($previous) = 'docinfo')"/>
1190 <xsl:if
1191 test="$needsBlank">
1192 &tCR;
1193 </xsl:if>
1194 <xsl:if
1195 test="$needsIndent">
1196 <xsl:call-template
1197 name="u:indent"/>
1198 </xsl:if>
1199 <xsl:if
1200 test="@classes">
1201 <!-- This paragraph has a classes attribute - always needs newline and
1202 indent -->
1203 <xsl:call-template
1204 name="u:outputClass">
1205 <xsl:with-param
1206 name="alreadyBlanked"
1207 select="$needsBlank"/>
1208 <xsl:with-param
1209 name="alreadyIndented"
1210 select="$needsIndent"/>
1211 </xsl:call-template>
1212 <xsl:call-template
1213 name="u:BandI"/>
1214 </xsl:if>
1215 <xsl:call-template
1216 name="u:outputFolding"/>
1217 </xsl:template>
1219 <!-- ******************************************************************** -->
1221 <!-- == simple_body_element -->
1222 <xsl:template
1223 match="pending">
1224 <xsl:call-template
1225 name="u:notSupported"/>
1226 </xsl:template>
1228 <!-- ******************************************************************** -->
1230 <!-- == simple_body_element == inline_element == directive -->
1231 <xsl:template
1232 match="raw">
1233 <xsl:choose>
1234 <xsl:when
1235 test="contains($inline_containers, concat('*', name(..), '*'))">
1236 <!-- Used as a custom role -->
1237 <!-- TODO `role' directives must be generated for user-defined raw
1238 roles. -->
1239 <!-- The name of the custom role is not contained in the input -->
1240 <xsl:text>:RAW-ROLE:`</xsl:text>
1241 <xsl:apply-templates/>
1242 <xsl:text>`</xsl:text>
1243 </xsl:when>
1244 <xsl:otherwise>
1245 <!-- A directive -->
1246 <xsl:call-template
1247 name="u:outputClass"/>
1248 <xsl:call-template
1249 name="u:BandI"/>
1250 <xsl:text>.. raw:: </xsl:text>
1251 <xsl:value-of
1252 select="@format"/>
1253 &tEOL;
1254 <xsl:call-template
1255 name="u:params">
1256 <xsl:with-param
1257 name="params"
1258 select="@*[name() != 'format' and name() != 'classes']"/>
1259 </xsl:call-template>
1260 &tCR;
1261 <xsl:call-template
1262 name="u:indent">
1263 <xsl:with-param
1264 name="ancestors"
1265 select="ancestor-or-self::*"/>
1266 </xsl:call-template>
1267 <xsl:apply-templates
1268 mode="inLiteral"/>
1269 &tEOL;
1270 </xsl:otherwise>
1271 </xsl:choose>
1272 </xsl:template>
1274 <!-- ******************************************************************** -->
1276 <!-- == simple_body_element == folding_element == directive -->
1277 <xsl:template
1278 match="rubric">
1279 <xsl:call-template
1280 name="u:BandI"/>
1281 <xsl:call-template
1282 name="u:outputFolding">
1283 <xsl:with-param
1284 name="prefix">
1285 <xsl:text>.. rubric:: </xsl:text>
1286 </xsl:with-param>
1287 </xsl:call-template>
1288 <xsl:call-template
1289 name="u:params"/>
1290 </xsl:template>
1292 <!-- ******************************************************************** -->
1294 <!-- == compound_body_element == directive -->
1295 <xsl:template
1296 match="compound">
1297 <xsl:call-template
1298 name="u:BandI"/>
1299 <xsl:text>.. compound::</xsl:text>
1300 &tEOL;
1301 <xsl:call-template
1302 name="u:params"/>
1303 <xsl:apply-templates/>
1304 </xsl:template>
1306 <!-- ******************************************************************** -->
1308 <!-- == compound_body_element == directive -->
1309 <xsl:template
1310 match="container">
1311 <xsl:call-template
1312 name="u:BandI"/>
1313 <xsl:text>.. container::</xsl:text>
1314 <xsl:if
1315 test="@classes">
1316 &tSP;
1317 <xsl:value-of
1318 select="@classes"/>
1319 </xsl:if>
1320 &tEOL;
1321 <xsl:apply-templates/>
1322 </xsl:template>
1324 <!-- ******************************************************************** -->
1326 <!-- == simple_body_element == directive -->
1327 <xsl:template
1328 match="substitution_definition">
1329 <!-- More than one child or not a directive is a replacement text -->
1330 <xsl:variable
1331 name="isReplace"
1332 select="not(* and count(node()) = 1 and contains($directives, concat('*', name(*[1]), '*')))"/>
1333 <xsl:call-template
1334 name="u:BandI"/>
1335 <xsl:variable
1336 name="prefix">
1337 <xsl:text>.. |</xsl:text>
1338 <xsl:call-template
1339 name="u:outputNames"/>
1340 <xsl:text>| </xsl:text>
1341 </xsl:variable>
1342 <xsl:choose>
1343 <xsl:when
1344 test="$isReplace">
1345 <!-- TODO Substitution references for replace can not be found because
1346 they are not marked as such; embedding them in `generated'
1347 would be nice -->
1348 <xsl:call-template
1349 name="u:outputFolding">
1350 <xsl:with-param
1351 name="prefix">
1352 <xsl:value-of
1353 select="$prefix"/>
1354 <xsl:text>replace:: </xsl:text>
1355 </xsl:with-param>
1356 </xsl:call-template>
1357 </xsl:when>
1358 <xsl:otherwise>
1359 <xsl:value-of
1360 select="$prefix"/>
1361 <xsl:apply-templates/>
1362 </xsl:otherwise>
1363 </xsl:choose>
1364 </xsl:template>
1366 <!-- ******************************************************************** -->
1368 <!--
1369 Content Model: ((%body.elements;)+, attribution?)
1370 Attributes: The block_quote element contains only the common attributes:
1371 ids, names, dupnames, source, and classes.
1373 <!-- == compound_body_element -->
1374 <xsl:template
1375 match="block_quote">
1376 <xsl:if
1377 test="@classes = 'epigraph' or @classes = 'highlights' or @classes = 'pull-quote'">
1378 <xsl:call-template
1379 name="u:BandI"/>
1380 <xsl:text>.. </xsl:text>
1381 <xsl:value-of
1382 select="@classes"/>
1383 <xsl:text>::</xsl:text>
1384 &tEOL;
1385 <xsl:call-template
1386 name="u:params"/>
1387 </xsl:if>
1388 <xsl:apply-templates/>
1389 </xsl:template>
1391 <!-- ******************************************************************** -->
1393 <!-- == simple_body_subelement == folding_element -->
1394 <xsl:template
1395 match="attribution">
1396 <xsl:call-template
1397 name="u:outputClass"/>
1398 <!-- blank line between quote and attribution -->
1399 &tCR;
1400 <xsl:call-template
1401 name="u:indent"/>
1402 <xsl:call-template
1403 name="u:outputFolding">
1404 <xsl:with-param
1405 name="prefix">
1406 <xsl:text>-- </xsl:text>
1407 </xsl:with-param>
1408 </xsl:call-template>
1409 </xsl:template>
1411 <!-- ******************************************************************** -->
1413 <!-- == compound_body_element == directive -->
1414 <xsl:template
1415 match="citation">
1416 <xsl:call-template
1417 name="u:outputClass"/>
1418 <xsl:call-template
1419 name="u:BandI"/>
1420 <xsl:text>.. [</xsl:text>
1421 <xsl:value-of
1422 select="label"/>
1423 <xsl:text>] </xsl:text>
1424 <xsl:apply-templates
1425 select="*[not(self::label)]"/>
1426 </xsl:template>
1428 <!-- == simple_body_subelement -->
1429 <xsl:template
1430 match="citation/label">
1431 <xsl:apply-templates/>
1432 </xsl:template>
1434 <!-- ******************************************************************** -->
1436 <!-- == compound_body_element == directive -->
1437 <xsl:template
1438 match="figure">
1439 <xsl:call-template
1440 name="u:BandI"/>
1441 <xsl:text>.. figure:: </xsl:text>
1442 <xsl:apply-templates/>
1443 </xsl:template>
1445 <!-- ******************************************************************** -->
1447 <!-- == simple_body_subelement == folding_element -->
1448 <xsl:template
1449 match="caption">
1450 <xsl:call-template
1451 name="u:indent"/>
1452 <xsl:call-template
1453 name="u:outputFolding"/>
1454 </xsl:template>
1456 <!-- ******************************************************************** -->
1458 <!-- == compound_body_subelement -->
1459 <xsl:template
1460 match="legend">
1461 <xsl:apply-templates/>
1462 </xsl:template>
1464 <!-- ******************************************************************** -->
1466 <!-- TODO Footnotes should continue on line of definition -->
1468 <!-- user-numbered footnotes lack @auto -->
1469 <!-- == compound_body_element == directive -->
1470 <xsl:template
1471 match="footnote[not(@auto)]">
1472 <xsl:call-template
1473 name="u:outputClass"/>
1474 <xsl:call-template
1475 name="u:BandI"/>
1476 <xsl:text>.. [</xsl:text>
1477 <xsl:apply-templates
1478 select="label"/>
1479 <xsl:text>] </xsl:text>
1480 <xsl:apply-templates
1481 select="*[not(self::label)]"/>
1482 </xsl:template>
1484 <!-- autonumbered footnotes have @auto -->
1485 <!-- if the target footnote_reference@names matches its label, it was not a
1486 numbered-name footnote -->
1487 <!-- == compound_body_element == directive -->
1488 <xsl:template
1489 match="footnote[@auto='1']">
1490 <xsl:call-template
1491 name="u:outputClass"/>
1492 <xsl:call-template
1493 name="u:BandI"/>
1494 <xsl:text>.. [#</xsl:text>
1495 <xsl:if
1496 test="@names = @ids">
1497 <xsl:call-template
1498 name="u:outputNames"/>
1499 </xsl:if>
1500 <xsl:text>] </xsl:text>
1501 <xsl:apply-templates
1502 select="*[not(self::label)]"/>
1503 </xsl:template>
1505 <!-- autosymboled footnotes have @auto -->
1506 <!-- == compound_body_element == directive -->
1507 <xsl:template
1508 match="footnote[@auto='*']">
1509 <xsl:call-template
1510 name="u:outputClass"/>
1511 <xsl:call-template
1512 name="u:BandI"/>
1513 <xsl:text>.. [*] </xsl:text>
1514 <xsl:apply-templates
1515 select="*[not(self::label)]"/>
1516 </xsl:template>
1518 <!-- == compound_body_element == directive -->
1519 <xsl:template
1520 match="footnote[starts-with(@names, 'TARGET_NOTE:\ ')]">
1521 <!-- This is not a footnote but a hint for a directive -->
1522 <xsl:if
1523 test="generate-id(//footnote[starts-with(@names, 'TARGET_NOTE:\ ')][1]) = generate-id(.)">
1524 <!-- Only for the first one -->
1525 <xsl:call-template
1526 name="u:BandI"/>
1527 <!-- TODO May have a `classes` attribute -->
1528 <xsl:text>.. target-notes::</xsl:text>
1529 &tEOL;
1530 </xsl:if>
1531 </xsl:template>
1533 <!-- == simple_body_subelement -->
1534 <xsl:template
1535 match="footnote/label">
1536 <xsl:apply-templates/>
1537 </xsl:template>
1539 <!-- ******************************************************************** -->
1541 <!--
1542 Content Model: (list_item +)
1543 Attributes: The bullet_list element contains the common attributes (ids,
1544 names, dupnames, source, and classes), plus bullet.
1545 bullet is used to record the style of bullet from the input data.
1546 In documents processed from reStructuredText, it contains one of "-",
1547 "+", or "*". It may be ignored in processing.
1549 <!-- == compound_body_element -->
1550 <xsl:template
1551 match="bullet_list">
1552 <xsl:call-template
1553 name="u:outputClass"/>
1554 <xsl:apply-templates
1555 mode="bullet_list"/>
1556 </xsl:template>
1558 <!-- ******************************************************************** -->
1560 <!--
1561 Content Model: (definition_list_item +)
1562 Attributes: The definition_list element contains only the common
1563 attributes: ids, names, dupnames, source, and classes.
1565 <!-- == compound_body_element -->
1566 <xsl:template
1567 match="definition_list">
1568 <xsl:call-template
1569 name="u:outputClass"/>
1570 <xsl:apply-templates/>
1571 </xsl:template>
1573 <!-- ******************************************************************** -->
1575 <!--
1576 Content Model: (term, classifier?, definition)
1577 Attributes: The definition_list_item element contains only the common
1578 attributes: ids, names, dupnames, source, and classes.
1580 <!-- == compound_body_subelement -->
1581 <xsl:template
1582 match="definition_list_item">
1583 <xsl:call-template
1584 name="u:outputClass"/>
1585 <xsl:call-template
1586 name="u:BandI"/>
1587 <xsl:apply-templates/>
1588 </xsl:template>
1590 <!-- ******************************************************************** -->
1592 <!--
1593 Content Model: %text.model;
1594 Attributes: The term element contains only the common attributes: ids,
1595 names, dupnames, source, and classes.
1597 <!-- == simple_body_subelement -->
1598 <xsl:template
1599 match="term">
1600 <xsl:apply-templates/>
1601 </xsl:template>
1603 <!-- ******************************************************************** -->
1605 <!--
1606 Content Model: %text.model;
1607 Attributes: The classifier element contains only the common attributes:
1608 ids, names, dupnames, source, and classes.
1610 <!-- == simple_body_subelement -->
1611 <xsl:template
1612 match="classifier">
1613 <xsl:text> : </xsl:text>
1614 <xsl:apply-templates/>
1615 </xsl:template>
1617 <!-- ******************************************************************** -->
1619 <!--
1620 Content Model: (%body.elements;)+
1621 Attributes: The definition element contains only the common attributes:
1622 ids, names, dupnames, source, and classes.
1624 <!-- == compound_body_subelement -->
1625 <xsl:template
1626 match="definition">
1627 <xsl:call-template
1628 name="u:outputClass"/>
1629 <xsl:apply-templates/>
1630 </xsl:template>
1632 <!-- ******************************************************************** -->
1634 <!--
1635 Content Model: (list_item +)
1636 Attributes: The enumerated_list element contains the common attributes
1637 (ids, names, dupnames, source, and classes), plus enumtype, prefix, suffix, and
1638 start.
1639 enumtype is used to record the intended enumeration sequence, one
1640 of "arabic" (1, 2, 3, ...), "loweralpha" (a, b, c, ..., z), "upperalpha" (A,
1641 B, C, ..., Z), "lowerroman" (i, ii, iii, iv, ..., mmmmcmxcix [4999]), or
1642 "upperroman" (I, II, III, IV, ..., MMMMCMXCIX [4999]).
1643 prefix stores the formatting characters used before the enumerator. In
1644 documents originating from reStructuredText data, it will contain either ""
1645 (empty string) or "(" (left parenthesis). It may or may not affect
1646 processing.
1647 suffix stores the formatting characters used after the enumerator. In
1648 documents originating from reStructuredText data, it will contain either "."
1649 (period) or ")" (right parenthesis). Depending on the capabilities of the
1650 output format, this attribute may or may not affect processing.
1651 start contains the ordinal value of the first item in the list, in
1652 decimal. For lists beginning at value 1 ("1", "a", "A", "i", or "I"), this
1653 attribute may be omitted.
1655 <!-- == compound_body_element -->
1656 <xsl:template
1657 match="enumerated_list">
1658 <xsl:call-template
1659 name="u:outputClass"/>
1660 <xsl:apply-templates
1661 mode="enumerated_list"/>
1662 </xsl:template>
1664 <!-- ******************************************************************** -->
1666 <!--
1667 Content Model: (field +)
1668 Attributes: The field_list element contains only the common attributes:
1669 ids, names, dupnames, source, and classes.
1671 <!-- == compound_body_element -->
1672 <xsl:template
1673 match="field_list">
1674 <xsl:call-template
1675 name="u:outputClass"/>
1676 <xsl:apply-templates/>
1677 </xsl:template>
1679 <!-- ******************************************************************** -->
1681 <!--
1682 Content Model: (field_name, field_body)
1683 Attributes: The field element contains only the common attributes: ids,
1684 names, dupnames, source, and classes.
1686 <!-- == compound_body_subelement -->
1687 <xsl:template
1688 match="field">
1689 <xsl:call-template
1690 name="u:outputClass"/>
1691 <xsl:call-template
1692 name="u:BandI"/>
1693 <xsl:apply-templates/>
1694 </xsl:template>
1696 <!-- ********************************************************************** -->
1698 <!--
1699 Content Model: %text.model;
1700 Attributes: The field_name element contains only the common attributes:
1701 ids, names, dupnames, source, and classes.
1703 <!-- == simple_body_subelement -->
1704 <xsl:template
1705 match="field_name">
1706 <xsl:text>:</xsl:text>
1707 <xsl:apply-templates/>
1708 <xsl:text>: </xsl:text>
1709 <!-- no EOL: field_body starts on same line -->
1710 </xsl:template>
1712 <!-- ******************************************************************** -->
1714 <!--
1715 Content Model: (%body.elements;)*
1716 Attributes: The field_body element contains only the common attributes:
1717 ids, names, dupnames, source, and classes.
1719 <!-- == compound_body_subelement -->
1720 <xsl:template
1721 match="field_body">
1722 <xsl:call-template
1723 name="u:outputClass"/>
1724 <xsl:apply-templates/>
1725 </xsl:template>
1727 <!-- ******************************************************************** -->
1729 <!--
1730 Content Model: (option_list_item +)
1731 Attributes: The option_list element contains only the common attributes:
1732 ids, names, dupnames, source, and classes.
1734 <!-- == compound_body_element -->
1735 <xsl:template
1736 match="option_list">
1737 <xsl:call-template
1738 name="u:outputClass"/>
1739 <xsl:call-template
1740 name="u:blank"/>
1741 <xsl:apply-templates/>
1742 </xsl:template>
1744 <!-- ******************************************************************** -->
1746 <!--
1747 Content Model: (option_group, description)
1748 Attributes: The option_list_item element contains only the common
1749 attributes: ids, names, dupnames, source, and classes.
1751 <!-- == compound_body_subelement -->
1752 <xsl:template
1753 match="option_list_item">
1754 <xsl:call-template
1755 name="u:outputClass"/>
1756 <xsl:call-template
1757 name="u:indent"/>
1758 <xsl:apply-templates/>
1759 </xsl:template>
1761 <!-- ******************************************************************** -->
1763 <!--
1764 Content Model: (option_group, description)
1765 Attributes: The option_group element contains only the common attributes:
1766 ids, names, dupnames, source, and classes.
1768 <!-- == compound_body_subelement -->
1769 <xsl:template
1770 match="option_group">
1771 <xsl:apply-templates/>
1772 &tEOL;
1773 </xsl:template>
1775 <!-- ******************************************************************** -->
1777 <!--
1778 Content Model: (option_string, option_argument *)
1779 Attributes: The option element contains only the common attributes: ids,
1780 names, dupnames, source, and classes.
1782 <!-- == compound_body_subelement -->
1783 <xsl:template
1784 match="option">
1785 <xsl:call-template
1786 name="u:outputClass"/>
1787 <xsl:apply-templates/>
1788 <xsl:if
1789 test="generate-id(current()) != generate-id(../*[last()])">
1790 <!-- No comma after final option -->
1791 <xsl:text>, </xsl:text>
1792 </xsl:if>
1793 <!-- no EOL: description on same line -->
1794 </xsl:template>
1796 <!-- ******************************************************************** -->
1798 <!--
1799 Content Model: (#PCDATA)
1800 Attributes: The option_string element contains only the common attributes:
1801 ids, names, dupnames, source, and classes.
1803 <!-- == simple_body_subelement -->
1804 <xsl:template
1805 match="option_string">
1806 <xsl:apply-templates/>
1807 </xsl:template>
1809 <!-- ******************************************************************** -->
1811 <!--
1812 Content Model: (#PCDATA)
1813 Attributes: The option_argument element contains the common attributes
1814 (ids, names, dupnames, source, and classes), plus delimiter.
1815 delimiter contains the text preceding the option_argument:
1816 either the text separating it from the option_string (typically
1817 either "=" or " ")
1818 or the text between option arguments (typically either "," or " ").
1820 <!-- == simple_body_subelement -->
1821 <xsl:template
1822 match="option_argument">
1823 <xsl:value-of
1824 select="@delimiter"/>
1825 <xsl:apply-templates/>
1826 </xsl:template>
1828 <!-- ******************************************************************** -->
1830 <!--
1831 Content Model: (%body.elements;)+
1832 Attributes: The description element contains only the common attributes:
1833 ids, names, dupnames, source, and classes.
1835 <!-- == compound_body_subelement -->
1836 <xsl:template
1837 match="description">
1838 <xsl:call-template
1839 name="u:outputClass"/>
1840 <xsl:apply-templates/>
1841 &tEOL;
1842 </xsl:template>
1844 <!-- ******************************************************************** -->
1846 <!--
1847 Content Model: (%body.elements;)+
1848 Attributes: The list_item element contains only the common attributes:
1849 ids, names, dupnames, source, and classes
1851 BULLET LIST
1852 bullet is used to record the style of bullet from the input data.
1853 In documents processed from reStructuredText, it contains one of "-",
1854 "+", or "*". It may be ignored in processing.
1856 <!-- == compound_body_subelement -->
1857 <xsl:template
1858 match="list_item"
1859 mode="bullet_list">
1860 <xsl:call-template
1861 name="u:outputClass"/>
1862 <xsl:if
1863 test="name(*[1]) != 'bullet_list'">
1864 <!-- Start the list item only if the first child is not another list -->
1865 <xsl:call-template
1866 name="u:BandI"/>
1867 <xsl:value-of
1868 select="../@bullet"/>
1869 &tSP; <!-- space after bullet -->
1870 </xsl:if>
1871 <xsl:apply-templates/>
1872 </xsl:template>
1874 <!-- ******************************************************************** -->
1876 <!--
1877 ENUMERATED LIST
1878 enumtype is used to record the intended enumeration sequence, one of
1879 "arabic" (1, 2, 3, ...), "loweralpha" (a, b, c, ..., z), "upperalpha" (A, B,
1880 C, ..., Z), "lowerroman" (i, ii, iii, iv, ..., mmmmcmxcix [4999]), or
1881 "upperroman" (I, II, III, IV, ..., MMMMCMXCIX [4999]).
1882 prefix stores the formatting characters used before the enumerator. In
1883 documents originating from reStructuredText data, it will contain either ""
1884 (empty string) or "(" (left parenthesis). It may or may not affect
1885 processing.
1886 suffix stores the formatting characters used after the enumerator. In
1887 documents originating from reStructuredText data, it will contain either "."
1888 (period) or ")" (right parenthesis). Depending on the capabilities of the
1889 output format, this attribute may or may not affect processing.
1890 start contains the ordinal value of the first item in the list, in
1891 decimal. For lists beginning at value 1 ("1", "a", "A", "i", or "I"), this
1892 attribute may be omitted.
1895 <!-- == compound_body_subelement -->
1896 <xsl:template
1897 match="list_item"
1898 mode="enumerated_list">
1899 <xsl:call-template
1900 name="u:outputClass"/>
1901 <xsl:call-template
1902 name="u:BandI"/>
1903 <xsl:call-template
1904 name="u:outputEnumerator"/>
1905 <xsl:apply-templates/>
1906 </xsl:template>
1908 <!-- Outputs a complete enumerator when called in an
1909 enumerated_list/list_item -->
1910 <xsl:template
1911 name="u:outputEnumerator">
1912 <!-- Use parent's numeration attribute -->
1913 <xsl:variable
1914 name="enumType"
1915 select="../@enumtype"/>
1916 <!-- Determine starting point -->
1917 <xsl:variable
1918 name="start">
1919 <xsl:choose>
1920 <xsl:when
1921 test="../@start">
1922 <xsl:value-of
1923 select="../@start"/>
1924 </xsl:when>
1925 <xsl:otherwise>
1926 <xsl:value-of
1927 select="1"/>
1928 </xsl:otherwise>
1929 </xsl:choose>
1930 </xsl:variable>
1931 <!-- Determine position of this item in its real context -->
1932 <xsl:variable
1933 name="position">
1934 <xsl:variable
1935 name="wanted"
1936 select="generate-id()"/>
1937 <!-- Generate the right current node list -->
1938 <xsl:for-each
1939 select="../list_item">
1940 <xsl:if
1941 test="generate-id() = $wanted">
1942 <xsl:value-of
1943 select="position()"/>
1944 </xsl:if>
1945 </xsl:for-each>
1946 </xsl:variable>
1947 <!-- Determine encoding of the number for the given numeration -->
1948 <xsl:variable
1949 name="cur">
1950 <xsl:call-template
1951 name="u:position2Enumerator">
1952 <xsl:with-param
1953 name="enumType"
1954 select="$enumType"/>
1955 <xsl:with-param
1956 name="position"
1957 select="$position"/>
1958 <xsl:with-param
1959 name="start"
1960 select="$start"/>
1961 </xsl:call-template>
1962 </xsl:variable>
1963 <!-- Determine encoding of the maximum number -->
1964 <xsl:variable
1965 name="max">
1966 <xsl:call-template
1967 name="u:position2Enumerator">
1968 <xsl:with-param
1969 name="enumType"
1970 select="$enumType"/>
1971 <xsl:with-param
1972 name="position"
1973 select="count(../list_item)"/>
1974 <xsl:with-param
1975 name="start"
1976 select="$start"/>
1977 </xsl:call-template>
1978 </xsl:variable>
1979 <!-- Output complete enumerator -->
1980 <xsl:value-of
1981 select="../@prefix"/>
1982 <xsl:value-of
1983 select="$cur"/>
1984 <xsl:value-of
1985 select="../@suffix"/>
1986 <!-- Output at least one trailing space -->
1987 &tSP;
1988 <!-- Output more whitespace to align with the maximum enumerator -->
1989 <xsl:if
1990 test="$enumType != 'lowerroman' and $enumType != 'upperroman'">
1991 <!-- Assumes that the maximum number has maximum string length -->
1992 <xsl:value-of
1993 select="str:padding(string-length($max) - string-length($cur))"/>
1994 </xsl:if>
1995 </xsl:template>
1997 <!-- Determine the right ordinal enumerator based on the parameters -->
1998 <xsl:template
1999 name="u:position2Enumerator">
2000 <xsl:param
2001 name="enumType"/>
2002 <xsl:param
2003 name="start"/>
2004 <xsl:param
2005 name="position"/>
2006 <!-- Determine logical number -->
2007 <xsl:variable
2008 name="ordinal"
2009 select="$start - 1 + $position"/>
2010 <xsl:choose>
2011 <xsl:when
2012 test="$enumType = 'arabic'">
2013 <xsl:value-of
2014 select="$ordinal"/>
2015 </xsl:when>
2016 <xsl:when
2017 test="$enumType = 'loweralpha'">
2018 <xsl:value-of
2019 select="substring('abcdefghijklmnopqrstzuvwxyz', $ordinal, 1)"/>
2020 </xsl:when>
2021 <xsl:when
2022 test="$enumType = 'upperalpha'">
2023 <xsl:value-of
2024 select="substring('ABCDEFGHIJKLMNOPQRSTZUVWXYZ', $ordinal, 1)"/>
2025 </xsl:when>
2026 <!-- TODO Support for counting roman numbers -->
2027 <xsl:when
2028 test="$enumType = 'lowerroman'">
2029 <xsl:text>i</xsl:text>
2030 </xsl:when>
2031 <xsl:when
2032 test="$enumType = 'upperroman'">
2033 <xsl:text>I</xsl:text>
2034 </xsl:when>
2035 </xsl:choose>
2036 </xsl:template>
2038 <!-- ******************************************************************** -->
2039 <!-- ******************************************************************** -->
2041 <!--
2042 Content Model: (title?, tgroup+)
2043 Attributes: The table element contains the common attributes and:
2044 frame, colsep, rowsep, pgwide
2046 <!-- == compound_body_element -->
2047 <xsl:template
2048 match="table">
2049 <xsl:call-template
2050 name="u:outputClass"/>
2051 <xsl:call-template
2052 name="u:blank"/>
2053 <xsl:apply-templates
2054 select="tgroup"/>
2055 <xsl:if
2056 test="title">
2057 <!-- TODO A table title must be rendered by using the `.. table::'
2058 directive -->
2059 <xsl:call-template
2060 name="u:BandI"/>
2061 <xsl:apply-templates
2062 select="title"/>
2063 &tEOL;
2064 </xsl:if>
2065 </xsl:template>
2067 <!-- ******************************************************************** -->
2069 <!--
2070 Content Model: (colspec*, thead?, tbody)
2071 Attributes: The tgroup element contains the common attributes and:
2072 cols, colsep, rowsep, align
2074 <!-- == compound_body_subelement -->
2075 <xsl:template
2076 match="tgroup">
2077 <xsl:apply-templates/>
2078 </xsl:template>
2080 <!-- ******************************************************************** -->
2082 <!--
2083 Content Model: EMPTY
2084 Attributes: The colspec element contains the common attributes and:
2085 colnum, colname, colwidth, colsep, rowsep, align, char, charoff
2087 The colwidth attribute gives the width of the respective column in characters
2088 including padding whitespace but no separator markup.
2090 <!-- == simple_body_subelement -->
2091 <!-- @colwidth needed by children but element has no own output -->
2092 <xsl:template
2093 match="colspec"/>
2095 <!-- ******************************************************************** -->
2097 <!--
2098 Content Model: (row+)
2099 Attributes: The thead element contains the common attributes and:
2100 valign
2102 <!-- == compound_body_subelement -->
2103 <xsl:template
2104 match="thead">
2105 <xsl:apply-templates/>
2106 </xsl:template>
2108 <!--
2109 Content Model: (row+)
2110 Attributes: The tbody element contains the common attributes and:
2111 valign
2113 <!-- == compound_body_subelement -->
2114 <xsl:template
2115 match="tbody">
2116 <xsl:apply-templates/>
2117 </xsl:template>
2119 <!-- ******************************************************************** -->
2121 <!--
2122 Content Model: (entry+)
2123 Attributes: The row element contains the common attributes and:
2124 rowsep, valign
2126 <!-- == compound_body_subelement -->
2127 <xsl:template
2128 match="row">
2129 <!-- Separator line above unless first row of a tbody with no previous
2130 thead (in this case the separator line is output already as the
2131 closing separator line of thead) -->
2132 <xsl:if
2133 test="position() > 1 or parent::thead or parent::tbody and not(../../thead)">
2134 <xsl:call-template
2135 name="u:rowSeparatorLine"/>
2136 </xsl:if>
2137 <!-- Determine heights in physical lines of all entries -->
2138 <xsl:variable
2139 name="heights">
2140 <xsl:for-each
2141 select="entry">
2142 <xsl:variable
2143 name="text">
2144 <!-- Catch the text of all entries -->
2145 <xsl:apply-templates/>
2146 </xsl:variable>
2147 <!-- Compute height of this entry; leading and trailing EOL must be
2148 subtracted -->
2149 <xsl:value-of
2150 select="string-length($text) - string-length(translate($text, '&#xA;', '')) - 1"/>
2151 &tSP; <!-- A space as a list separator -->
2152 </xsl:for-each>
2153 </xsl:variable>
2154 <!-- Determine maximum height so every entry must be this high -->
2155 <xsl:variable
2156 name="maxHeight"
2157 select="math:max(str:tokenize(normalize-space($heights)))"/>
2158 <!-- Output all the physical lines of this row -->
2159 <xsl:call-template
2160 name="u:rowLines">
2161 <xsl:with-param
2162 name="currentLine"
2163 select="1"/>
2164 <xsl:with-param
2165 name="maxLine"
2166 select="$maxHeight"/>
2167 </xsl:call-template>
2168 <!-- Output final separator line if this is the last row -->
2169 <xsl:if
2170 test="position() = last()">
2171 <xsl:call-template
2172 name="u:rowSeparatorLine">
2173 <xsl:with-param
2174 name="char">
2175 <!-- Determine correct character for the separator line -->
2176 <xsl:choose>
2177 <xsl:when
2178 test="parent::thead">
2179 <xsl:value-of
2180 select="'='"/>
2181 </xsl:when>
2182 <xsl:otherwise>
2183 <xsl:value-of
2184 select="'-'"/>
2185 </xsl:otherwise>
2186 </xsl:choose>
2187 </xsl:with-param>
2188 </xsl:call-template>
2189 </xsl:if>
2190 </xsl:template>
2192 <!-- Output physical line $currentLine of a row and continue until
2193 line $maxLine is output -->
2194 <xsl:template
2195 name="u:rowLines">
2196 <xsl:param
2197 name="currentLine"/>
2198 <xsl:param
2199 name="maxLine"/>
2200 <xsl:if
2201 test="$currentLine &lt;= $maxLine">
2202 <!-- If there are still physical lines to output do it -->
2203 <xsl:call-template
2204 name="u:indent"/>
2205 <!-- Leading bar -->
2206 <xsl:text>|</xsl:text>
2207 <xsl:apply-templates>
2208 <xsl:with-param
2209 name="currentLine"
2210 select="$currentLine"/>
2211 </xsl:apply-templates>
2212 <!-- End of this physical line -->
2213 &tEOL;
2214 <!-- Continue with the next physical line -->
2215 <xsl:call-template
2216 name="u:rowLines">
2217 <xsl:with-param
2218 name="currentLine"
2219 select="$currentLine + 1"/>
2220 <xsl:with-param
2221 name="maxLine"
2222 select="$maxLine"/>
2223 </xsl:call-template>
2224 </xsl:if>
2225 </xsl:template>
2227 <!-- Output a separator line with all the right characters -->
2228 <xsl:template
2229 name="u:rowSeparatorLine">
2230 <xsl:param
2231 name="char"
2232 select="'-'"/>
2233 <xsl:call-template
2234 name="u:indent"/>
2235 <xsl:text>+</xsl:text>
2236 <xsl:for-each
2237 select="../../colspec">
2238 <xsl:value-of
2239 select="str:padding(@colwidth, $char)"/>
2240 <xsl:text>+</xsl:text>
2241 </xsl:for-each>
2242 &tEOL;
2243 </xsl:template>
2245 <!-- ******************************************************************** -->
2247 <!--
2248 Content Model: (%body.elements;)*
2249 Attributes: The entry element contains the common attributes and:
2250 colname, namest, morerows, colsep, rowsep, align, char, charoff, valign and
2251 morecols
2253 <!-- == compound_body_subelement -->
2254 <xsl:template
2255 match="entry">
2256 <!-- TODO `classes` attribute needs support -->
2257 <!-- This is called in two ways; if $currentLine = 0 all physical lines
2258 of this entry must be output; if $currentLine > 0 the physical line
2259 with exactly this number shall be output -->
2260 <xsl:param
2261 name="currentLine"
2262 select="0"/>
2263 <xsl:variable
2264 name="column"
2265 select="position() + sum(preceding-sibling::entry/@morecols)"/>
2266 <!-- Determine width in characters needed for this entry -->
2267 <xsl:variable
2268 name="width">
2269 <xsl:call-template
2270 name="u:computeEntryWidth">
2271 <xsl:with-param
2272 name="colspecs"
2273 select="../../../colspec"/>
2274 <xsl:with-param
2275 name="column"
2276 select="$column"/>
2277 <xsl:with-param
2278 name="span"
2279 select="@morecols"/>
2280 </xsl:call-template>
2281 </xsl:variable>
2282 <!-- Output the entry completely or a certain physical line -->
2283 <xsl:call-template
2284 name="u:outputEntry">
2285 <xsl:with-param
2286 name="string">
2287 <!-- Capture physical lines of the entry in a variable -->
2288 <xsl:apply-templates/>
2289 </xsl:with-param>
2290 <xsl:with-param
2291 name="width"
2292 select="$width"/>
2293 <xsl:with-param
2294 name="expectedIndent">
2295 <!-- Capture indent for the entry generated by the normal template
2296 rules to remove it later -->
2297 <xsl:call-template
2298 name="u:indent"/>
2299 </xsl:with-param>
2300 <xsl:with-param
2301 name="outputLine"
2302 select="$currentLine"/>
2303 </xsl:call-template>
2304 <!-- Final bar after the entry -->
2305 <xsl:text>|</xsl:text>
2306 </xsl:template>
2308 <!-- Compute width of the entry -->
2309 <xsl:template
2310 name="u:computeEntryWidth">
2311 <!-- The colspec elements of all columns -->
2312 <xsl:param
2313 name="colspecs"/>
2314 <!-- Column of this entry -->
2315 <xsl:param
2316 name="column"/>
2317 <!-- Number of columns this entry spans -->
2318 <xsl:param
2319 name="span"
2320 select="0"/>
2321 <xsl:param
2322 name="sum"
2323 select="0"/>
2324 <xsl:choose>
2325 <xsl:when
2326 test="$span">
2327 <!-- If entry spans multiple columns compute their width -->
2328 <xsl:call-template
2329 name="u:computeEntryWidth">
2330 <xsl:with-param
2331 name="colspecs"
2332 select="$colspecs"/>
2333 <xsl:with-param
2334 name="column"
2335 select="$column + 1"/>
2336 <xsl:with-param
2337 name="span"
2338 select="$span - 1"/>
2339 <!-- Add the separator character and the following column width -->
2340 <xsl:with-param
2341 name="sum"
2342 select="$sum + 1 + $colspecs[$column]/@colwidth"/>
2343 </xsl:call-template>
2344 </xsl:when>
2345 <xsl:otherwise>
2346 <!-- Does not span more columns so return sum and width of this
2347 column -->
2348 <xsl:value-of
2349 select="$sum + $colspecs[$column]/@colwidth"/>
2350 </xsl:otherwise>
2351 </xsl:choose>
2352 </xsl:template>
2354 <!-- Outputs one or all lines of a table entry as a string trimmed left and
2355 padded -->
2356 <xsl:template
2357 name="u:outputEntry">
2358 <!-- Width of the entry; there is no provision for actual physical lines
2359 longer than this width -->
2360 <xsl:param
2361 name="width"/>
2362 <!-- The string containing the remaining physical lines; may be an empty
2363 string -->
2364 <xsl:param
2365 name="string"
2366 select="''"/>
2367 <!-- The indendation which is expected to be prefixed before every
2368 physical line -->
2369 <xsl:param
2370 name="expectedIndent"
2371 select="''"/>
2372 <!-- Is this the first call to this template -->
2373 <xsl:param
2374 name="isFirst"
2375 select="true()"/>
2376 <!-- Number of physical line to output or 0 to output all lines -->
2377 <xsl:param
2378 name="outputLine"
2379 select="0"/>
2380 <!-- Output is wanted if all or the first physical line are to be
2381 output -->
2382 <xsl:variable
2383 name="doOutput"
2384 select="$outputLine = 0 or $outputLine = 1"/>
2385 <xsl:variable
2386 name="stringLFHalfTrimmed">
2387 <xsl:choose>
2388 <xsl:when
2389 test="$isFirst and substring($string, 1, 1) = '&#x0A;'">
2390 <!-- Remove leading linefeed if this is the first time -->
2391 <xsl:value-of
2392 select="substring($string, 2)"/>
2393 </xsl:when>
2394 <xsl:otherwise>
2395 <xsl:value-of
2396 select="$string"/>
2397 </xsl:otherwise>
2398 </xsl:choose>
2399 </xsl:variable>
2400 <xsl:variable
2401 name="stringLFTrimmed">
2402 <xsl:choose>
2403 <xsl:when
2404 test="$isFirst and substring($stringLFHalfTrimmed, string-length($stringLFHalfTrimmed), 1) = '&#x0A;'">
2405 <!-- Remove trailing linefeed if this is the first time -->
2406 <xsl:value-of
2407 select="substring($stringLFHalfTrimmed, 1, string-length($stringLFHalfTrimmed) - 1)"/>
2408 </xsl:when>
2409 <xsl:otherwise>
2410 <xsl:value-of
2411 select="$stringLFHalfTrimmed"/>
2412 </xsl:otherwise>
2413 </xsl:choose>
2414 </xsl:variable>
2415 <!-- Determine remaining lines after the first one -->
2416 <xsl:variable
2417 name="remainingLines">
2418 <xsl:if
2419 test="contains($stringLFTrimmed, '&#x0A;')">
2420 <xsl:value-of
2421 select="substring-after($stringLFTrimmed, '&#x0A;')"/>
2422 </xsl:if>
2423 </xsl:variable>
2424 <xsl:if
2425 test="$doOutput">
2426 <!-- If this physical line must be output determine the first physical
2427 line -->
2428 <xsl:variable
2429 name="firstLine">
2430 <xsl:choose>
2431 <xsl:when
2432 test="string-length($remainingLines)">
2433 <xsl:value-of
2434 select="substring-before($stringLFTrimmed, '&#x0A;')"/>
2435 </xsl:when>
2436 <xsl:otherwise>
2437 <xsl:value-of
2438 select="$stringLFTrimmed"/>
2439 </xsl:otherwise>
2440 </xsl:choose>
2441 </xsl:variable>
2442 <!-- Remove the leading indentation from the physical line which is
2443 brought there by the normal templates -->
2444 <xsl:variable
2445 name="trimmed">
2446 <xsl:if
2447 test="string-length($firstLine)">
2448 <!-- Trim only non-empty lines -->
2449 <xsl:value-of
2450 select="substring-after($firstLine, $expectedIndent)"/>
2451 </xsl:if>
2452 </xsl:variable>
2453 <!-- Pad the line with a leading and a trailing space -->
2454 <xsl:variable
2455 name="padded"
2456 select="concat(' ', $trimmed, ' ')"/>
2457 <!-- Output the padded value -->
2458 <xsl:value-of
2459 select="$padded"/>
2460 <!-- Fill up the width of the entry with spaces -->
2461 <xsl:if
2462 test="$width - string-length($padded) &lt; 0">
2463 <xsl:message>
2464 <xsl:text>WARNING: Table column too narrow (minimum: </xsl:text>
2465 <xsl:value-of
2466 select="string-length($padded)"/>
2467 <xsl:text>)</xsl:text>
2468 &tEOL;
2469 </xsl:message>
2470 </xsl:if>
2471 <xsl:value-of
2472 select="str:padding($width - string-length($padded))"/>
2473 </xsl:if>
2474 <xsl:if
2475 test="$outputLine > 1 or $outputLine = 0 and string-length($remainingLines)">
2476 <!-- If a following physical line must be output or if all physical
2477 lines shall be output and there are remaining physical lines -->
2478 <xsl:if
2479 test="$outputLine = 0">
2480 <!-- Output linefeed only if we output all the lines -->
2481 &tEOL;
2482 </xsl:if>
2483 <!-- Output the remaining lines -->
2484 <xsl:call-template
2485 name="u:outputEntry">
2486 <xsl:with-param
2487 name="width"
2488 select="$width"/>
2489 <xsl:with-param
2490 name="string"
2491 select="$remainingLines"/>
2492 <xsl:with-param
2493 name="expectedIndent"
2494 select="$expectedIndent"/>
2495 <xsl:with-param
2496 name="isFirst"
2497 select="false()"/>
2498 <xsl:with-param
2499 name="outputLine">
2500 <xsl:choose>
2501 <xsl:when
2502 test="$outputLine = 0">
2503 <xsl:value-of
2504 select="0"/>
2505 </xsl:when>
2506 <xsl:otherwise>
2507 <xsl:value-of
2508 select="$outputLine - 1"/>
2509 </xsl:otherwise>
2510 </xsl:choose>
2511 </xsl:with-param>
2512 </xsl:call-template>
2513 </xsl:if>
2514 </xsl:template>
2516 <!-- ******************************************************************** -->
2517 <!-- ******************************************************************** -->
2519 <!-- == inline_element -->
2520 <xsl:template
2521 match="citation_reference">
2522 <xsl:call-template
2523 name="u:bkslshEscPre"/>
2524 <xsl:text>[</xsl:text>
2525 <xsl:apply-templates/>
2526 <xsl:text>]_</xsl:text>
2527 <xsl:call-template
2528 name="u:bkslshEscSuf"/>
2529 </xsl:template>
2531 <!-- ******************************************************************** -->
2533 <!-- == inline_element -->
2534 <xsl:template
2535 match="substitution_reference">
2536 <xsl:call-template
2537 name="u:bkslshEscPre"/>
2538 <xsl:text>|</xsl:text>
2539 <xsl:apply-templates/>
2540 <xsl:text>|</xsl:text>
2541 <xsl:call-template
2542 name="u:bkslshEscSuf"/>
2543 </xsl:template>
2545 <!-- ******************************************************************** -->
2547 <!-- == inline_element -->
2548 <xsl:template
2549 match="emphasis">
2550 <xsl:call-template
2551 name="u:bkslshEscPre"/>
2552 <xsl:text>*</xsl:text>
2553 <xsl:apply-templates/>
2554 <xsl:text>*</xsl:text>
2555 <xsl:call-template
2556 name="u:bkslshEscSuf"/>
2557 </xsl:template>
2559 <!-- ******************************************************************** -->
2561 <!-- user-numbered footnotes lack @auto -->
2562 <!-- == inline_element -->
2563 <xsl:template
2564 match="footnote_reference[not(@auto)]">
2565 <xsl:call-template
2566 name="u:bkslshEscPre"/>
2567 <xsl:text>[</xsl:text>
2568 <xsl:value-of
2569 select="text()"/>
2570 <xsl:text>]_</xsl:text>
2571 <xsl:call-template
2572 name="u:bkslshEscSuf"/>
2573 <!-- child paragraph provides blank line -->
2574 </xsl:template>
2576 <!-- automatically numbered footnotes have @auto -->
2577 <!-- if @names is different from label content, it is a named footnote -->
2578 <!-- == inline_element -->
2579 <xsl:template
2580 match="footnote_reference[@auto='1']">
2581 <xsl:variable
2582 name="ref"
2583 select="@refid"/>
2584 <xsl:if
2585 test="not(starts-with(//footnote[@ids=$ref]/@names, 'TARGET_NOTE:\ '))">
2586 <!-- Not a generated footnote reference for a `.. target-notes::';
2587 such footnote reference and the preceding space should be
2588 embedded in `generated'! -->
2589 <xsl:call-template
2590 name="u:bkslshEscPre"/>
2591 <xsl:text>[#</xsl:text>
2592 <xsl:if
2593 test="//footnote[@ids=$ref]/@names != //footnote[@ids=$ref]/label">
2594 <xsl:call-template
2595 name="u:outputNames">
2596 <xsl:with-param
2597 name="names"
2598 select="//footnote[@ids=$ref]/@names"/>
2599 </xsl:call-template>
2600 </xsl:if>
2601 <xsl:text>]_</xsl:text>
2602 <xsl:call-template
2603 name="u:bkslshEscSuf"/>
2604 </xsl:if>
2605 </xsl:template>
2607 <!-- automatically symboled footnotes have @auto=* -->
2608 <!-- == inline_element -->
2609 <xsl:template
2610 match="footnote_reference[@auto='*']">
2611 <xsl:call-template
2612 name="u:bkslshEscPre"/>
2613 <xsl:text>[*]_</xsl:text>
2614 <xsl:call-template
2615 name="u:bkslshEscSuf"/>
2616 </xsl:template>
2618 <!-- ******************************************************************** -->
2620 <!--
2621 Content Model: %text.model;
2623 <!-- == inline_element -->
2624 <xsl:template
2625 match="literal">
2626 <xsl:call-template
2627 name="u:bkslshEscPre"/>
2628 <xsl:text>``</xsl:text>
2629 <xsl:apply-templates/>
2630 <xsl:text>``</xsl:text>
2631 <xsl:call-template
2632 name="u:bkslshEscSuf"/>
2633 </xsl:template>
2635 <!-- ******************************************************************** -->
2637 <!-- Attribute combinations found in `standard' text and other examples:
2638 @refuri = standalone hyperlink
2639 @ids @refid = TOC, probably all in <generated>
2640 @name @refuri with matching <target> in document = named external hyperlink _
2641 @name @refuri immediately followed by matching <target> = named embedded URI _
2642 @name @refuri with no matching <target> in document = anonymous embedded URI __
2643 @anonymous @name @refuri with no matching <target> in document = anonymous explicit URI __
2644 @name @refid = internal cross-reference _
2645 @anonymous @name @refid = anonymous implicit internal reference __
2646 @name @refid image = clickable image to internal reference _
2647 @refuri image = clickable image to standalone hyperlink
2649 A target matches if target/@names contains the lower cased, whitespace
2650 quoted reference/@name
2653 <!-- Standalone hyperlink -->
2654 <!-- == inline_element -->
2655 <xsl:template
2656 match="reference[not(@name or @anonymous)]">
2657 <xsl:call-template
2658 name="u:bkslshEscPre"/>
2659 <xsl:choose>
2660 <xsl:when
2661 test="starts-with(., 'PEP ')">
2662 <xsl:text>:PEP:`</xsl:text>
2663 <xsl:value-of
2664 select="substring-after(., 'PEP ')"/>
2665 <xsl:text>`</xsl:text>
2666 </xsl:when>
2667 <xsl:when
2668 test="starts-with(., 'RFC ')">
2669 <xsl:text>:RFC:`</xsl:text>
2670 <xsl:value-of
2671 select="substring-after(., 'RFC ')"/>
2672 <xsl:text>`</xsl:text>
2673 </xsl:when>
2674 <xsl:otherwise>
2675 <xsl:apply-templates/>
2676 </xsl:otherwise>
2677 </xsl:choose>
2678 <xsl:call-template
2679 name="u:bkslshEscSuf"/>
2680 </xsl:template>
2682 <!-- External references -->
2683 <!-- == inline_element -->
2684 <xsl:template
2685 match="reference[@name and @refuri]">
2686 <!-- Determine normalized name by downcasing it -->
2687 <xsl:variable
2688 name="normalized"
2689 select="translate(normalize-space(@name), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
2690 <xsl:variable
2691 name="quoted"
2692 select="str:replace($normalized, ' ', '\ ')"/>
2693 <xsl:variable
2694 name="matching"
2695 select="//target[contains(@names, $quoted)]"/>
2696 <xsl:call-template
2697 name="u:inlineReference">
2698 <xsl:with-param
2699 name="anonymous"
2700 select="not($matching) or @anonymous"/>
2701 <xsl:with-param
2702 name="embedded"
2703 select="not(@anonymous) and (not($matching) or generate-id(following-sibling::node()[1]) = generate-id($matching))"/>
2704 </xsl:call-template>
2705 </xsl:template>
2707 <!-- Internal references -->
2708 <!-- == inline_element -->
2709 <xsl:template
2710 match="reference[@name and @refid]">
2711 <xsl:call-template
2712 name="u:inlineReference">
2713 <xsl:with-param
2714 name="anonymous"
2715 select="@anonymous"/>
2716 </xsl:call-template>
2717 </xsl:template>
2719 <!-- Image references -->
2720 <!-- == inline_element -->
2721 <xsl:template
2722 match="reference[image]">
2723 <!-- All done by the `image' tag -->
2724 <xsl:apply-templates/>
2725 </xsl:template>
2727 <!-- ******************************************************************** -->
2729 <!--
2730 Content Model: %text.model;
2732 <!-- == inline_element -->
2733 <xsl:template
2734 match="strong">
2735 <xsl:call-template
2736 name="u:bkslshEscPre"/>
2737 <xsl:text>**</xsl:text>
2738 <xsl:apply-templates/>
2739 <xsl:text>**</xsl:text>
2740 <xsl:call-template
2741 name="u:bkslshEscSuf"/>
2742 </xsl:template>
2744 <!-- ******************************************************************** -->
2746 <!-- == inline_element -->
2747 <xsl:template
2748 match="subscript">
2749 <xsl:call-template
2750 name="u:bkslshEscPre"/>
2751 <xsl:text>:sub:`</xsl:text>
2752 <xsl:apply-templates/>
2753 <xsl:text>`</xsl:text>
2754 <xsl:call-template
2755 name="u:bkslshEscSuf"/>
2756 </xsl:template>
2758 <!-- ******************************************************************** -->
2760 <!-- == inline_element -->
2761 <xsl:template
2762 match="superscript">
2763 <xsl:call-template
2764 name="u:bkslshEscPre"/>
2765 <xsl:text>:sup:`</xsl:text>
2766 <xsl:apply-templates/>
2767 <xsl:text>`</xsl:text>
2768 <xsl:call-template
2769 name="u:bkslshEscSuf"/>
2770 </xsl:template>
2772 <!-- ******************************************************************** -->
2774 <!-- The target element has various roles depending on context; they are
2775 all handled here -->
2776 <!-- == simple_body_element == inline_element == directive -->
2777 <xsl:template
2778 match="target">
2779 <xsl:choose>
2780 <xsl:when
2781 test="name(preceding-sibling::*[1]) = 'reference'">
2782 <!-- An embedded inline target - handled by the reference itself -->
2783 </xsl:when>
2784 <xsl:when
2785 test="contains($inline_containers, concat('*', name(..), '*'))">
2786 <!-- An inline target of some sort -->
2787 <xsl:call-template
2788 name="u:inlineReference">
2789 <xsl:with-param
2790 name="isTarget"
2791 select="true()"/>
2792 </xsl:call-template>
2793 </xsl:when>
2794 <xsl:when
2795 test="@anonymous">
2796 <!-- An anonymous target directive -->
2797 <xsl:call-template
2798 name="u:outputClass"/>
2799 <xsl:call-template
2800 name="u:BandI"/>
2801 <xsl:text>__ </xsl:text>
2802 <xsl:choose>
2803 <xsl:when
2804 test="@refid">
2805 <xsl:call-template
2806 name="u:outputNamesRefid"/>
2807 <xsl:text>_</xsl:text>
2808 </xsl:when>
2809 <xsl:when
2810 test="@refuri">
2811 <xsl:value-of
2812 select="@refuri"/>
2813 </xsl:when>
2814 </xsl:choose>
2815 &tEOL;
2816 </xsl:when>
2817 <xsl:when
2818 test="@names | @refid">
2819 <!-- A target directive -->
2820 <xsl:call-template
2821 name="u:outputClass"/>
2822 <xsl:call-template
2823 name="u:BandI"/>
2824 <xsl:text>.. _</xsl:text>
2825 <xsl:choose>
2826 <xsl:when
2827 test="@refid">
2828 <xsl:call-template
2829 name="u:outputNamesRefid"/>
2830 </xsl:when>
2831 <xsl:otherwise>
2832 <xsl:variable
2833 name="quoteNeeded"
2834 select="contains(@names, ':')"/>
2835 <xsl:if
2836 test="$quoteNeeded">
2837 <xsl:text>`</xsl:text>
2838 </xsl:if>
2839 <xsl:call-template
2840 name="u:outputNames"/>
2841 <xsl:if
2842 test="$quoteNeeded">
2843 <xsl:text>`</xsl:text>
2844 </xsl:if>
2845 </xsl:otherwise>
2846 </xsl:choose>
2847 <xsl:text>:</xsl:text>
2848 <xsl:if
2849 test="@refuri">
2850 <xsl:text> </xsl:text>
2851 <xsl:value-of
2852 select="@refuri"/>
2853 </xsl:if>
2854 &tEOL;
2855 </xsl:when>
2856 <xsl:otherwise>
2857 <!-- Should not happen -->
2858 <xsl:call-template
2859 name="u:notSupported"/>
2860 </xsl:otherwise>
2861 </xsl:choose>
2862 </xsl:template>
2864 <!-- ******************************************************************** -->
2866 <!--
2867 Content Model: %text.model;
2869 <!-- == inline_element -->
2870 <xsl:template
2871 match="title_reference">
2872 <xsl:call-template
2873 name="u:bkslshEscPre"/>
2874 <xsl:text>`</xsl:text>
2875 <xsl:apply-templates/>
2876 <xsl:text>`</xsl:text>
2877 <xsl:call-template
2878 name="u:bkslshEscSuf"/>
2879 </xsl:template>
2881 <!-- ******************************************************************** -->
2883 <!--
2884 Content Model: %text.model;
2886 <!-- == inline_element -->
2887 <xsl:template
2888 match="inline">
2889 <!-- TODO `role' directives must be generated for plain and derived
2890 user-defined roles. -->
2891 <xsl:call-template
2892 name="u:bkslshEscPre"/>
2893 <xsl:text>:</xsl:text>
2894 <xsl:value-of
2895 select="@classes"/>
2896 <xsl:text>:`</xsl:text>
2897 <xsl:apply-templates/>
2898 <xsl:text>`</xsl:text>
2899 <xsl:call-template
2900 name="u:bkslshEscSuf"/>
2901 </xsl:template>
2903 <!-- ******************************************************************** -->
2905 <!-- TODO `meta` directive must be implemented. -->
2907 <!-- ******************************************************************** -->
2909 <!--
2910 Docutils wraps generated elements around text that is inserted (generated) by
2911 Docutils; i.e., text that was not in the document, like section numbers
2912 inserted by the "sectnum" directive.
2914 <!-- == inline_element -->
2915 <xsl:template
2916 match="generated"/>
2918 <!-- == inline_element -->
2919 <xsl:template
2920 match="problematic">
2921 <!-- Simply output the contained text because this is probably the
2922 original text-->
2923 <xsl:value-of
2924 select="text()"/>
2925 </xsl:template>
2927 <!-- == compound_body_element -->
2928 <xsl:template
2929 match="system_message"/>
2931 <!-- ******************************************************************** -->
2932 <!-- ******************************************************************** -->
2934 <!--
2935 When a block of text contains linefeeds, it was indented relative to a marker
2936 on the first line
2938 <xsl:template
2939 match="text()">
2940 <xsl:call-template
2941 name="u:indentLF"/>
2942 </xsl:template>
2944 <xsl:template
2945 match="text()"
2946 mode="inLiteral">
2947 <xsl:call-template
2948 name="u:indentLF">
2949 <xsl:with-param
2950 name="literal"
2951 select="true()"/>
2952 </xsl:call-template>
2953 </xsl:template>
2955 <!-- ******************************************************************** -->
2956 <!-- ******************************************************************** -->
2958 <!-- Add a blank line if necessary and indent -->
2959 <xsl:template
2960 name="u:BandI">
2961 <xsl:call-template
2962 name="u:blank"/>
2963 <xsl:call-template
2964 name="u:indent"/>
2965 </xsl:template>
2967 <!-- ******************************************************************** -->
2969 <!-- Add a blank line in certain contexts -->
2970 <xsl:template
2971 name="u:blank">
2972 <xsl:apply-templates
2973 mode="blankSkipInline"
2974 select="preceding::*[1]"/>
2975 </xsl:template>
2977 <!-- Find the preceding element we are really interested in and act
2978 according to this element -->
2979 <xsl:template
2980 mode="blankSkipInline"
2981 match="*">
2982 <xsl:choose>
2983 <!-- Skip all inline elements and body subelements and check their
2984 parents -->
2985 <xsl:when
2986 test="contains(concat($inline_elements, $simple_body_subelements, $compound_body_subelements), concat('*', name(.), '*'))">
2987 <xsl:apply-templates
2988 mode="blankSkipInline"
2989 select=".."/>
2990 </xsl:when>
2991 <xsl:otherwise>
2992 <!-- Reached the type of element we decide on -->
2993 <xsl:if
2994 test="contains($blank_after, concat('*', name(.), '*'))">
2995 &tCR;
2996 </xsl:if>
2997 </xsl:otherwise>
2998 </xsl:choose>
2999 </xsl:template>
3001 <!-- ******************************************************************** -->
3003 <!--
3004 Indent a block if it's a child of...
3006 <data:lookup>
3007 <data:node
3008 name="address"
3009 indent="10"/>
3010 <data:node
3011 name="author"
3012 indent="9"/>
3013 <data:node
3014 name="authors"
3015 indent="10"/>
3016 <data:node
3017 name="contact"
3018 indent="10"/>
3019 <data:node
3020 name="copyright"
3021 indent="12"/>
3022 <data:node
3023 name="date"
3024 indent="7"/>
3025 <data:node
3026 name="organization"
3027 indent="15"/>
3028 <data:node
3029 name="revision"
3030 indent="11"/>
3031 <data:node
3032 name="status"
3033 indent="9"/>
3034 <data:node
3035 name="version"
3036 indent="10"/>
3037 <!-- This is only for `bullet_list/list_item';
3038 `enumerated_list/list_item' is handled special -->
3039 <data:node
3040 name="list_item"
3041 indent="2"/>
3042 <data:node
3043 name="definition_list_item"
3044 indent="4"/>
3045 <data:node
3046 name="field_body"
3047 indent="4"/>
3048 <data:node
3049 name="option_list_item"
3050 indent="4"/>
3051 <!-- This is also the indentation if block_quote comes as one of the
3052 special directives -->
3053 <data:node
3054 name="block_quote"
3055 indent="4"/>
3056 <data:node
3057 name="literal_block"
3058 indent="4"/>
3059 <data:node
3060 name="attribution"
3061 indent="3"/>
3062 <data:node
3063 name="line"
3064 indent="2"/>
3065 </data:lookup>
3067 <!-- Do indent according to ancestor -->
3068 <xsl:template
3069 name="u:indent">
3070 <!-- In some cases the ancestors to indent for need to be determined
3071 by the calling template -->
3072 <xsl:param
3073 name="ancestors"
3074 select="ancestor::*"/>
3075 <xsl:for-each
3076 select="$ancestors">
3077 <xsl:variable
3078 name="this"
3079 select="name()"/>
3080 <xsl:choose>
3081 <xsl:when
3082 test="contains($directives, concat('*', $this, '*'))">
3083 <!-- TODO Indentation of lines after some directives must be
3084 indented to align with the directive instead of a
3085 fixed indentation; however, this is rather complicated
3086 since identation for parameters should be fixed -->
3087 <xsl:value-of
3088 select="str:padding(3)"/>
3089 </xsl:when>
3090 <xsl:when
3091 test="$this = 'list_item' and parent::enumerated_list">
3092 <!-- Enumerated list items base their indentation on the
3093 numeration -->
3094 <xsl:variable
3095 name="enumerator">
3096 <xsl:call-template
3097 name="u:outputEnumerator"/>
3098 </xsl:variable>
3099 <xsl:value-of
3100 select="str:padding(string-length($enumerator))"/>
3101 </xsl:when>
3102 <xsl:otherwise>
3103 <xsl:value-of
3104 select="str:padding(document('')//data:lookup/data:node[@name=$this]/@indent)"/>
3105 </xsl:otherwise>
3106 </xsl:choose>
3107 </xsl:for-each>
3108 </xsl:template>
3110 <!-- ******************************************************************** -->
3112 <!-- Indent a text containing line feeds correctly -->
3113 <xsl:template
3114 name="u:indentLF">
3115 <xsl:param
3116 name="string"
3117 select="."/>
3118 <!-- A fixed indentation may be given by caller -->
3119 <xsl:param
3120 name="indent">
3121 <!-- If not given compute it -->
3122 <xsl:call-template
3123 name="u:indent"/>
3124 </xsl:param>
3125 <xsl:param
3126 name="literal"
3127 select="false()"/>
3128 <xsl:value-of
3129 select="rst:plain($string, $indent, $literal)"/>
3130 </xsl:template>
3132 <!-- ******************************************************************** -->
3134 <!-- Do output for those elements which do fold their inline content -->
3135 <xsl:template
3136 name="u:outputFolding">
3137 <!-- The prefix text to be output before the body -->
3138 <xsl:param
3139 name="prefix"
3140 select="''"/>
3141 <!-- The indentation for this body -->
3142 <xsl:param
3143 name="indent">
3144 <xsl:call-template
3145 name="u:indent">
3146 <xsl:with-param
3147 name="ancestors"
3148 select="ancestor-or-self::*"/>
3149 </xsl:call-template>
3150 </xsl:param>
3151 <xsl:variable
3152 name="string">
3153 <!-- TODO Whitespace count of inline literals must be preserved -->
3154 <xsl:apply-templates/>
3155 </xsl:variable>
3156 <!-- Always output prefix with all trailing and leading spaces -->
3157 <xsl:value-of
3158 select="$prefix"/>
3159 <xsl:choose>
3160 <xsl:when
3161 test="$fold &gt; 0">
3162 <xsl:variable
3163 name="normalized"
3164 select="normalize-space($string)"/>
3165 <xsl:choose>
3166 <xsl:when
3167 test="$string = ''">
3168 <!-- Empty strings need no output -->
3169 </xsl:when>
3170 <xsl:when
3171 test="$normalized = ''">
3172 <!-- Only white-space in string; output a single space here -->
3173 &tSP;
3174 </xsl:when>
3175 <xsl:otherwise>
3176 <!-- Output leading white-space here -->
3177 <xsl:if
3178 test="normalize-space(substring($string, 1, 1)) = ''">
3179 &tSP;
3180 </xsl:if>
3181 <xsl:call-template
3182 name="u:indentFold">
3183 <xsl:with-param
3184 name="string"
3185 select="$normalized"/>
3186 <xsl:with-param
3187 name="indent"
3188 select="$indent"/>
3189 <xsl:with-param
3190 name="cursorColumn"
3191 select="string-length($indent) + string-length($prefix)"/>
3192 </xsl:call-template>
3193 <!-- Output trailing white-space here -->
3194 <xsl:if
3195 test="normalize-space(substring($string, string-length($string), 1)) = ''">
3196 &tSP;
3197 </xsl:if>
3198 </xsl:otherwise>
3199 </xsl:choose>
3200 </xsl:when>
3201 <xsl:otherwise>
3202 <xsl:value-of
3203 select="$string"/>
3204 </xsl:otherwise>
3205 </xsl:choose>
3206 &tEOL;
3207 </xsl:template>
3209 <!-- ******************************************************************** -->
3211 <!-- Indent a string with folding -->
3212 <xsl:template
3213 name="u:indentFold">
3214 <!-- Normalized string to output -->
3215 <xsl:param
3216 name="string"/>
3217 <!-- Indentation to use for a new line -->
3218 <xsl:param
3219 name="indent"/>
3220 <!-- Current output column -->
3221 <!-- TODO This is not a correct assumption for field definitions where
3222 the field name effectively determines the column of the first
3223 line -->
3224 <xsl:param
3225 name="cursorColumn"
3226 select="string-length($indent)"/>
3227 <!-- Do we start on a new (indented) line? -->
3228 <xsl:param
3229 name="isNewLine"
3230 select="true()"/>
3231 <xsl:variable
3232 name="firstWord">
3233 <xsl:choose>
3234 <!-- TODO Quoted spaces must not end a word -->
3235 <xsl:when
3236 test="contains($string, ' ')">
3237 <xsl:value-of
3238 select="substring-before($string, ' ')"/>
3239 </xsl:when>
3240 <xsl:otherwise>
3241 <xsl:value-of
3242 select="$string"/>
3243 </xsl:otherwise>
3244 </xsl:choose>
3245 </xsl:variable>
3246 <xsl:variable
3247 name="rest"
3248 select="substring-after($string, ' ')"/>
3249 <xsl:choose>
3250 <xsl:when
3251 test="$string = ''"/>
3252 <xsl:when
3253 test="$isNewLine">
3254 <!-- Output at least first word -->
3255 <xsl:value-of
3256 select="$firstWord"/>
3257 <xsl:call-template
3258 name="u:indentFold">
3259 <xsl:with-param
3260 name="string"
3261 select="$rest"/>
3262 <xsl:with-param
3263 name="indent"
3264 select="$indent"/>
3265 <xsl:with-param
3266 name="cursorColumn"
3267 select="$cursorColumn + string-length($firstWord)"/>
3268 <xsl:with-param
3269 name="isNewLine"
3270 select="false()"/>
3271 </xsl:call-template>
3272 </xsl:when>
3273 <xsl:when
3274 test="$cursorColumn + 1 + string-length($firstWord) &gt; $fold">
3275 <!-- Line would get too long; start new line, indent and continue -->
3276 &tEOL;
3277 <xsl:value-of
3278 select="$indent"/>
3279 <xsl:call-template
3280 name="u:indentFold">
3281 <xsl:with-param
3282 name="string"
3283 select="$string"/>
3284 <xsl:with-param
3285 name="indent"
3286 select="$indent"/>
3287 <xsl:with-param
3288 name="cursorColumn"
3289 select="string-length($indent)"/>
3290 <xsl:with-param
3291 name="isNewLine"
3292 select="true()"/>
3293 </xsl:call-template>
3294 </xsl:when>
3295 <xsl:otherwise>
3296 <!-- In a line and first word fits; separate and add word -->
3297 &tSP;
3298 <xsl:value-of
3299 select="$firstWord"/>
3300 <xsl:call-template
3301 name="u:indentFold">
3302 <xsl:with-param
3303 name="string"
3304 select="$rest"/>
3305 <xsl:with-param
3306 name="indent"
3307 select="$indent"/>
3308 <xsl:with-param
3309 name="cursorColumn"
3310 select="$cursorColumn + 1 + string-length($firstWord)"/>
3311 <xsl:with-param
3312 name="isNewLine"
3313 select="false()"/>
3314 </xsl:call-template>
3315 </xsl:otherwise>
3316 </xsl:choose>
3317 </xsl:template>
3319 <!-- ******************************************************************** -->
3321 <!-- Output attributes of the current element as a field list -->
3322 <xsl:template
3323 name="u:params">
3324 <xsl:param
3325 name="params"
3326 select="@*"/>
3327 <!-- Ancestors are needed for determining indentation; caller may give
3328 them -->
3329 <xsl:param
3330 name="ancestors"
3331 select="ancestor-or-self::*"/>
3332 <xsl:for-each
3333 select="$params">
3334 <!-- Skip URIs based on parent -->
3335 <xsl:if
3336 test="name() != 'uri' and name() != 'xml:space'">
3337 <xsl:call-template
3338 name="u:param">
3339 <xsl:with-param
3340 name="ancestors"
3341 select="$ancestors"/>
3342 </xsl:call-template>
3343 </xsl:if>
3344 </xsl:for-each>
3345 </xsl:template>
3347 <!-- Output one attribute of the current element as a field list -->
3348 <xsl:template
3349 name="u:param">
3350 <xsl:param
3351 name="name"
3352 select="name()"/>
3353 <xsl:param
3354 name="value"
3355 select="."/>
3356 <!-- Ancestors are needed for determining indentation; caller may give
3357 them -->
3358 <xsl:param
3359 name="ancestors"
3360 select="ancestor::*"/>
3361 <xsl:call-template
3362 name="u:indent">
3363 <xsl:with-param
3364 name="ancestors"
3365 select="$ancestors"/>
3366 </xsl:call-template>
3367 <xsl:text>:</xsl:text>
3368 <xsl:choose>
3369 <xsl:when
3370 test="$name = 'classes'">
3371 <xsl:text>class</xsl:text>
3372 </xsl:when>
3373 <xsl:otherwise>
3374 <xsl:value-of
3375 select="$name"/>
3376 </xsl:otherwise>
3377 </xsl:choose>
3378 <xsl:text>:</xsl:text>
3379 <xsl:if
3380 test="$value">
3381 <xsl:text> </xsl:text>
3382 <xsl:value-of
3383 select="$value"/>
3384 </xsl:if>
3385 &tEOL;
3386 </xsl:template>
3388 <!-- ******************************************************************** -->
3390 <!-- Output `\' or `\ ' before some inline element if necessary -->
3391 <xsl:template
3392 name="u:bkslshEscPre">
3393 <!-- Get the sibling node directly before the current element -->
3394 <xsl:variable
3395 name="before"
3396 select="preceding-sibling::node()[1]"/>
3397 <xsl:choose>
3398 <!-- No sibling before this node -->
3399 <xsl:when
3400 test="not($before)"/>
3401 <!-- Element directly before this - must be another inline element -->
3402 <xsl:when
3403 test="name($before)">
3404 <!-- So separate it by a quoted space -->
3405 <xsl:text>\ </xsl:text>
3406 </xsl:when>
3407 <!-- Node directly before this is text - check it -->
3408 <xsl:when
3409 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;([{&lt;-/:'), substring($before, string-length($before), 1)))">
3410 <!-- Does not end in one of the allowed characters so separate it -->
3411 <xsl:text>\ </xsl:text>
3412 </xsl:when>
3413 </xsl:choose>
3414 </xsl:template>
3416 <!-- Output `\' after some inline element if necessary -->
3417 <xsl:template
3418 name="u:bkslshEscSuf">
3419 <!-- Get the sibling node directly after the current element -->
3420 <xsl:variable
3421 name="after"
3422 select="following-sibling::node()[1]"/>
3423 <xsl:choose>
3424 <!-- No sibling after this node -->
3425 <xsl:when
3426 test="not($after)"/>
3427 <!-- Element directly after this - must be another inline element
3428 handling itself -->
3429 <xsl:when
3430 test="name($after)"/>
3431 <!-- Node directly after this is text - check it -->
3432 <xsl:when
3433 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;)]}&gt;-/:.,;!?\'), substring($after, 1, 1)))">
3434 <!-- Does not start with one of the allowed characters so separate
3435 it -->
3436 <xsl:text>\</xsl:text>
3437 </xsl:when>
3438 </xsl:choose>
3439 </xsl:template>
3441 <!-- ******************************************************************** -->
3443 <xsl:template
3444 name="u:notSupported">
3445 <xsl:call-template
3446 name="u:BandI"/>
3447 <xsl:text>######## NOT SUPPORTED: `</xsl:text>
3448 <xsl:value-of
3449 select="name(.)"/>
3450 <xsl:text>' ########</xsl:text>
3451 &tEOL;
3452 </xsl:template>
3454 <!-- ******************************************************************** -->
3456 <xsl:template
3457 name="u:overline">
3458 <!-- Length of the rendered(!) text -->
3459 <xsl:param
3460 name="length"/>
3461 <!-- Depth 1 and 2 are document title and subtitle while depths
3462 greater than 2 are normal section titles -->
3463 <xsl:param
3464 name="depth"/>
3465 <!-- Test whether a overline is wanted at all -->
3466 <xsl:if
3467 test="substring($adornment, 2 * ($depth - 1) + 1, 1) = 'o'">
3468 <xsl:value-of
3469 select="str:padding($length, substring($adornment, 2 * ($depth - 1) + 2, 1))"/>
3470 &tEOL;
3471 </xsl:if>
3472 </xsl:template>
3474 <xsl:template
3475 name="u:underline">
3476 <!-- Length of the rendered(!) text -->
3477 <xsl:param
3478 name="length"/>
3479 <!-- Depth 1 and 2 are document title and subtitle while depths
3480 greater than 2 are normal section titles -->
3481 <xsl:param
3482 name="depth"/>
3483 <xsl:value-of
3484 select="str:padding($length, substring($adornment, 2 * ($depth - 1) + 2, 1))"/>
3485 &tEOL;
3486 </xsl:template>
3488 <!-- ******************************************************************** -->
3490 <!-- Output a non-standalone reference or target -->
3491 <xsl:template
3492 name="u:inlineReference">
3493 <xsl:param
3494 name="anonymous"
3495 select="false()"/>
3496 <xsl:param
3497 name="embedded"
3498 select="false()"/>
3499 <!-- Is this a target instead of a reference? -->
3500 <xsl:param
3501 name="isTarget"
3502 select="false()"/>
3503 <xsl:param
3504 name="text"
3505 select="node()"/>
3506 <xsl:call-template
3507 name="u:bkslshEscPre"/>
3508 <!-- Delimiter only if link contains other than alphanumerics -->
3509 <xsl:variable
3510 name="delimiter">
3511 <xsl:if
3512 test="* or translate($text, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '') or $embedded">
3513 <xsl:text>`</xsl:text>
3514 </xsl:if>
3515 </xsl:variable>
3516 <xsl:if
3517 test="$isTarget">
3518 <xsl:text>_</xsl:text>
3519 </xsl:if>
3520 <xsl:value-of
3521 select="$delimiter"/>
3522 <xsl:apply-templates
3523 select="$text"/>
3524 <xsl:if
3525 test="$embedded">
3526 <xsl:text> &lt;</xsl:text>
3527 <xsl:value-of
3528 select="@refuri"/>
3529 <xsl:text>&gt;</xsl:text>
3530 </xsl:if>
3531 <xsl:value-of
3532 select="$delimiter"/>
3533 <xsl:if
3534 test="not($isTarget)">
3535 <xsl:text>_</xsl:text>
3536 <xsl:if
3537 test="$anonymous">
3538 <xsl:text>_</xsl:text>
3539 </xsl:if>
3540 </xsl:if>
3541 <xsl:call-template
3542 name="u:bkslshEscSuf"/>
3543 </xsl:template>
3545 <!-- ******************************************************************** -->
3547 <!-- Output a class directive for the directly following element. -->
3548 <!-- TODO A class directive can also be used as a container putting the
3549 respective attribute to its content; however, this is not
3550 reflected in XML - you'd need to check a sequence of elements
3551 whether they all have the same attribute; furthermore class
3552 settings for block quotes needs to be treated special -->
3553 <xsl:template
3554 name="u:outputClass">
3555 <!-- Blank line already output? -->
3556 <xsl:param
3557 name="alreadyBlanked"
3558 select="false()"/>
3559 <!-- Indentation already output? -->
3560 <xsl:param
3561 name="alreadyIndented"
3562 select="false()"/>
3563 <!-- Add a blank line after class directive? -->
3564 <xsl:param
3565 name="blankAfter"
3566 select="false()"/>
3567 <xsl:if
3568 test="@classes">
3569 <xsl:if
3570 test="not($alreadyBlanked)">
3571 <xsl:call-template
3572 name="u:blank"/>
3573 </xsl:if>
3574 <xsl:if
3575 test="not($alreadyIndented)">
3576 <xsl:call-template
3577 name="u:indent"/>
3578 </xsl:if>
3579 <xsl:text>.. class:: </xsl:text>
3580 <xsl:value-of
3581 select="@classes"/>
3582 &tEOL;
3583 <xsl:if
3584 test="$blankAfter">
3585 &tCR;
3586 </xsl:if>
3587 </xsl:if>
3588 </xsl:template>
3590 <!-- ******************************************************************** -->
3592 <!-- Output a names attribute at index considering quoted spaces. -->
3593 <xsl:template
3594 name="u:outputNames">
3595 <!-- Blank line already output? -->
3596 <xsl:param
3597 name="names"
3598 select="@names"/>
3599 <xsl:param
3600 name="index"
3601 select="0"/>
3602 <xsl:value-of
3603 select="str:replace(str:tokenize(normalize-space(str:replace($names, '\ ', '|')))[position() = $index + 1], '|', ' ')"/>
3604 </xsl:template>
3606 <!-- ******************************************************************** -->
3608 <!-- Output a names attribute for a refid. -->
3609 <xsl:template
3610 name="u:outputNamesRefid">
3611 <xsl:param
3612 name="refid"
3613 select="@refid"/>
3614 <!-- Determine the elements which is referred -->
3615 <xsl:variable
3616 name="refElem"
3617 select="//*[@ids and math:max(dyn:map(str:tokenize(normalize-space(@ids)), 'number($refid = .)')) > 0]"/>
3618 <xsl:call-template
3619 name="u:outputNames">
3620 <xsl:with-param
3621 name="names"
3622 select="$refElem/@names"/>
3623 <xsl:with-param
3624 name="index"
3625 select="math:max(dyn:map(str:tokenize(normalize-space($refElem/@ids)), 'number($refid = .) * position() - 1'))"/>
3626 </xsl:call-template>
3627 </xsl:template>
3629 <!-- ******************************************************************** -->
3630 <!-- ******************************************************************** -->
3632 <!-- Report unknown tags -->
3633 <xsl:template
3634 match="*">
3635 <xsl:message>
3636 <xsl:text>`</xsl:text>
3637 <xsl:value-of
3638 select="name(.)"/>
3639 <xsl:text>' encountered</xsl:text>
3640 <xsl:if
3641 test="parent::*">
3642 <xsl:text> in `</xsl:text>
3643 <xsl:value-of
3644 select="name(parent::*)"/>
3645 <xsl:text>'</xsl:text>
3646 </xsl:if>
3647 <xsl:text>, but no template matches.</xsl:text>
3648 </xsl:message>
3649 </xsl:template>
3651 </xsl:stylesheet>