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