Add support for `imenu` and `which-func-mode`. Remember setting
[docutils/kirr.git] / sandbox / xml2rst / rst / xml2rst.xsl
blob7c34db5997966f09382e687c5484a98bf7f8c16b
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:call-template
1863 name="u:BandI"/>
1864 <xsl:value-of
1865 select="../@bullet"/>
1866 &tSP; <!-- space after bullet -->
1867 <xsl:apply-templates/>
1868 </xsl:template>
1870 <!-- ******************************************************************** -->
1872 <!--
1873 ENUMERATED LIST
1874 enumtype is used to record the intended enumeration sequence, one of
1875 "arabic" (1, 2, 3, ...), "loweralpha" (a, b, c, ..., z), "upperalpha" (A, B,
1876 C, ..., Z), "lowerroman" (i, ii, iii, iv, ..., mmmmcmxcix [4999]), or
1877 "upperroman" (I, II, III, IV, ..., MMMMCMXCIX [4999]).
1878 prefix stores the formatting characters used before the enumerator. In
1879 documents originating from reStructuredText data, it will contain either ""
1880 (empty string) or "(" (left parenthesis). It may or may not affect
1881 processing.
1882 suffix stores the formatting characters used after the enumerator. In
1883 documents originating from reStructuredText data, it will contain either "."
1884 (period) or ")" (right parenthesis). Depending on the capabilities of the
1885 output format, this attribute may or may not affect processing.
1886 start contains the ordinal value of the first item in the list, in
1887 decimal. For lists beginning at value 1 ("1", "a", "A", "i", or "I"), this
1888 attribute may be omitted.
1891 <!-- == compound_body_subelement -->
1892 <xsl:template
1893 match="list_item"
1894 mode="enumerated_list">
1895 <xsl:call-template
1896 name="u:outputClass"/>
1897 <xsl:call-template
1898 name="u:BandI"/>
1899 <xsl:call-template
1900 name="u:outputEnumerator"/>
1901 <xsl:apply-templates/>
1902 </xsl:template>
1904 <!-- Outputs a complete enumerator when called in an
1905 enumerated_list/list_item -->
1906 <xsl:template
1907 name="u:outputEnumerator">
1908 <!-- Use parent's numeration attribute -->
1909 <xsl:variable
1910 name="enumType"
1911 select="../@enumtype"/>
1912 <!-- Determine starting point -->
1913 <xsl:variable
1914 name="start">
1915 <xsl:choose>
1916 <xsl:when
1917 test="../@start">
1918 <xsl:value-of
1919 select="../@start"/>
1920 </xsl:when>
1921 <xsl:otherwise>
1922 <xsl:value-of
1923 select="1"/>
1924 </xsl:otherwise>
1925 </xsl:choose>
1926 </xsl:variable>
1927 <!-- Determine position of this item in its real context -->
1928 <xsl:variable
1929 name="position">
1930 <xsl:variable
1931 name="wanted"
1932 select="generate-id()"/>
1933 <!-- Generate the right current node list -->
1934 <xsl:for-each
1935 select="../list_item">
1936 <xsl:if
1937 test="generate-id() = $wanted">
1938 <xsl:value-of
1939 select="position()"/>
1940 </xsl:if>
1941 </xsl:for-each>
1942 </xsl:variable>
1943 <!-- Determine encoding of the number for the given numeration -->
1944 <xsl:variable
1945 name="cur">
1946 <xsl:call-template
1947 name="u:position2Enumerator">
1948 <xsl:with-param
1949 name="enumType"
1950 select="$enumType"/>
1951 <xsl:with-param
1952 name="position"
1953 select="$position"/>
1954 <xsl:with-param
1955 name="start"
1956 select="$start"/>
1957 </xsl:call-template>
1958 </xsl:variable>
1959 <!-- Determine encoding of the maximum number -->
1960 <xsl:variable
1961 name="max">
1962 <xsl:call-template
1963 name="u:position2Enumerator">
1964 <xsl:with-param
1965 name="enumType"
1966 select="$enumType"/>
1967 <xsl:with-param
1968 name="position"
1969 select="count(../list_item)"/>
1970 <xsl:with-param
1971 name="start"
1972 select="$start"/>
1973 </xsl:call-template>
1974 </xsl:variable>
1975 <!-- Output complete enumerator -->
1976 <xsl:value-of
1977 select="../@prefix"/>
1978 <xsl:value-of
1979 select="$cur"/>
1980 <xsl:value-of
1981 select="../@suffix"/>
1982 <!-- Output at least one trailing space -->
1983 &tSP;
1984 <!-- Output more whitespace to align with the maximum enumerator -->
1985 <xsl:if
1986 test="$enumType != 'lowerroman' and $enumType != 'upperroman'">
1987 <!-- Assumes that the maximum number has maximum string length -->
1988 <xsl:value-of
1989 select="str:padding(string-length($max) - string-length($cur))"/>
1990 </xsl:if>
1991 </xsl:template>
1993 <!-- Determine the right ordinal enumerator based on the parameters -->
1994 <xsl:template
1995 name="u:position2Enumerator">
1996 <xsl:param
1997 name="enumType"/>
1998 <xsl:param
1999 name="start"/>
2000 <xsl:param
2001 name="position"/>
2002 <!-- Determine logical number -->
2003 <xsl:variable
2004 name="ordinal"
2005 select="$start - 1 + $position"/>
2006 <xsl:choose>
2007 <xsl:when
2008 test="$enumType = 'arabic'">
2009 <xsl:value-of
2010 select="$ordinal"/>
2011 </xsl:when>
2012 <xsl:when
2013 test="$enumType = 'loweralpha'">
2014 <xsl:value-of
2015 select="substring('abcdefghijklmnopqrstzuvwxyz', $ordinal, 1)"/>
2016 </xsl:when>
2017 <xsl:when
2018 test="$enumType = 'upperalpha'">
2019 <xsl:value-of
2020 select="substring('ABCDEFGHIJKLMNOPQRSTZUVWXYZ', $ordinal, 1)"/>
2021 </xsl:when>
2022 <!-- TODO Support for counting roman numbers -->
2023 <xsl:when
2024 test="$enumType = 'lowerroman'">
2025 <xsl:text>i</xsl:text>
2026 </xsl:when>
2027 <xsl:when
2028 test="$enumType = 'upperroman'">
2029 <xsl:text>I</xsl:text>
2030 </xsl:when>
2031 </xsl:choose>
2032 </xsl:template>
2034 <!-- ******************************************************************** -->
2035 <!-- ******************************************************************** -->
2037 <!--
2038 Content Model: (title?, tgroup+)
2039 Attributes: The table element contains the common attributes and:
2040 frame, colsep, rowsep, pgwide
2042 <!-- == compound_body_element -->
2043 <xsl:template
2044 match="table">
2045 <xsl:call-template
2046 name="u:outputClass"/>
2047 <xsl:call-template
2048 name="u:blank"/>
2049 <xsl:apply-templates
2050 select="tgroup"/>
2051 <xsl:if
2052 test="title">
2053 <!-- TODO A table title must be rendered by using the `.. table::'
2054 directive -->
2055 <xsl:call-template
2056 name="u:BandI"/>
2057 <xsl:apply-templates
2058 select="title"/>
2059 &tEOL;
2060 </xsl:if>
2061 </xsl:template>
2063 <!-- ******************************************************************** -->
2065 <!--
2066 Content Model: (colspec*, thead?, tbody)
2067 Attributes: The tgroup element contains the common attributes and:
2068 cols, colsep, rowsep, align
2070 <!-- == compound_body_subelement -->
2071 <xsl:template
2072 match="tgroup">
2073 <xsl:apply-templates/>
2074 </xsl:template>
2076 <!-- ******************************************************************** -->
2078 <!--
2079 Content Model: EMPTY
2080 Attributes: The colspec element contains the common attributes and:
2081 colnum, colname, colwidth, colsep, rowsep, align, char, charoff
2083 The colwidth attribute gives the width of the respective column in characters
2084 including padding whitespace but no separator markup.
2086 <!-- == simple_body_subelement -->
2087 <!-- @colwidth needed by children but element has no own output -->
2088 <xsl:template
2089 match="colspec"/>
2091 <!-- ******************************************************************** -->
2093 <!--
2094 Content Model: (row+)
2095 Attributes: The thead element contains the common attributes and:
2096 valign
2098 <!-- == compound_body_subelement -->
2099 <xsl:template
2100 match="thead">
2101 <xsl:apply-templates/>
2102 </xsl:template>
2104 <!--
2105 Content Model: (row+)
2106 Attributes: The tbody element contains the common attributes and:
2107 valign
2109 <!-- == compound_body_subelement -->
2110 <xsl:template
2111 match="tbody">
2112 <xsl:apply-templates/>
2113 </xsl:template>
2115 <!-- ******************************************************************** -->
2117 <!--
2118 Content Model: (entry+)
2119 Attributes: The row element contains the common attributes and:
2120 rowsep, valign
2122 <!-- == compound_body_subelement -->
2123 <xsl:template
2124 match="row">
2125 <!-- Separator line above unless first row of a tbody with no previous
2126 thead (in this case the separator line is output already as the
2127 closing separator line of thead) -->
2128 <xsl:if
2129 test="position() > 1 or parent::thead or parent::tbody and not(../../thead)">
2130 <xsl:call-template
2131 name="u:rowSeparatorLine"/>
2132 </xsl:if>
2133 <!-- Determine heights in physical lines of all entries -->
2134 <xsl:variable
2135 name="heights">
2136 <xsl:for-each
2137 select="entry">
2138 <xsl:variable
2139 name="text">
2140 <!-- Catch the text of all entries -->
2141 <xsl:apply-templates/>
2142 </xsl:variable>
2143 <!-- Compute height of this entry; leading and trailing EOL must be
2144 subtracted -->
2145 <xsl:value-of
2146 select="string-length($text) - string-length(translate($text, '&#xA;', '')) - 1"/>
2147 &tSP; <!-- A space as a list separator -->
2148 </xsl:for-each>
2149 </xsl:variable>
2150 <!-- Determine maximum height so every entry must be this high -->
2151 <xsl:variable
2152 name="maxHeight"
2153 select="math:max(str:tokenize(normalize-space($heights)))"/>
2154 <!-- Output all the physical lines of this row -->
2155 <xsl:call-template
2156 name="u:rowLines">
2157 <xsl:with-param
2158 name="currentLine"
2159 select="1"/>
2160 <xsl:with-param
2161 name="maxLine"
2162 select="$maxHeight"/>
2163 </xsl:call-template>
2164 <!-- Output final separator line if this is the last row -->
2165 <xsl:if
2166 test="position() = last()">
2167 <xsl:call-template
2168 name="u:rowSeparatorLine">
2169 <xsl:with-param
2170 name="char">
2171 <!-- Determine correct character for the separator line -->
2172 <xsl:choose>
2173 <xsl:when
2174 test="parent::thead">
2175 <xsl:value-of
2176 select="'='"/>
2177 </xsl:when>
2178 <xsl:otherwise>
2179 <xsl:value-of
2180 select="'-'"/>
2181 </xsl:otherwise>
2182 </xsl:choose>
2183 </xsl:with-param>
2184 </xsl:call-template>
2185 </xsl:if>
2186 </xsl:template>
2188 <!-- Output physical line $currentLine of a row and continue until
2189 line $maxLine is output -->
2190 <xsl:template
2191 name="u:rowLines">
2192 <xsl:param
2193 name="currentLine"/>
2194 <xsl:param
2195 name="maxLine"/>
2196 <xsl:if
2197 test="$currentLine &lt;= $maxLine">
2198 <!-- If there are still physical lines to output do it -->
2199 <xsl:call-template
2200 name="u:indent"/>
2201 <!-- Leading bar -->
2202 <xsl:text>|</xsl:text>
2203 <xsl:apply-templates>
2204 <xsl:with-param
2205 name="currentLine"
2206 select="$currentLine"/>
2207 </xsl:apply-templates>
2208 <!-- End of this physical line -->
2209 &tEOL;
2210 <!-- Continue with the next physical line -->
2211 <xsl:call-template
2212 name="u:rowLines">
2213 <xsl:with-param
2214 name="currentLine"
2215 select="$currentLine + 1"/>
2216 <xsl:with-param
2217 name="maxLine"
2218 select="$maxLine"/>
2219 </xsl:call-template>
2220 </xsl:if>
2221 </xsl:template>
2223 <!-- Output a separator line with all the right characters -->
2224 <xsl:template
2225 name="u:rowSeparatorLine">
2226 <xsl:param
2227 name="char"
2228 select="'-'"/>
2229 <xsl:call-template
2230 name="u:indent"/>
2231 <xsl:text>+</xsl:text>
2232 <xsl:for-each
2233 select="../../colspec">
2234 <xsl:value-of
2235 select="str:padding(@colwidth, $char)"/>
2236 <xsl:text>+</xsl:text>
2237 </xsl:for-each>
2238 &tEOL;
2239 </xsl:template>
2241 <!-- ******************************************************************** -->
2243 <!--
2244 Content Model: (%body.elements;)*
2245 Attributes: The entry element contains the common attributes and:
2246 colname, namest, morerows, colsep, rowsep, align, char, charoff, valign and
2247 morecols
2249 <!-- == compound_body_subelement -->
2250 <xsl:template
2251 match="entry">
2252 <!-- TODO `classes` attribute needs support -->
2253 <!-- This is called in two ways; if $currentLine = 0 all physical lines
2254 of this entry must be output; if $currentLine > 0 the physical line
2255 with exactly this number shall be output -->
2256 <xsl:param
2257 name="currentLine"
2258 select="0"/>
2259 <xsl:variable
2260 name="column"
2261 select="position() + sum(preceding-sibling::entry/@morecols)"/>
2262 <!-- Determine width in characters needed for this entry -->
2263 <xsl:variable
2264 name="width">
2265 <xsl:call-template
2266 name="u:computeEntryWidth">
2267 <xsl:with-param
2268 name="colspecs"
2269 select="../../../colspec"/>
2270 <xsl:with-param
2271 name="column"
2272 select="$column"/>
2273 <xsl:with-param
2274 name="span"
2275 select="@morecols"/>
2276 </xsl:call-template>
2277 </xsl:variable>
2278 <!-- Output the entry completely or a certain physical line -->
2279 <xsl:call-template
2280 name="u:outputEntry">
2281 <xsl:with-param
2282 name="string">
2283 <!-- Capture physical lines of the entry in a variable -->
2284 <xsl:apply-templates/>
2285 </xsl:with-param>
2286 <xsl:with-param
2287 name="width"
2288 select="$width"/>
2289 <xsl:with-param
2290 name="expectedIndent">
2291 <!-- Capture indent for the entry generated by the normal template
2292 rules to remove it later -->
2293 <xsl:call-template
2294 name="u:indent"/>
2295 </xsl:with-param>
2296 <xsl:with-param
2297 name="outputLine"
2298 select="$currentLine"/>
2299 </xsl:call-template>
2300 <!-- Final bar after the entry -->
2301 <xsl:text>|</xsl:text>
2302 </xsl:template>
2304 <!-- Compute width of the entry -->
2305 <xsl:template
2306 name="u:computeEntryWidth">
2307 <!-- The colspec elements of all columns -->
2308 <xsl:param
2309 name="colspecs"/>
2310 <!-- Column of this entry -->
2311 <xsl:param
2312 name="column"/>
2313 <!-- Number of columns this entry spans -->
2314 <xsl:param
2315 name="span"
2316 select="0"/>
2317 <xsl:param
2318 name="sum"
2319 select="0"/>
2320 <xsl:choose>
2321 <xsl:when
2322 test="$span">
2323 <!-- If entry spans multiple columns compute their width -->
2324 <xsl:call-template
2325 name="u:computeEntryWidth">
2326 <xsl:with-param
2327 name="colspecs"
2328 select="$colspecs"/>
2329 <xsl:with-param
2330 name="column"
2331 select="$column + 1"/>
2332 <xsl:with-param
2333 name="span"
2334 select="$span - 1"/>
2335 <!-- Add the separator character and the following column width -->
2336 <xsl:with-param
2337 name="sum"
2338 select="$sum + 1 + $colspecs[$column]/@colwidth"/>
2339 </xsl:call-template>
2340 </xsl:when>
2341 <xsl:otherwise>
2342 <!-- Does not span more columns so return sum and width of this
2343 column -->
2344 <xsl:value-of
2345 select="$sum + $colspecs[$column]/@colwidth"/>
2346 </xsl:otherwise>
2347 </xsl:choose>
2348 </xsl:template>
2350 <!-- Outputs one or all lines of a table entry as a string trimmed left and
2351 padded -->
2352 <xsl:template
2353 name="u:outputEntry">
2354 <!-- Width of the entry; there is no provision for actual physical lines
2355 longer than this width -->
2356 <xsl:param
2357 name="width"/>
2358 <!-- The string containing the remaining physical lines; may be an empty
2359 string -->
2360 <xsl:param
2361 name="string"
2362 select="''"/>
2363 <!-- The indendation which is expected to be prefixed before every
2364 physical line -->
2365 <xsl:param
2366 name="expectedIndent"
2367 select="''"/>
2368 <!-- Is this the first call to this template -->
2369 <xsl:param
2370 name="isFirst"
2371 select="true()"/>
2372 <!-- Number of physical line to output or 0 to output all lines -->
2373 <xsl:param
2374 name="outputLine"
2375 select="0"/>
2376 <!-- Output is wanted if all or the first physical line are to be
2377 output -->
2378 <xsl:variable
2379 name="doOutput"
2380 select="$outputLine = 0 or $outputLine = 1"/>
2381 <xsl:variable
2382 name="stringLFHalfTrimmed">
2383 <xsl:choose>
2384 <xsl:when
2385 test="$isFirst and substring($string, 1, 1) = '&#x0A;'">
2386 <!-- Remove leading linefeed if this is the first time -->
2387 <xsl:value-of
2388 select="substring($string, 2)"/>
2389 </xsl:when>
2390 <xsl:otherwise>
2391 <xsl:value-of
2392 select="$string"/>
2393 </xsl:otherwise>
2394 </xsl:choose>
2395 </xsl:variable>
2396 <xsl:variable
2397 name="stringLFTrimmed">
2398 <xsl:choose>
2399 <xsl:when
2400 test="$isFirst and substring($stringLFHalfTrimmed, string-length($stringLFHalfTrimmed), 1) = '&#x0A;'">
2401 <!-- Remove trailing linefeed if this is the first time -->
2402 <xsl:value-of
2403 select="substring($stringLFHalfTrimmed, 1, string-length($stringLFHalfTrimmed) - 1)"/>
2404 </xsl:when>
2405 <xsl:otherwise>
2406 <xsl:value-of
2407 select="$stringLFHalfTrimmed"/>
2408 </xsl:otherwise>
2409 </xsl:choose>
2410 </xsl:variable>
2411 <!-- Determine remaining lines after the first one -->
2412 <xsl:variable
2413 name="remainingLines">
2414 <xsl:if
2415 test="contains($stringLFTrimmed, '&#x0A;')">
2416 <xsl:value-of
2417 select="substring-after($stringLFTrimmed, '&#x0A;')"/>
2418 </xsl:if>
2419 </xsl:variable>
2420 <xsl:if
2421 test="$doOutput">
2422 <!-- If this physical line must be output determine the first physical
2423 line -->
2424 <xsl:variable
2425 name="firstLine">
2426 <xsl:choose>
2427 <xsl:when
2428 test="string-length($remainingLines)">
2429 <xsl:value-of
2430 select="substring-before($stringLFTrimmed, '&#x0A;')"/>
2431 </xsl:when>
2432 <xsl:otherwise>
2433 <xsl:value-of
2434 select="$stringLFTrimmed"/>
2435 </xsl:otherwise>
2436 </xsl:choose>
2437 </xsl:variable>
2438 <!-- Remove the leading indentation from the physical line which is
2439 brought there by the normal templates -->
2440 <xsl:variable
2441 name="trimmed">
2442 <xsl:if
2443 test="string-length($firstLine)">
2444 <!-- Trim only non-empty lines -->
2445 <xsl:value-of
2446 select="substring-after($firstLine, $expectedIndent)"/>
2447 </xsl:if>
2448 </xsl:variable>
2449 <!-- Pad the line with a leading and a trailing space -->
2450 <xsl:variable
2451 name="padded"
2452 select="concat(' ', $trimmed, ' ')"/>
2453 <!-- Output the padded value -->
2454 <xsl:value-of
2455 select="$padded"/>
2456 <!-- Fill up the width of the entry with spaces -->
2457 <xsl:if
2458 test="$width - string-length($padded) &lt; 0">
2459 <xsl:message>
2460 <xsl:text>WARNING: Table column too narrow (minimum: </xsl:text>
2461 <xsl:value-of
2462 select="string-length($padded)"/>
2463 <xsl:text>)</xsl:text>
2464 &tEOL;
2465 </xsl:message>
2466 </xsl:if>
2467 <xsl:value-of
2468 select="str:padding($width - string-length($padded))"/>
2469 </xsl:if>
2470 <xsl:if
2471 test="$outputLine > 1 or $outputLine = 0 and string-length($remainingLines)">
2472 <!-- If a following physical line must be output or if all physical
2473 lines shall be output and there are remaining physical lines -->
2474 <xsl:if
2475 test="$outputLine = 0">
2476 <!-- Output linefeed only if we output all the lines -->
2477 &tEOL;
2478 </xsl:if>
2479 <!-- Output the remaining lines -->
2480 <xsl:call-template
2481 name="u:outputEntry">
2482 <xsl:with-param
2483 name="width"
2484 select="$width"/>
2485 <xsl:with-param
2486 name="string"
2487 select="$remainingLines"/>
2488 <xsl:with-param
2489 name="expectedIndent"
2490 select="$expectedIndent"/>
2491 <xsl:with-param
2492 name="isFirst"
2493 select="false()"/>
2494 <xsl:with-param
2495 name="outputLine">
2496 <xsl:choose>
2497 <xsl:when
2498 test="$outputLine = 0">
2499 <xsl:value-of
2500 select="0"/>
2501 </xsl:when>
2502 <xsl:otherwise>
2503 <xsl:value-of
2504 select="$outputLine - 1"/>
2505 </xsl:otherwise>
2506 </xsl:choose>
2507 </xsl:with-param>
2508 </xsl:call-template>
2509 </xsl:if>
2510 </xsl:template>
2512 <!-- ******************************************************************** -->
2513 <!-- ******************************************************************** -->
2515 <!-- == inline_element -->
2516 <xsl:template
2517 match="citation_reference">
2518 <xsl:call-template
2519 name="u:bkslshEscPre"/>
2520 <xsl:text>[</xsl:text>
2521 <xsl:apply-templates/>
2522 <xsl:text>]_</xsl:text>
2523 <xsl:call-template
2524 name="u:bkslshEscSuf"/>
2525 </xsl:template>
2527 <!-- ******************************************************************** -->
2529 <!-- == inline_element -->
2530 <xsl:template
2531 match="emphasis">
2532 <xsl:call-template
2533 name="u:bkslshEscPre"/>
2534 <xsl:text>*</xsl:text>
2535 <xsl:apply-templates/>
2536 <xsl:text>*</xsl:text>
2537 <xsl:call-template
2538 name="u:bkslshEscSuf"/>
2539 </xsl:template>
2541 <!-- ******************************************************************** -->
2543 <!-- user-numbered footnotes lack @auto -->
2544 <!-- == inline_element -->
2545 <xsl:template
2546 match="footnote_reference[not(@auto)]">
2547 <xsl:call-template
2548 name="u:bkslshEscPre"/>
2549 <xsl:text>[</xsl:text>
2550 <xsl:value-of
2551 select="text()"/>
2552 <xsl:text>]_</xsl:text>
2553 <xsl:call-template
2554 name="u:bkslshEscSuf"/>
2555 <!-- child paragraph provides blank line -->
2556 </xsl:template>
2558 <!-- automatically numbered footnotes have @auto -->
2559 <!-- if @names is different from label content, it is a named footnote -->
2560 <!-- == inline_element -->
2561 <xsl:template
2562 match="footnote_reference[@auto='1']">
2563 <xsl:variable
2564 name="ref"
2565 select="@refid"/>
2566 <xsl:if
2567 test="not(starts-with(//footnote[@ids=$ref]/@names, 'TARGET_NOTE:\ '))">
2568 <!-- Not a generated footnote reference for a `.. target-notes::';
2569 such footnote reference and the preceding space should be
2570 embedded in `generated'! -->
2571 <xsl:call-template
2572 name="u:bkslshEscPre"/>
2573 <xsl:text>[#</xsl:text>
2574 <xsl:if
2575 test="//footnote[@ids=$ref]/@names != //footnote[@ids=$ref]/label">
2576 <xsl:call-template
2577 name="u:outputNames">
2578 <xsl:with-param
2579 name="names"
2580 select="//footnote[@ids=$ref]/@names"/>
2581 </xsl:call-template>
2582 </xsl:if>
2583 <xsl:text>]_</xsl:text>
2584 <xsl:call-template
2585 name="u:bkslshEscSuf"/>
2586 </xsl:if>
2587 </xsl:template>
2589 <!-- automatically symboled footnotes have @auto=* -->
2590 <!-- == inline_element -->
2591 <xsl:template
2592 match="footnote_reference[@auto='*']">
2593 <xsl:call-template
2594 name="u:bkslshEscPre"/>
2595 <xsl:text>[*]_</xsl:text>
2596 <xsl:call-template
2597 name="u:bkslshEscSuf"/>
2598 </xsl:template>
2600 <!-- ******************************************************************** -->
2602 <!--
2603 Content Model: %text.model;
2605 <!-- == inline_element -->
2606 <xsl:template
2607 match="literal">
2608 <xsl:call-template
2609 name="u:bkslshEscPre"/>
2610 <xsl:text>``</xsl:text>
2611 <xsl:apply-templates/>
2612 <xsl:text>``</xsl:text>
2613 <xsl:call-template
2614 name="u:bkslshEscSuf"/>
2615 </xsl:template>
2617 <!-- ******************************************************************** -->
2619 <!-- Attribute combinations found in `standard' text and other examples:
2620 @refuri = standalone hyperlink
2621 @ids @refid = TOC, probably all in <generated>
2622 @name @refuri with matching <target> in document = named external hyperlink _
2623 @name @refuri immediately followed by matching <target> = named embedded URI _
2624 @name @refuri with no matching <target> in document = anonymous embedded URI __
2625 @anonymous @name @refuri with no matching <target> in document = anonymous explicit URI __
2626 @name @refid = internal cross-reference _
2627 @anonymous @name @refid = anonymous implicit internal reference __
2628 @name @refid image = clickable image to internal reference _
2629 @refuri image = clickable image to standalone hyperlink
2631 A target matches if target/@names contains the lower cased, whitespace
2632 quoted reference/@name
2635 <!-- Standalone hyperlink -->
2636 <!-- == inline_element -->
2637 <xsl:template
2638 match="reference[not(@name or @anonymous)]">
2639 <xsl:call-template
2640 name="u:bkslshEscPre"/>
2641 <xsl:choose>
2642 <xsl:when
2643 test="starts-with(., 'PEP ')">
2644 <xsl:text>:PEP:`</xsl:text>
2645 <xsl:value-of
2646 select="substring-after(., 'PEP ')"/>
2647 <xsl:text>`</xsl:text>
2648 </xsl:when>
2649 <xsl:when
2650 test="starts-with(., 'RFC ')">
2651 <xsl:text>:RFC:`</xsl:text>
2652 <xsl:value-of
2653 select="substring-after(., 'RFC ')"/>
2654 <xsl:text>`</xsl:text>
2655 </xsl:when>
2656 <xsl:otherwise>
2657 <xsl:apply-templates/>
2658 </xsl:otherwise>
2659 </xsl:choose>
2660 <xsl:call-template
2661 name="u:bkslshEscSuf"/>
2662 </xsl:template>
2664 <!-- External references -->
2665 <!-- == inline_element -->
2666 <xsl:template
2667 match="reference[@name and @refuri]">
2668 <!-- Determine normalized name by downcasing it -->
2669 <xsl:variable
2670 name="normalized"
2671 select="translate(normalize-space(@name), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
2672 <xsl:variable
2673 name="quoted"
2674 select="str:replace($normalized, ' ', '\ ')"/>
2675 <xsl:variable
2676 name="matching"
2677 select="//target[contains(@names, $quoted)]"/>
2678 <xsl:call-template
2679 name="u:inlineReference">
2680 <xsl:with-param
2681 name="anonymous"
2682 select="not($matching) or @anonymous"/>
2683 <xsl:with-param
2684 name="embedded"
2685 select="not(@anonymous) and (not($matching) or generate-id(following-sibling::node()[1]) = generate-id($matching))"/>
2686 </xsl:call-template>
2687 </xsl:template>
2689 <!-- Internal references -->
2690 <!-- == inline_element -->
2691 <xsl:template
2692 match="reference[@name and @refid]">
2693 <xsl:call-template
2694 name="u:inlineReference">
2695 <xsl:with-param
2696 name="anonymous"
2697 select="@anonymous"/>
2698 </xsl:call-template>
2699 </xsl:template>
2701 <!-- Image references -->
2702 <!-- == inline_element -->
2703 <xsl:template
2704 match="reference[image]">
2705 <!-- All done by the `image' tag -->
2706 <xsl:apply-templates/>
2707 </xsl:template>
2709 <!-- ******************************************************************** -->
2711 <!--
2712 Content Model: %text.model;
2714 <!-- == inline_element -->
2715 <xsl:template
2716 match="strong">
2717 <xsl:call-template
2718 name="u:bkslshEscPre"/>
2719 <xsl:text>**</xsl:text>
2720 <xsl:apply-templates/>
2721 <xsl:text>**</xsl:text>
2722 <xsl:call-template
2723 name="u:bkslshEscSuf"/>
2724 </xsl:template>
2726 <!-- ******************************************************************** -->
2728 <!-- == inline_element -->
2729 <xsl:template
2730 match="subscript">
2731 <xsl:call-template
2732 name="u:bkslshEscPre"/>
2733 <xsl:text>:sub:`</xsl:text>
2734 <xsl:apply-templates/>
2735 <xsl:text>`</xsl:text>
2736 <xsl:call-template
2737 name="u:bkslshEscSuf"/>
2738 </xsl:template>
2740 <!-- ******************************************************************** -->
2742 <!-- == inline_element -->
2743 <xsl:template
2744 match="superscript">
2745 <xsl:call-template
2746 name="u:bkslshEscPre"/>
2747 <xsl:text>:sup:`</xsl:text>
2748 <xsl:apply-templates/>
2749 <xsl:text>`</xsl:text>
2750 <xsl:call-template
2751 name="u:bkslshEscSuf"/>
2752 </xsl:template>
2754 <!-- ******************************************************************** -->
2756 <!-- The target element has various roles depending on context; they are
2757 all handled here -->
2758 <!-- == simple_body_element == inline_element == directive -->
2759 <xsl:template
2760 match="target">
2761 <xsl:choose>
2762 <xsl:when
2763 test="name(preceding-sibling::*[1]) = 'reference'">
2764 <!-- An embedded inline target - handled by the reference itself -->
2765 </xsl:when>
2766 <xsl:when
2767 test="contains($inline_containers, concat('*', name(..), '*'))">
2768 <!-- An inline target of some sort -->
2769 <xsl:call-template
2770 name="u:inlineReference">
2771 <xsl:with-param
2772 name="isTarget"
2773 select="true()"/>
2774 </xsl:call-template>
2775 </xsl:when>
2776 <xsl:when
2777 test="@anonymous">
2778 <!-- An anonymous target directive -->
2779 <xsl:call-template
2780 name="u:outputClass"/>
2781 <xsl:call-template
2782 name="u:BandI"/>
2783 <xsl:text>__ </xsl:text>
2784 <xsl:choose>
2785 <xsl:when
2786 test="@refid">
2787 <xsl:call-template
2788 name="u:outputNamesRefid"/>
2789 <xsl:text>_</xsl:text>
2790 </xsl:when>
2791 <xsl:when
2792 test="@refuri">
2793 <xsl:value-of
2794 select="@refuri"/>
2795 </xsl:when>
2796 </xsl:choose>
2797 &tEOL;
2798 </xsl:when>
2799 <xsl:when
2800 test="@names | @refid">
2801 <!-- A target directive -->
2802 <xsl:call-template
2803 name="u:outputClass"/>
2804 <xsl:call-template
2805 name="u:BandI"/>
2806 <xsl:text>.. _</xsl:text>
2807 <xsl:choose>
2808 <xsl:when
2809 test="@refid">
2810 <xsl:call-template
2811 name="u:outputNamesRefid"/>
2812 </xsl:when>
2813 <xsl:otherwise>
2814 <xsl:variable
2815 name="quoteNeeded"
2816 select="contains(@names, ':')"/>
2817 <xsl:if
2818 test="$quoteNeeded">
2819 <xsl:text>`</xsl:text>
2820 </xsl:if>
2821 <xsl:call-template
2822 name="u:outputNames"/>
2823 <xsl:if
2824 test="$quoteNeeded">
2825 <xsl:text>`</xsl:text>
2826 </xsl:if>
2827 </xsl:otherwise>
2828 </xsl:choose>
2829 <xsl:text>:</xsl:text>
2830 <xsl:if
2831 test="@refuri">
2832 <xsl:text> </xsl:text>
2833 <xsl:value-of
2834 select="@refuri"/>
2835 </xsl:if>
2836 &tEOL;
2837 </xsl:when>
2838 <xsl:otherwise>
2839 <!-- Should not happen -->
2840 <xsl:call-template
2841 name="u:notSupported"/>
2842 </xsl:otherwise>
2843 </xsl:choose>
2844 </xsl:template>
2846 <!-- ******************************************************************** -->
2848 <!--
2849 Content Model: %text.model;
2851 <!-- == inline_element -->
2852 <xsl:template
2853 match="title_reference">
2854 <xsl:call-template
2855 name="u:bkslshEscPre"/>
2856 <xsl:text>`</xsl:text>
2857 <xsl:apply-templates/>
2858 <xsl:text>`</xsl:text>
2859 <xsl:call-template
2860 name="u:bkslshEscSuf"/>
2861 </xsl:template>
2863 <!-- ******************************************************************** -->
2865 <!--
2866 Content Model: %text.model;
2868 <!-- == inline_element -->
2869 <xsl:template
2870 match="inline">
2871 <!-- TODO `role' directives must be generated for plain and derived
2872 user-defined roles. -->
2873 <xsl:call-template
2874 name="u:bkslshEscPre"/>
2875 <xsl:text>:</xsl:text>
2876 <xsl:value-of
2877 select="@classes"/>
2878 <xsl:text>:`</xsl:text>
2879 <xsl:apply-templates/>
2880 <xsl:text>`</xsl:text>
2881 <xsl:call-template
2882 name="u:bkslshEscSuf"/>
2883 </xsl:template>
2885 <!-- ******************************************************************** -->
2887 <!-- TODO `meta` directive must be implemented. -->
2889 <!-- ******************************************************************** -->
2891 <!--
2892 Docutils wraps generated elements around text that is inserted (generated) by
2893 Docutils; i.e., text that was not in the document, like section numbers
2894 inserted by the "sectnum" directive.
2896 <!-- == inline_element -->
2897 <xsl:template
2898 match="generated"/>
2900 <!-- == inline_element -->
2901 <xsl:template
2902 match="problematic">
2903 <!-- Simply output the contained text because this is probably the
2904 original text-->
2905 <xsl:value-of
2906 select="text()"/>
2907 </xsl:template>
2909 <!-- == compound_body_element -->
2910 <xsl:template
2911 match="system_message"/>
2913 <!-- ******************************************************************** -->
2914 <!-- ******************************************************************** -->
2916 <!--
2917 When a block of text contains linefeeds, it was indented relative to a marker
2918 on the first line
2920 <xsl:template
2921 match="text()">
2922 <xsl:call-template
2923 name="u:indentLF"/>
2924 </xsl:template>
2926 <xsl:template
2927 match="text()"
2928 mode="inLiteral">
2929 <xsl:call-template
2930 name="u:indentLF">
2931 <xsl:with-param
2932 name="literal"
2933 select="true()"/>
2934 </xsl:call-template>
2935 </xsl:template>
2937 <!-- ******************************************************************** -->
2938 <!-- ******************************************************************** -->
2940 <!-- Add a blank line if necessary and indent -->
2941 <xsl:template
2942 name="u:BandI">
2943 <xsl:call-template
2944 name="u:blank"/>
2945 <xsl:call-template
2946 name="u:indent"/>
2947 </xsl:template>
2949 <!-- ******************************************************************** -->
2951 <!-- Add a blank line in certain contexts -->
2952 <xsl:template
2953 name="u:blank">
2954 <xsl:apply-templates
2955 mode="blankSkipInline"
2956 select="preceding::*[1]"/>
2957 </xsl:template>
2959 <!-- Find the preceding element we are really interested in and act
2960 according to this element -->
2961 <xsl:template
2962 mode="blankSkipInline"
2963 match="*">
2964 <xsl:choose>
2965 <!-- Skip all inline elements and body subelements and check their
2966 parents -->
2967 <xsl:when
2968 test="contains(concat($inline_elements, $simple_body_subelements, $compound_body_subelements), concat('*', name(.), '*'))">
2969 <xsl:apply-templates
2970 mode="blankSkipInline"
2971 select=".."/>
2972 </xsl:when>
2973 <xsl:otherwise>
2974 <!-- Reached the type of element we decide on -->
2975 <xsl:if
2976 test="contains($blank_after, concat('*', name(.), '*'))">
2977 &tCR;
2978 </xsl:if>
2979 </xsl:otherwise>
2980 </xsl:choose>
2981 </xsl:template>
2983 <!-- ******************************************************************** -->
2985 <!--
2986 Indent a block if it's a child of...
2988 <data:lookup>
2989 <data:node
2990 name="address"
2991 indent="10"/>
2992 <data:node
2993 name="author"
2994 indent="9"/>
2995 <data:node
2996 name="authors"
2997 indent="10"/>
2998 <data:node
2999 name="contact"
3000 indent="10"/>
3001 <data:node
3002 name="copyright"
3003 indent="12"/>
3004 <data:node
3005 name="date"
3006 indent="7"/>
3007 <data:node
3008 name="organization"
3009 indent="15"/>
3010 <data:node
3011 name="revision"
3012 indent="11"/>
3013 <data:node
3014 name="status"
3015 indent="9"/>
3016 <data:node
3017 name="version"
3018 indent="10"/>
3019 <!-- This is only for `bullet_list/list_item';
3020 `enumerated_list/list_item' is handled special -->
3021 <data:node
3022 name="list_item"
3023 indent="2"/>
3024 <data:node
3025 name="definition_list_item"
3026 indent="4"/>
3027 <data:node
3028 name="field_body"
3029 indent="4"/>
3030 <data:node
3031 name="option_list_item"
3032 indent="4"/>
3033 <!-- This is also the indentation if block_quote comes as one of the
3034 special directives -->
3035 <data:node
3036 name="block_quote"
3037 indent="4"/>
3038 <data:node
3039 name="literal_block"
3040 indent="4"/>
3041 <data:node
3042 name="attribution"
3043 indent="3"/>
3044 <data:node
3045 name="line"
3046 indent="2"/>
3047 </data:lookup>
3049 <!-- Do indent according to ancestor -->
3050 <xsl:template
3051 name="u:indent">
3052 <!-- In some cases the ancestors to indent for need to be determined
3053 by the calling template -->
3054 <xsl:param
3055 name="ancestors"
3056 select="ancestor::*"/>
3057 <xsl:for-each
3058 select="$ancestors">
3059 <xsl:variable
3060 name="this"
3061 select="name()"/>
3062 <xsl:choose>
3063 <xsl:when
3064 test="contains($directives, concat('*', $this, '*'))">
3065 <!-- TODO Indentation of lines after some directives must be
3066 indented to align with the directive instead of a
3067 fixed indentation; however, this is rather complicated
3068 since identation for parameters should be fixed -->
3069 <xsl:value-of
3070 select="str:padding(3)"/>
3071 </xsl:when>
3072 <xsl:when
3073 test="$this = 'list_item' and parent::enumerated_list">
3074 <!-- Enumerated list items base their indentation on the
3075 numeration -->
3076 <xsl:variable
3077 name="enumerator">
3078 <xsl:call-template
3079 name="u:outputEnumerator"/>
3080 </xsl:variable>
3081 <xsl:value-of
3082 select="str:padding(string-length($enumerator))"/>
3083 </xsl:when>
3084 <xsl:otherwise>
3085 <xsl:value-of
3086 select="str:padding(document('')//data:lookup/data:node[@name=$this]/@indent)"/>
3087 </xsl:otherwise>
3088 </xsl:choose>
3089 </xsl:for-each>
3090 </xsl:template>
3092 <!-- ******************************************************************** -->
3094 <!-- Indent a text containing line feeds correctly -->
3095 <xsl:template
3096 name="u:indentLF">
3097 <xsl:param
3098 name="string"
3099 select="."/>
3100 <!-- A fixed indentation may be given by caller -->
3101 <xsl:param
3102 name="indent">
3103 <!-- If not given compute it -->
3104 <xsl:call-template
3105 name="u:indent"/>
3106 </xsl:param>
3107 <xsl:param
3108 name="literal"
3109 select="false()"/>
3110 <xsl:value-of
3111 select="rst:plain($string, $indent, $literal)"/>
3112 </xsl:template>
3114 <!-- ******************************************************************** -->
3116 <!-- Do output for those elements which do fold their inline content -->
3117 <xsl:template
3118 name="u:outputFolding">
3119 <!-- The prefix text to be output before the body -->
3120 <xsl:param
3121 name="prefix"
3122 select="''"/>
3123 <!-- The indentation for this body -->
3124 <xsl:param
3125 name="indent">
3126 <xsl:call-template
3127 name="u:indent">
3128 <xsl:with-param
3129 name="ancestors"
3130 select="ancestor-or-self::*"/>
3131 </xsl:call-template>
3132 </xsl:param>
3133 <xsl:variable
3134 name="string">
3135 <!-- TODO Whitespace count of inline literals must be preserved -->
3136 <xsl:apply-templates/>
3137 </xsl:variable>
3138 <!-- Always output prefix with all trailing and leading spaces -->
3139 <xsl:value-of
3140 select="$prefix"/>
3141 <xsl:choose>
3142 <xsl:when
3143 test="$fold &gt; 0">
3144 <xsl:variable
3145 name="normalized"
3146 select="normalize-space($string)"/>
3147 <xsl:choose>
3148 <xsl:when
3149 test="$string = ''">
3150 <!-- Empty strings need no output -->
3151 </xsl:when>
3152 <xsl:when
3153 test="$normalized = ''">
3154 <!-- Only white-space in string; output a single space here -->
3155 &tSP;
3156 </xsl:when>
3157 <xsl:otherwise>
3158 <!-- Output leading white-space here -->
3159 <xsl:if
3160 test="normalize-space(substring($string, 1, 1)) = ''">
3161 &tSP;
3162 </xsl:if>
3163 <xsl:call-template
3164 name="u:indentFold">
3165 <xsl:with-param
3166 name="string"
3167 select="$normalized"/>
3168 <xsl:with-param
3169 name="indent"
3170 select="$indent"/>
3171 <xsl:with-param
3172 name="cursorColumn"
3173 select="string-length($indent) + string-length($prefix)"/>
3174 </xsl:call-template>
3175 <!-- Output trailing white-space here -->
3176 <xsl:if
3177 test="normalize-space(substring($string, string-length($string), 1)) = ''">
3178 &tSP;
3179 </xsl:if>
3180 </xsl:otherwise>
3181 </xsl:choose>
3182 </xsl:when>
3183 <xsl:otherwise>
3184 <xsl:value-of
3185 select="$string"/>
3186 </xsl:otherwise>
3187 </xsl:choose>
3188 &tEOL;
3189 </xsl:template>
3191 <!-- ******************************************************************** -->
3193 <!-- Indent a string with folding -->
3194 <xsl:template
3195 name="u:indentFold">
3196 <!-- Normalized string to output -->
3197 <xsl:param
3198 name="string"/>
3199 <!-- Indentation to use for a new line -->
3200 <xsl:param
3201 name="indent"/>
3202 <!-- Current output column -->
3203 <!-- TODO This is not a correct assumption for field definitions where
3204 the field name effectively determines the column of the first
3205 line -->
3206 <xsl:param
3207 name="cursorColumn"
3208 select="string-length($indent)"/>
3209 <!-- Do we start on a new (indented) line? -->
3210 <xsl:param
3211 name="isNewLine"
3212 select="true()"/>
3213 <xsl:variable
3214 name="firstWord">
3215 <xsl:choose>
3216 <!-- TODO Quoted spaces must not end a word -->
3217 <xsl:when
3218 test="contains($string, ' ')">
3219 <xsl:value-of
3220 select="substring-before($string, ' ')"/>
3221 </xsl:when>
3222 <xsl:otherwise>
3223 <xsl:value-of
3224 select="$string"/>
3225 </xsl:otherwise>
3226 </xsl:choose>
3227 </xsl:variable>
3228 <xsl:variable
3229 name="rest"
3230 select="substring-after($string, ' ')"/>
3231 <xsl:choose>
3232 <xsl:when
3233 test="$string = ''"/>
3234 <xsl:when
3235 test="$isNewLine">
3236 <!-- Output at least first word -->
3237 <xsl:value-of
3238 select="$firstWord"/>
3239 <xsl:call-template
3240 name="u:indentFold">
3241 <xsl:with-param
3242 name="string"
3243 select="$rest"/>
3244 <xsl:with-param
3245 name="indent"
3246 select="$indent"/>
3247 <xsl:with-param
3248 name="cursorColumn"
3249 select="$cursorColumn + string-length($firstWord)"/>
3250 <xsl:with-param
3251 name="isNewLine"
3252 select="false()"/>
3253 </xsl:call-template>
3254 </xsl:when>
3255 <xsl:when
3256 test="$cursorColumn + 1 + string-length($firstWord) &gt; $fold">
3257 <!-- Line would get too long; start new line, indent and continue -->
3258 &tEOL;
3259 <xsl:value-of
3260 select="$indent"/>
3261 <xsl:call-template
3262 name="u:indentFold">
3263 <xsl:with-param
3264 name="string"
3265 select="$string"/>
3266 <xsl:with-param
3267 name="indent"
3268 select="$indent"/>
3269 <xsl:with-param
3270 name="cursorColumn"
3271 select="string-length($indent)"/>
3272 <xsl:with-param
3273 name="isNewLine"
3274 select="true()"/>
3275 </xsl:call-template>
3276 </xsl:when>
3277 <xsl:otherwise>
3278 <!-- In a line and first word fits; separate and add word -->
3279 &tSP;
3280 <xsl:value-of
3281 select="$firstWord"/>
3282 <xsl:call-template
3283 name="u:indentFold">
3284 <xsl:with-param
3285 name="string"
3286 select="$rest"/>
3287 <xsl:with-param
3288 name="indent"
3289 select="$indent"/>
3290 <xsl:with-param
3291 name="cursorColumn"
3292 select="$cursorColumn + 1 + string-length($firstWord)"/>
3293 <xsl:with-param
3294 name="isNewLine"
3295 select="false()"/>
3296 </xsl:call-template>
3297 </xsl:otherwise>
3298 </xsl:choose>
3299 </xsl:template>
3301 <!-- ******************************************************************** -->
3303 <!-- Output attributes of the current element as a field list -->
3304 <xsl:template
3305 name="u:params">
3306 <xsl:param
3307 name="params"
3308 select="@*"/>
3309 <!-- Ancestors are needed for determining indentation; caller may give
3310 them -->
3311 <xsl:param
3312 name="ancestors"
3313 select="ancestor-or-self::*"/>
3314 <xsl:for-each
3315 select="$params">
3316 <!-- Skip URIs based on parent -->
3317 <xsl:if
3318 test="name() != 'uri' and name() != 'xml:space'">
3319 <xsl:call-template
3320 name="u:param">
3321 <xsl:with-param
3322 name="ancestors"
3323 select="$ancestors"/>
3324 </xsl:call-template>
3325 </xsl:if>
3326 </xsl:for-each>
3327 </xsl:template>
3329 <!-- Output one attribute of the current element as a field list -->
3330 <xsl:template
3331 name="u:param">
3332 <xsl:param
3333 name="name"
3334 select="name()"/>
3335 <xsl:param
3336 name="value"
3337 select="."/>
3338 <!-- Ancestors are needed for determining indentation; caller may give
3339 them -->
3340 <xsl:param
3341 name="ancestors"
3342 select="ancestor::*"/>
3343 <xsl:call-template
3344 name="u:indent">
3345 <xsl:with-param
3346 name="ancestors"
3347 select="$ancestors"/>
3348 </xsl:call-template>
3349 <xsl:text>:</xsl:text>
3350 <xsl:choose>
3351 <xsl:when
3352 test="$name = 'classes'">
3353 <xsl:text>class</xsl:text>
3354 </xsl:when>
3355 <xsl:otherwise>
3356 <xsl:value-of
3357 select="$name"/>
3358 </xsl:otherwise>
3359 </xsl:choose>
3360 <xsl:text>:</xsl:text>
3361 <xsl:if
3362 test="$value">
3363 <xsl:text> </xsl:text>
3364 <xsl:value-of
3365 select="$value"/>
3366 </xsl:if>
3367 &tEOL;
3368 </xsl:template>
3370 <!-- ******************************************************************** -->
3372 <!-- Output `\' or `\ ' before some inline element if necessary -->
3373 <xsl:template
3374 name="u:bkslshEscPre">
3375 <!-- Get the sibling node directly before the current element -->
3376 <xsl:variable
3377 name="before"
3378 select="preceding-sibling::node()[1]"/>
3379 <xsl:choose>
3380 <!-- No sibling before this node -->
3381 <xsl:when
3382 test="not($before)"/>
3383 <!-- Element directly before this - must be another inline element -->
3384 <xsl:when
3385 test="name($before)">
3386 <!-- So separate it by a quoted space -->
3387 <xsl:text>\ </xsl:text>
3388 </xsl:when>
3389 <!-- Node directly before this is text - check it -->
3390 <xsl:when
3391 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;([{&lt;-/:'), substring($before, string-length($before), 1)))">
3392 <!-- Does not end in one of the allowed characters so separate it -->
3393 <xsl:text>\ </xsl:text>
3394 </xsl:when>
3395 </xsl:choose>
3396 </xsl:template>
3398 <!-- Output `\' after some inline element if necessary -->
3399 <xsl:template
3400 name="u:bkslshEscSuf">
3401 <!-- Get the sibling node directly after the current element -->
3402 <xsl:variable
3403 name="after"
3404 select="following-sibling::node()[1]"/>
3405 <xsl:choose>
3406 <!-- No sibling after this node -->
3407 <xsl:when
3408 test="not($after)"/>
3409 <!-- Element directly after this - must be another inline element
3410 handling itself -->
3411 <xsl:when
3412 test="name($after)"/>
3413 <!-- Node directly after this is text - check it -->
3414 <xsl:when
3415 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;)]}&gt;-/:.,;!?\'), substring($after, 1, 1)))">
3416 <!-- Does not start with one of the allowed characters so separate
3417 it -->
3418 <xsl:text>\</xsl:text>
3419 </xsl:when>
3420 </xsl:choose>
3421 </xsl:template>
3423 <!-- ******************************************************************** -->
3425 <xsl:template
3426 name="u:notSupported">
3427 <xsl:call-template
3428 name="u:BandI"/>
3429 <xsl:text>######## NOT SUPPORTED: `</xsl:text>
3430 <xsl:value-of
3431 select="name(.)"/>
3432 <xsl:text>' ########</xsl:text>
3433 &tEOL;
3434 </xsl:template>
3436 <!-- ******************************************************************** -->
3438 <xsl:template
3439 name="u:overline">
3440 <!-- Length of the rendered(!) text -->
3441 <xsl:param
3442 name="length"/>
3443 <!-- Depth 1 and 2 are document title and subtitle while depths
3444 greater than 2 are normal section titles -->
3445 <xsl:param
3446 name="depth"/>
3447 <!-- Test whether a overline is wanted at all -->
3448 <xsl:if
3449 test="substring($adornment, 2 * ($depth - 1) + 1, 1) = 'o'">
3450 <xsl:value-of
3451 select="str:padding($length, substring($adornment, 2 * ($depth - 1) + 2, 1))"/>
3452 &tEOL;
3453 </xsl:if>
3454 </xsl:template>
3456 <xsl:template
3457 name="u:underline">
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 <xsl:value-of
3466 select="str:padding($length, substring($adornment, 2 * ($depth - 1) + 2, 1))"/>
3467 &tEOL;
3468 </xsl:template>
3470 <!-- ******************************************************************** -->
3472 <!-- Output a non-standalone reference or target -->
3473 <xsl:template
3474 name="u:inlineReference">
3475 <xsl:param
3476 name="anonymous"
3477 select="false()"/>
3478 <xsl:param
3479 name="embedded"
3480 select="false()"/>
3481 <!-- Is this a target instead of a reference? -->
3482 <xsl:param
3483 name="isTarget"
3484 select="false()"/>
3485 <xsl:param
3486 name="text"
3487 select="node()"/>
3488 <xsl:call-template
3489 name="u:bkslshEscPre"/>
3490 <!-- Delimiter only if link contains other than alphanumerics -->
3491 <xsl:variable
3492 name="delimiter">
3493 <xsl:if
3494 test="* or translate($text, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '') or $embedded">
3495 <xsl:text>`</xsl:text>
3496 </xsl:if>
3497 </xsl:variable>
3498 <xsl:if
3499 test="$isTarget">
3500 <xsl:text>_</xsl:text>
3501 </xsl:if>
3502 <xsl:value-of
3503 select="$delimiter"/>
3504 <xsl:apply-templates
3505 select="$text"/>
3506 <xsl:if
3507 test="$embedded">
3508 <xsl:text> &lt;</xsl:text>
3509 <xsl:value-of
3510 select="@refuri"/>
3511 <xsl:text>&gt;</xsl:text>
3512 </xsl:if>
3513 <xsl:value-of
3514 select="$delimiter"/>
3515 <xsl:if
3516 test="not($isTarget)">
3517 <xsl:text>_</xsl:text>
3518 <xsl:if
3519 test="$anonymous">
3520 <xsl:text>_</xsl:text>
3521 </xsl:if>
3522 </xsl:if>
3523 <xsl:call-template
3524 name="u:bkslshEscSuf"/>
3525 </xsl:template>
3527 <!-- ******************************************************************** -->
3529 <!-- Output a class directive for the directly following element. -->
3530 <!-- TODO A class directive can also be used as a container putting the
3531 respective attribute to its content; however, this is not
3532 reflected in XML - you'd need to check a sequence of elements
3533 whether they all have the same attribute; furthermore class
3534 settings for block quotes needs to be treated special -->
3535 <xsl:template
3536 name="u:outputClass">
3537 <!-- Blank line already output? -->
3538 <xsl:param
3539 name="alreadyBlanked"
3540 select="false()"/>
3541 <!-- Indentation already output? -->
3542 <xsl:param
3543 name="alreadyIndented"
3544 select="false()"/>
3545 <!-- Add a blank line after class directive? -->
3546 <xsl:param
3547 name="blankAfter"
3548 select="false()"/>
3549 <xsl:if
3550 test="@classes">
3551 <xsl:if
3552 test="not($alreadyBlanked)">
3553 <xsl:call-template
3554 name="u:blank"/>
3555 </xsl:if>
3556 <xsl:if
3557 test="not($alreadyIndented)">
3558 <xsl:call-template
3559 name="u:indent"/>
3560 </xsl:if>
3561 <xsl:text>.. class:: </xsl:text>
3562 <xsl:value-of
3563 select="@classes"/>
3564 &tEOL;
3565 <xsl:if
3566 test="$blankAfter">
3567 &tCR;
3568 </xsl:if>
3569 </xsl:if>
3570 </xsl:template>
3572 <!-- ******************************************************************** -->
3574 <!-- Output a names attribute at index considering quoted spaces. -->
3575 <xsl:template
3576 name="u:outputNames">
3577 <!-- Blank line already output? -->
3578 <xsl:param
3579 name="names"
3580 select="@names"/>
3581 <xsl:param
3582 name="index"
3583 select="0"/>
3584 <xsl:value-of
3585 select="str:replace(str:tokenize(normalize-space(str:replace($names, '\ ', '|')))[position() = $index + 1], '|', ' ')"/>
3586 </xsl:template>
3588 <!-- ******************************************************************** -->
3590 <!-- Output a names attribute for a refid. -->
3591 <xsl:template
3592 name="u:outputNamesRefid">
3593 <xsl:param
3594 name="refid"
3595 select="@refid"/>
3596 <!-- Determine the elements which is referred -->
3597 <xsl:variable
3598 name="refElem"
3599 select="//*[@ids and math:max(dyn:map(str:tokenize(normalize-space(@ids)), 'number($refid = .)')) > 0]"/>
3600 <xsl:call-template
3601 name="u:outputNames">
3602 <xsl:with-param
3603 name="names"
3604 select="$refElem/@names"/>
3605 <xsl:with-param
3606 name="index"
3607 select="math:max(dyn:map(str:tokenize(normalize-space($refElem/@ids)), 'number($refid = .) * position() - 1'))"/>
3608 </xsl:call-template>
3609 </xsl:template>
3611 <!-- ******************************************************************** -->
3612 <!-- ******************************************************************** -->
3614 <!-- Report unknown tags -->
3615 <xsl:template
3616 match="*">
3617 <xsl:message>
3618 <xsl:text>`</xsl:text>
3619 <xsl:value-of
3620 select="name(.)"/>
3621 <xsl:text>' encountered</xsl:text>
3622 <xsl:if
3623 test="parent::*">
3624 <xsl:text> in `</xsl:text>
3625 <xsl:value-of
3626 select="name(parent::*)"/>
3627 <xsl:text>'</xsl:text>
3628 </xsl:if>
3629 <xsl:text>, but no template matches.</xsl:text>
3630 </xsl:message>
3631 </xsl:template>
3633 </xsl:stylesheet>