more compact comments for __version_info__
[docutils.git] / sandbox / xml2rst / xml2rstlib / xml2rst-noexslt.xsl
blob489890a18c3bc4e1972784669ada52aa370961e4
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, 2009 Stefan Merten, David Priest
17 xml2rst.xsl is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published
19 by the Free Software Foundation; either version 2 of the License,
20 or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 02111-1307, USA.
31 -->
33 <!-- ********************************************************************** -->
34 <!-- ********************************************************************** -->
36 <!-- These elements in the DTD need support:
38 - ``colspec`` has attribute "stub %yesorno; #IMPLIED"
40 - ``document`` has attribute "title CDATA #IMPLIED"
42 Probably rendered by the `.. title::` directive
44 -->
46 <!--
47 Set namespace extensions. These are used as [shortname]:[tag] throughout the
48 XSL-FO files.
49 xsl: eXtensible Stylesheet Language
50 u: user extensions (indicates utility 'call-template' routines defined in
51 these XSL files)
52 data: Data elements used by the stylesheet
53 -->
54 <xsl:stylesheet
55 version="1.0"
56 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
57 xmlns:u="u"
58 xmlns:data="a"
59 exclude-result-prefixes="data">
61 <xsl:output
62 method="text"
63 omit-xml-declaration="yes"
64 indent="no"/>
66 <!-- ******************************************************************** -->
67 <!-- ******************************************************************** -->
69 <!-- Parameter to configure title markup; see manual page for description -->
70 <xsl:param
71 name="adornment"
72 select="'o=o-u=u-u~u`u,u.'"/>
74 <!-- Parameter for folding long lines; see manual page for description -->
75 <xsl:param
76 name="fold"
77 select="0"/>
79 <!-- ******************************************************************** -->
80 <!-- ******************************************************************** -->
82 <xsl:variable
83 name="apos"
84 select='"&apos;"'/>
86 <xsl:variable
87 name="structural_elements"
88 select="'*document*section*topic*sidebar*'"/>
90 <xsl:variable
91 name="structural_subelements"
92 select="'*title*subtitle*docinfo*decoration*transition*'"/>
94 <xsl:variable
95 name="bibliographic_elements"
96 select="'*address*author*authors*contact*copyright*date*field*organization*revision*status*version*'"/>
98 <xsl:variable
99 name="decorative_elements"
100 select="'*footer*header*'"/>
102 <xsl:variable
103 name="simple_body_elements_no_substitution"
104 select="'*comment*doctest_block*image*literal_block*paragraph*pending*raw*rubric*target*'"/>
106 <xsl:variable
107 name="folding_elements"
108 select="concat('*comment*paragraph*rubric*attribution*caption*line*', substring-after($bibliographic_elements, '*'))"/>
110 <xsl:variable
111 name="simple_body_elements"
112 select="concat($simple_body_elements_no_substitution, 'substitution_definition*')"/>
114 <xsl:variable
115 name="compound_body_elements"
116 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*'"/>
118 <xsl:variable
119 name="body_elements"
120 select="concat($simple_body_elements, substring-after($compound_body_elements, '*'))"/>
122 <xsl:variable
123 name="admonitions"
124 select="'*admonition*attention*caution*danger*error*hint*important*note*tip*warning*'"/>
126 <xsl:variable
127 name="simple_body_subelements"
128 select="'*attribution*caption*classifier*colspec*field_name*label*line*option_argument*option_string*term*'"/>
130 <xsl:variable
131 name="compound_body_subelements"
132 select="'*definition*definition_list_item*description*entry*field*field_body*legend*list_item*option*option_group*option_list_item*row*tbody*tgroup*thead*'"/>
134 <xsl:variable
135 name="inline_elements"
136 select="'*abbreviation*acronym*citation_reference*emphasis*footnote_reference*generated*image*inline*literal*problematic*reference*strong*subscript*substitution_reference*superscript*target*title_reference*raw*'"/>
138 <xsl:variable
139 name="inline_containers"
140 select="concat($simple_body_elements_no_substitution, substring-after($inline_elements, '*'))"/>
142 <xsl:variable
143 name="directives"
144 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*'"/>
146 <xsl:variable
147 name="titled_elements"
148 select="'*sidebar*topic*admonition*'"/>
150 <xsl:variable
151 name="blank_after"
152 select="concat($structural_elements, substring-after($structural_subelements, '*'), substring-after($body_elements, '*'))"/>
154 <xsl:variable
155 name="adornment_characters"
156 select="concat($apos, '!&quot;#$%&amp;()*+,-./:;&lt;=&gt;?@[\]^_`{|}~')"/>
158 <!-- ******************************************************************** -->
159 <!-- ******************************************************************** -->
161 <!--
162 Content Model: ((title, subtitle?)?, docinfo?, decoration?,
163 %structure.model;)
165 Attributes: The document element contains only the common attributes: ids,
166 names, dupnames, source, and classes.
168 Depending on the source of the data and the stage of processing, the
169 "document" may not initially contain a "title". A document title is not
170 directly representable in reStructuredText. Instead, a lone top-level section
171 may have its title promoted to become the document title, and similarly for a
172 lone second-level (sub)section's title to become the document subtitle. The
173 "docinfo" may be transformed from an initial field_list, and "decoration" is
174 usually constructed programmatically.
176 <!-- == structural_element -->
177 <xsl:template
178 match="document">
179 <xsl:if
180 test="//generated[@classes = 'sectnum']">
181 <xsl:text>.. section-numbering::</xsl:text>
182 &tEOL;
183 &tCR;
184 </xsl:if>
185 <xsl:call-template
186 name="u:outputClass">
187 <xsl:with-param
188 name="blankAfter"
189 select="true()"/>
190 </xsl:call-template>
191 <xsl:apply-templates/>
192 </xsl:template>
194 <!-- ******************************************************************** -->
196 <!--
197 Content Model: (title, %structure.model;)
198 Attributes: The section element contains only the common attributes: ids,
199 names, dupnames, source, and classes.
201 <!-- == structural_element -->
202 <xsl:template
203 match="section">
204 <xsl:call-template
205 name="u:outputClass"/>
206 <xsl:call-template
207 name="u:blank"/>
208 <xsl:apply-templates/>
209 </xsl:template>
211 <!-- == structural_element -->
212 <xsl:template
213 match="section[@classes = 'system-messages']"/>
214 <!-- Ignore system messages completely -->
215 <!-- This should be really in `generated' -->
217 <!-- ******************************************************************** -->
219 <!--
220 Content Model: (title, subtitle?, (%body.elements;)+)
221 Attributes: The sidebar element contains only the common attributes: ids,
222 names, dupnames, source, and classes.
224 <!-- == structural_element == directive -->
225 <xsl:template
226 match="sidebar">
227 <xsl:call-template
228 name="u:BandI"/>
229 <xsl:text>.. sidebar:: </xsl:text>
230 <xsl:value-of
231 select="title"/>
232 &tEOL;
233 <xsl:if
234 test="subtitle">
235 <xsl:call-template
236 name="u:param">
237 <xsl:with-param
238 name="name"
239 select="'subtitle'"/>
240 <xsl:with-param
241 name="value"
242 select="subtitle"/>
243 <xsl:with-param
244 name="ancestors"
245 select="ancestor-or-self::*"/>
246 </xsl:call-template>
247 </xsl:if>
248 <xsl:call-template
249 name="u:params"/>
250 <!-- Always blank line after parameter block -->
251 &tCR;
252 <xsl:apply-templates
253 select="*[not(self::title) and not(self::subtitle)]"/>
254 </xsl:template>
256 <!-- ******************************************************************** -->
258 <!--
259 Content Model: (title?, (%body.elements;)+)
260 Attributes: The topic element contains only the common attributes: ids,
261 names, dupnames, source, and classes.
263 <!-- == structural_element == directive -->
264 <xsl:template
265 match="topic">
266 <xsl:call-template
267 name="u:BandI"/>
268 <xsl:text>.. topic:: </xsl:text>
269 <xsl:value-of
270 select="title"/>
271 &tEOL;
272 <xsl:call-template
273 name="u:params"/>
274 <xsl:apply-templates
275 select="*[not(self::title)]"/>
276 </xsl:template>
278 <!-- == structural_element == directive -->
279 <xsl:template
280 match="topic[starts-with(@classes, 'contents')]">
281 <xsl:call-template
282 name="u:BandI"/>
283 <xsl:text>.. contents:: </xsl:text>
284 <xsl:apply-templates
285 select="title"/>
286 &tEOL;
287 <xsl:call-template
288 name="u:params">
289 <xsl:with-param
290 name="params"
291 select="@*[name() != 'ids' and name() != 'names' and name() != 'classes']"/>
292 </xsl:call-template>
293 <xsl:variable
294 name="isLocal"
295 select="substring-before(@classes, ' local')"/>
296 <xsl:variable
297 name="realClassesLocal"
298 select="normalize-space(substring-after(@classes, 'contents'))"/>
299 <xsl:variable
300 name="realClassesNode">
301 <xsl:choose>
302 <xsl:when
303 test="$isLocal">
304 <xsl:value-of
305 select="normalize-space(substring-before($realClassesLocal, 'local'))"/>
306 </xsl:when>
307 <xsl:otherwise>
308 <xsl:value-of
309 select="$realClassesLocal"/>
310 </xsl:otherwise>
311 </xsl:choose>
312 </xsl:variable>
313 <xsl:variable
314 name="realClasses"
315 select="string($realClassesNode)"/>
316 <xsl:if
317 test="$isLocal">
318 <xsl:call-template
319 name="u:param">
320 <xsl:with-param
321 name="name"
322 select="'local'"/>
323 <xsl:with-param
324 name="value"
325 select="''"/>
326 <xsl:with-param
327 name="ancestors"
328 select="ancestor-or-self::*"/>
329 </xsl:call-template>
330 </xsl:if>
331 <xsl:if
332 test="$realClasses">
333 <xsl:call-template
334 name="u:param">
335 <xsl:with-param
336 name="name"
337 select="'class'"/>
338 <xsl:with-param
339 name="value"
340 select="$realClasses"/>
341 <xsl:with-param
342 name="ancestors"
343 select="ancestor-or-self::*"/>
344 </xsl:call-template>
345 </xsl:if>
346 <!-- Autogenerated content is discarded -->
347 &tCR;
348 </xsl:template>
350 <!-- == structural_element == directive -->
351 <xsl:template
352 match="topic[@classes='dedication' or @classes='abstract']">
353 <xsl:call-template
354 name="u:BandI"/>
355 <xsl:text>:</xsl:text>
356 <xsl:apply-templates
357 select="title"/>
358 <xsl:text>: </xsl:text>
359 &tEOL;
360 <xsl:apply-templates
361 select="*[not(self::title)]"/>
362 </xsl:template>
364 <!-- ******************************************************************** -->
366 <!--
367 Content Model: (title, (%body.elements;)+)
368 Attributes: The admonition element contains only the common attributes:
369 ids, names, dupnames, source, and classes.
371 <!-- == compound_body_element == directive -->
372 <xsl:template
373 match="admonition">
374 <xsl:call-template
375 name="u:BandI"/>
376 <xsl:text>.. admonition:: </xsl:text>
377 <xsl:apply-templates
378 select="title"/>
379 &tEOL;
380 <xsl:call-template
381 name="u:params">
382 <xsl:with-param
383 name="params"
384 select="@*[name() != 'classes' or not(starts-with(., 'admonition-'))]"/>
385 </xsl:call-template>
386 <xsl:call-template
387 name="u:indent"/>
388 <xsl:apply-templates
389 select="*[not(self::title)]"/>
390 </xsl:template>
392 <!-- ******************************************************************** -->
394 <!--
395 Content Model: (%body.elements;)+
396 Attributes: The note element contains only the common attributes: ids,
397 names, dupnames, source, and classes.
399 <!-- == compound_body_element == directive -->
400 <xsl:template
401 match="attention | caution | danger | error | hint | important | note | tip | warning">
402 <xsl:call-template
403 name="u:outputClass"/>
404 <xsl:call-template
405 name="u:BandI"/>
406 <xsl:text>.. </xsl:text>
407 <xsl:value-of
408 select="name()"/>
409 <xsl:text>:: </xsl:text>
410 <xsl:call-template
411 name="u:params">
412 <xsl:with-param
413 name="params"
414 select="@*[name() != 'classes']"/>
415 </xsl:call-template>
416 <xsl:apply-templates/>
417 </xsl:template>
419 <!-- ******************************************************************** -->
421 <!--
422 Content Model: (header?, footer?)
423 Attributes: The decoration element contains only the common attributes:
424 ids, names, dupnames, source, and classes.
426 Although the content model doesn't specifically require contents, no empty
427 decoration elements are ever created.
429 <!-- == structural_subelement -->
430 <xsl:template
431 match="//document/decoration">
432 <xsl:apply-templates/>
433 </xsl:template>
435 <!-- TODO To be rendered as `.. header::` directive -->
436 <!-- == decorative_element -->
437 <xsl:template
438 match="//document/decoration/header">
439 <xsl:apply-templates/>
440 </xsl:template>
442 <!-- TODO To be rendered as `.. footer::` directive -->
443 <!-- == decorative_element -->
444 <xsl:template
445 match="//document/decoration/footer">
446 <xsl:apply-templates/>
447 </xsl:template>
449 <!-- ******************************************************************** -->
451 <!--
452 Content Model: (%bibliographic.elements;)+
453 Attributes: The docinfo element contains only the common attributes: ids,
454 names, dupnames, source, and classes.
456 <!-- == structural_subelement -->
457 <xsl:template
458 match="docinfo">
459 <xsl:call-template
460 name="u:outputClass"/>
461 <xsl:call-template
462 name="u:blank"/>
463 <xsl:apply-templates/>
464 <xsl:call-template
465 name="u:blank"/>
466 </xsl:template>
468 <!-- ******************************************************************** -->
470 <!--
471 Content Model: ((author, organization?, address?, contact?)+)
472 Attributes: The authors element contains only the common attributes: ids,
473 names, dupnames, source, and classes.
475 In reStructuredText, multiple author's names are separated with semicolons
476 (";") or commas (","); semicolons take precedence. There is currently no way
477 to represent the author's organization, address, or contact in a
478 reStructuredText "Authors" field.
480 <!-- == bibliographic_element == folding_element -->
481 <xsl:template
482 match="docinfo/authors">
483 <xsl:call-template
484 name="u:outputFolding">
485 <xsl:with-param
486 name="prefix">
487 <xsl:text>:</xsl:text>
488 <xsl:value-of
489 select="name()"/>
490 <xsl:text>: </xsl:text>
491 </xsl:with-param>
492 </xsl:call-template>
493 </xsl:template>
495 <!--
496 Content Model: %text.model;
497 Attributes: All docinfo elements contains the common attributes (ids,
498 names, dupnames, source, and classes)
499 Some docinfo elements also have xml:space.
501 <xsl:template
502 match="docinfo/authors/*">
503 <xsl:apply-templates/>
504 <!-- no semicolon after final author -->
505 <xsl:if
506 test="generate-id(current()) != generate-id(../*[last()])">
507 <xsl:text>; </xsl:text>
508 </xsl:if>
509 </xsl:template>
511 <!--
512 Content Model: (field_name, field_body)
513 Attributes: The field element contains only the common attributes: ids,
514 names, dupnames, source, and classes.
516 <!-- == bibliographic_element -->
517 <xsl:template
518 match="docinfo/field">
519 <!-- contents handled by ordinary field lists -->
520 <xsl:apply-templates/>
521 <!-- Supply an EOL because following elements do not recognize this -->
522 &tEOL;
523 </xsl:template>
525 <!--
526 Content Model: %text.model;
527 Attributes: All docinfo elements contains the common attributes (ids,
528 names, dupnames, source, and classes)
529 Some docinfo elements also have xml:space.
531 <!-- == bibliographic_element == folding_element -->
532 <xsl:template
533 match="docinfo/*[name()!='authors' and name()!='field']">
534 <xsl:call-template
535 name="u:outputFolding">
536 <xsl:with-param
537 name="prefix">
538 <xsl:text>:</xsl:text>
539 <xsl:value-of
540 select="name()"/>
541 <xsl:text>: </xsl:text>
542 </xsl:with-param>
543 </xsl:call-template>
544 </xsl:template>
546 <!-- ******************************************************************** -->
548 <!--
549 Content Model: EMPTY
550 Attributes: The transition element contains only the common attributes:
551 ids, names, dupnames, source, and classes.
553 <!-- == structural_subelement -->
554 <xsl:template
555 match="transition">
556 <xsl:call-template
557 name="u:outputClass"/>
558 &tCR; <!-- req: blank line before -->
559 <xsl:text>-----</xsl:text>
560 &tEOL;
561 <!-- Add a required blank line after unless class follows immediately -->
562 <xsl:if
563 test="not(following-sibling::*[1]/@classes)">
564 &tCR;
565 </xsl:if>
566 </xsl:template>
568 <!-- ******************************************************************** -->
569 <!-- ******************************************************************** -->
571 <!--
572 IFF there is a /document/title element, it is the publication's title. All
573 other titles will appear within sections.
575 Content Model: %text.model;
576 Attributes: The title element contains the common attributes (ids, names,
577 dupnames, source, and classes), plus refid and auto.
578 refid is used as a backlink to a table of contents entry.
579 auto is used to indicate (with value "1") that the title has been
580 numbered automatically.
582 <!-- == structural_subelement -->
583 <xsl:template
584 match="//document/title">
585 <xsl:call-template
586 name="u:outputClass"/>
587 <xsl:variable
588 name="textWS">
589 <!-- Catch the title text as it is rendered so its length can be
590 determined -->
591 <xsl:apply-templates/>
592 </xsl:variable>
593 <xsl:variable
594 name="text"
595 select="normalize-space($textWS)"/>
596 <xsl:variable
597 name="length"
598 select="string-length($text)"/>
599 <xsl:call-template
600 name="u:overline">
601 <xsl:with-param
602 name="length"
603 select="$length"/>
604 <xsl:with-param
605 name="depth"
606 select="1"/>
607 </xsl:call-template>
608 <xsl:value-of
609 select="$text"/>
610 &tEOL;
611 <xsl:call-template
612 name="u:underline">
613 <xsl:with-param
614 name="length"
615 select="$length"/>
616 <xsl:with-param
617 name="depth"
618 select="1"/>
619 </xsl:call-template>
620 </xsl:template>
622 <!-- ******************************************************************** -->
624 <!--
625 Title Underlines are defined by their position within the tree.
627 Content Model: %text.model;
628 Attributes: The title element contains the common attributes (ids, names,
629 dupnames, source, and classes), plus refid and auto.
630 refid is used as a backlink to a table of contents entry.
631 auto is used to indicate (with value "1") that the title has been
632 numbered automatically.
634 <!-- == structural_subelement -->
635 <xsl:template
636 match="section/title">
637 <xsl:call-template
638 name="u:outputClass"/>
639 <xsl:variable
640 name="textWS">
641 <!-- catch the title text as it is rendered -->
642 <xsl:apply-templates/>
643 </xsl:variable>
644 <xsl:variable
645 name="text"
646 select="normalize-space($textWS)"/>
647 <xsl:variable
648 name="length"
649 select="string-length($text)"/>
650 <xsl:variable
651 name="depth"
652 select="count(ancestor::section)"/>
653 <xsl:call-template
654 name="u:overline">
655 <xsl:with-param
656 name="length"
657 select="$length"/>
658 <xsl:with-param
659 name="depth"
660 select="$depth + 2"/>
661 </xsl:call-template>
662 <xsl:value-of
663 select="$text"/>
664 &tEOL;
665 <xsl:call-template
666 name="u:underline">
667 <xsl:with-param
668 name="length"
669 select="$length"/>
670 <xsl:with-param
671 name="depth"
672 select="$depth + 2"/>
673 </xsl:call-template>
674 <!-- Add a blank line after unless structure follows immediately -->
675 <xsl:if
676 test="not(contains(concat($structural_elements, $compound_body_elements), concat('*', name(following-sibling::*[1]), '*')) or following-sibling::*[1]/@classes)">
677 &tCR;
678 </xsl:if>
679 </xsl:template>
681 <!-- ******************************************************************** -->
683 <!--
684 Content Model: %text.model;
685 Attributes: The title element contains the common attributes (ids, names,
686 dupnames, source, and classes), plus refid and auto.
687 refid is used as a backlink to a table of contents entry.
688 auto is used to indicate (with value "1") that the title has been
689 numbered automatically.
691 <!-- == structural_subelement -->
692 <xsl:template
693 match="title">
694 <xsl:call-template
695 name="u:outputClass">
696 <xsl:with-param
697 name="alreadyBlanked"
698 select="true()"/>
699 </xsl:call-template>
700 <!-- blank line provided by parent -->
701 <xsl:apply-templates/>
702 <!-- no EOL: provided by parent -->
703 </xsl:template>
705 <!-- ******************************************************************** -->
707 <!--
708 IFF there is a /document/title element, it is the publication's title. All
709 other titles will appear within sections.
711 Content Model: %text.model;
712 Attributes: The subtitle element contains only the common attributes:
713 ids, names, dupnames, source, and classes.
715 <!-- == structural_subelement -->
716 <xsl:template
717 match="//document/subtitle">
718 <xsl:call-template
719 name="u:outputClass"/>
720 <xsl:variable
721 name="textWS">
722 <!-- Catch the title text as it is rendered -->
723 <xsl:apply-templates/>
724 </xsl:variable>
725 <xsl:variable
726 name="text"
727 select="normalize-space($textWS)"/>
728 <xsl:variable
729 name="length"
730 select="string-length($text)"/>
732 <!-- always a blank line above -->
733 &tCR;
734 <xsl:call-template
735 name="u:overline">
736 <xsl:with-param
737 name="length"
738 select="$length"/>
739 <xsl:with-param
740 name="depth"
741 select="2"/>
742 </xsl:call-template>
743 <xsl:value-of
744 select="$text"/>
745 &tEOL;
746 <xsl:call-template
747 name="u:underline">
748 <xsl:with-param
749 name="length"
750 select="$length"/>
751 <xsl:with-param
752 name="depth"
753 select="2"/>
754 </xsl:call-template>
755 </xsl:template>
757 <!-- ******************************************************************** -->
759 <!--
760 Content Model: %text.model;
761 Attributes: The subtitle element contains only the common attributes: ids,
762 names, dupnames, source, and classes.
764 <!-- == structural_subelement -->
765 <xsl:template
766 match="sidebar/subtitle">
767 <xsl:call-template
768 name="u:outputClass"/>
769 <xsl:call-template
770 name="u:indent"/>
771 <xsl:apply-templates/>
772 &tEOL;
773 &tCR;
774 </xsl:template>
776 <!-- ******************************************************************** -->
777 <!-- ******************************************************************** -->
779 <!--
780 Content Model: %text.model;
781 Attributes: The comment element contains only the common attributes: ids,
782 names, dupnames, source, and classes.
784 <!-- == simple_body_element == folding_element == directive -->
785 <xsl:template
786 match="comment">
787 <xsl:call-template
788 name="u:BandI"/>
789 <xsl:call-template
790 name="u:outputFolding">
791 <xsl:with-param
792 name="prefix">
793 <xsl:text>.. </xsl:text>
794 </xsl:with-param>
795 </xsl:call-template>
796 </xsl:template>
798 <!-- ******************************************************************** -->
800 <!--
801 Content Model: %text.model;
802 Attributes: The doctest_block element contains the common attributes (ids,
803 names, dupnames, source, and classes), plus xml:space.
805 <!-- == simple_body_element -->
806 <xsl:template
807 match="doctest_block">
808 <xsl:call-template
809 name="u:outputClass"/>
810 <xsl:call-template
811 name="u:BandI"/>
812 <xsl:apply-templates/>
813 &tEOL;
814 </xsl:template>
816 <!-- ******************************************************************** -->
818 <!-- An image element can have various roles; they are all covered here -->
819 <!-- == simple_body_element == inline_element == directive -->
820 <xsl:template
821 match="image">
822 <xsl:choose>
823 <xsl:when
824 test="contains($inline_containers, concat('*', name(..), '*')) and @alt">
825 <!-- An inline image with an `@alt' - must be a substitution
826 reference -->
827 <xsl:text>|</xsl:text>
828 <!-- Original text is lost - use what we have -->
829 <xsl:value-of
830 select="@alt"/>
831 <xsl:text>|</xsl:text>
832 </xsl:when>
833 <xsl:otherwise>
834 <!-- A directive -->
835 <xsl:if
836 test="not(parent::figure)">
837 <xsl:if
838 test="not(parent::substitution_definition)">
839 <xsl:call-template
840 name="u:BandI"/>
841 <xsl:text>.. </xsl:text>
842 </xsl:if>
843 <xsl:text>image:: </xsl:text>
844 </xsl:if>
845 <xsl:value-of
846 select="@uri"/>
847 &tEOL;
848 <xsl:choose>
849 <xsl:when
850 test="parent::figure">
851 <!-- `@classes' is special because it is in the parent -->
852 <xsl:if
853 test="../@classes">
854 <xsl:call-template
855 name="u:param">
856 <xsl:with-param
857 name="name"
858 select="'figclass'"/>
859 <xsl:with-param
860 name="value"
861 select="../@classes"/>
862 <xsl:with-param
863 name="ancestors"
864 select="ancestor::*"/>
865 </xsl:call-template>
866 </xsl:if>
867 <!-- `@align' is special because it is in the parent -->
868 <xsl:if
869 test="../@align">
870 <xsl:call-template
871 name="u:param">
872 <xsl:with-param
873 name="name"
874 select="'align'"/>
875 <xsl:with-param
876 name="value"
877 select="../@align"/>
878 <xsl:with-param
879 name="ancestors"
880 select="ancestor::*"/>
881 </xsl:call-template>
882 </xsl:if>
883 <xsl:call-template
884 name="u:params">
885 <!-- `figure' would add one level of indentation -->
886 <xsl:with-param
887 name="ancestors"
888 select="ancestor::*"/>
889 </xsl:call-template>
890 </xsl:when>
891 <xsl:when
892 test="parent::substitution_definition">
893 <xsl:call-template
894 name="u:params">
895 <!-- `@alt' only for the real images -->
896 <xsl:with-param
897 name="params"
898 select="@*[name() != 'alt']"/>
899 </xsl:call-template>
900 </xsl:when>
901 <xsl:otherwise>
902 <xsl:call-template
903 name="u:params">
904 <xsl:with-param
905 name="params"
906 select="@*[name() != 'ids' and name() != 'names']"/>
907 </xsl:call-template>
908 </xsl:otherwise>
909 </xsl:choose>
910 <xsl:if
911 test="parent::reference">
912 <!-- A clickable image -->
913 <xsl:call-template
914 name="u:param">
915 <xsl:with-param
916 name="name"
917 select="'target'"/>
918 <xsl:with-param
919 name="value">
920 <xsl:choose>
921 <xsl:when
922 test="../@name">
923 <!-- An internal link -->
924 <xsl:call-template
925 name="u:inlineReference">
926 <xsl:with-param
927 name="text"
928 select="../@refid"/>
929 </xsl:call-template>
930 </xsl:when>
931 <xsl:otherwise>
932 <!-- An external link -->
933 <xsl:value-of
934 select="../@refuri"/>
935 </xsl:otherwise>
936 </xsl:choose>
937 </xsl:with-param>
938 <xsl:with-param
939 name="ancestors"
940 select="ancestor-or-self::*"/>
941 </xsl:call-template>
942 </xsl:if>
943 <!-- Always blank line after parameter block -->
944 &tCR;
945 </xsl:otherwise>
946 </xsl:choose>
947 </xsl:template>
949 <!-- ******************************************************************** -->
951 <!--
952 Content Model: (line_block | line)+
953 Attributes: The line_block element contains the common attributes (ids,
954 names, dupnames, source, and classes), plus xml:space.
956 <!-- == compound_body_element -->
957 <xsl:template
958 match="line_block">
959 <xsl:call-template
960 name="u:outputClass"/>
961 <xsl:variable
962 name="isEmbedded"
963 select="name(..) = 'line_block'"/>
964 <xsl:if
965 test="not($isEmbedded)">
966 <xsl:call-template
967 name="u:blank"/>
968 </xsl:if>
969 <xsl:apply-templates/>
970 </xsl:template>
972 <!-- ******************************************************************** -->
974 <!--
975 Content Model: %text.model;
976 Attributes: The line element contains the common attributes (ids,
977 names, dupnames, source, and classes).
979 <!-- == simple_body_subelement == folding_element -->
980 <xsl:template
981 match="line">
982 <xsl:call-template
983 name="u:outputClass"/>
984 <xsl:variable
985 name="indent">
986 <xsl:call-template
987 name="u:indent"/>
988 </xsl:variable>
989 <xsl:value-of
990 select="$indent"/>
991 <xsl:choose>
992 <xsl:when
993 test="node()">
994 <!-- Only for non-empty lines -->
995 <xsl:variable
996 name="lineBlockIndent">
997 <!-- Very special indendation for nested `line_block's -->
998 <xsl:for-each
999 select="ancestor::line_block[position() > 1]">
1000 <xsl:call-template
1001 name="u:repeat">
1002 <xsl:with-param
1003 name="length"
1004 select="4"/>
1005 </xsl:call-template>
1006 </xsl:for-each>
1007 </xsl:variable>
1008 <xsl:call-template
1009 name="u:outputFolding">
1010 <xsl:with-param
1011 name="prefix">
1012 <xsl:text>| </xsl:text>
1013 <xsl:value-of
1014 select="$lineBlockIndent"/>
1015 </xsl:with-param>
1016 <xsl:with-param
1017 name="indent"
1018 select="concat($indent, ' ', $lineBlockIndent)"/>
1019 </xsl:call-template>
1020 </xsl:when>
1021 <xsl:otherwise>
1022 <xsl:text>|</xsl:text>
1023 &tEOL;
1024 </xsl:otherwise>
1025 </xsl:choose>
1026 </xsl:template>
1028 <!-- ******************************************************************** -->
1030 <!--
1031 Content Model: %text.model;
1032 Attributes: The literal_block element contains the common attributes (ids,
1033 names, dupnames, source, and classes), plus xml:space.
1035 <!-- == simple_body_element == directive -->
1036 <xsl:template
1037 match="literal_block">
1038 <xsl:choose>
1039 <xsl:when
1040 test=".//*[contains($inline_elements, concat('*', name(), '*'))]">
1041 <!-- If it contains inline elements this is a parsed-literal -->
1042 <xsl:call-template
1043 name="u:BandI"/>
1044 <xsl:text>.. parsed-literal::</xsl:text>
1045 &tEOL;
1046 <xsl:call-template
1047 name="u:params"/>
1048 &tCR;
1049 </xsl:when>
1050 <xsl:otherwise>
1051 <xsl:call-template
1052 name="u:outputClass"/>
1053 <!-- TODO Support for the (fully) minimized style would be nice but
1054 is difficult to accomplish because there is a linefeed
1055 already when we arrive here :-( -->
1056 <xsl:call-template
1057 name="u:BandI"/>
1058 <xsl:text>::</xsl:text>
1059 &tEOL;
1060 &tCR;
1061 </xsl:otherwise>
1062 </xsl:choose>
1063 <xsl:variable
1064 name="isQuotedLiteral">
1065 <xsl:call-template
1066 name="u:isQuotedLiteral"/>
1067 </xsl:variable>
1068 <!-- Indent correctly depending on quoted literal or not -->
1069 <xsl:choose>
1070 <xsl:when
1071 test="string-length($isQuotedLiteral)">
1072 <xsl:call-template
1073 name="u:indent">
1074 <xsl:with-param
1075 name="ancestors"
1076 select="ancestor::*"/>
1077 </xsl:call-template>
1078 <xsl:apply-templates
1079 mode="quotedLiteral"/>
1080 </xsl:when>
1081 <xsl:otherwise>
1082 <xsl:call-template
1083 name="u:indent">
1084 <xsl:with-param
1085 name="ancestors"
1086 select="ancestor-or-self::*"/>
1087 </xsl:call-template>
1088 <xsl:apply-templates/>
1089 </xsl:otherwise>
1090 </xsl:choose>
1091 &tEOL;
1092 </xsl:template>
1094 <!-- Indent a text of a quoted literal containing line feeds correctly -->
1095 <xsl:template
1096 match="text()"
1097 mode="quotedLiteral">
1098 <xsl:call-template
1099 name="u:indentLF">
1100 <xsl:with-param
1101 name="indent">
1102 <xsl:call-template
1103 name="u:indent">
1104 <xsl:with-param
1105 name="ancestors"
1106 select="ancestor::*[position() > 1]"/>
1107 </xsl:call-template>
1108 </xsl:with-param>
1109 </xsl:call-template>
1110 </xsl:template>
1112 <!-- Determine whether `$text' is a quoted literal and return the quote
1113 character if so -->
1114 <xsl:template
1115 name="u:isQuotedLiteral">
1116 <xsl:param
1117 name="text"
1118 select="text()"/>
1119 <xsl:param
1120 name="quote"
1121 select="substring($text, 1, 1)"/>
1122 <xsl:if
1123 test="contains($adornment_characters, $quote) and substring($text, 1, 1) = $quote">
1124 <!-- Given quote is an adornment character and first character is this
1125 quote -->
1126 <xsl:choose>
1127 <xsl:when
1128 test="contains($text, '&#xA;')">
1129 <!-- Test the remaining lines -->
1130 <xsl:call-template
1131 name="u:isQuotedLiteral">
1132 <xsl:with-param
1133 name="text"
1134 select="substring-after($text, '&#xA;')"/>
1135 <xsl:with-param
1136 name="quote"
1137 select="$quote"/>
1138 </xsl:call-template>
1139 </xsl:when>
1140 <xsl:otherwise>
1141 <!-- No more lines to test so this is a quoted literal -->
1142 <xsl:value-of
1143 select="$quote"/>
1144 </xsl:otherwise>
1145 </xsl:choose>
1146 </xsl:if>
1147 </xsl:template>
1149 <!-- ******************************************************************** -->
1151 <!--
1152 Content Model: %text.model;
1153 Attributes: The paragraph element contains only the common attributes:
1154 ids, names, dupnames, source, and classes.
1156 <!-- == simple_body_element == folding_element -->
1157 <xsl:template
1158 match="paragraph">
1159 <xsl:variable
1160 name="previous"
1161 select="preceding-sibling::*[1]"/>
1162 <!-- Do indent except first element in some compound elements -->
1163 <xsl:variable
1164 name="needsIndent"
1165 select="($previous or not(parent::list_item or parent::field_body or contains($admonitions, concat('*', name(..), '*')))) and name($previous) != 'label'"/>
1166 <!-- Blank line in front if following a body element, except first
1167 elements in some compound elements -->
1168 <xsl:variable
1169 name="needsBlank"
1170 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')"/>
1171 <xsl:if
1172 test="$needsBlank">
1173 &tCR;
1174 </xsl:if>
1175 <xsl:if
1176 test="$needsIndent">
1177 <xsl:call-template
1178 name="u:indent"/>
1179 </xsl:if>
1180 <xsl:if
1181 test="@classes">
1182 <!-- This paragraph has a classes attribute - always needs newline and
1183 indent -->
1184 <xsl:call-template
1185 name="u:outputClass">
1186 <xsl:with-param
1187 name="alreadyBlanked"
1188 select="$needsBlank"/>
1189 <xsl:with-param
1190 name="alreadyIndented"
1191 select="$needsIndent"/>
1192 </xsl:call-template>
1193 <xsl:call-template
1194 name="u:BandI"/>
1195 </xsl:if>
1196 <xsl:call-template
1197 name="u:outputFolding"/>
1198 </xsl:template>
1200 <!-- ******************************************************************** -->
1202 <!-- == simple_body_element -->
1203 <xsl:template
1204 match="pending">
1205 <xsl:call-template
1206 name="u:notSupported"/>
1207 </xsl:template>
1209 <!-- ******************************************************************** -->
1211 <!-- == simple_body_element == inline_element == directive -->
1212 <xsl:template
1213 match="raw">
1214 <xsl:choose>
1215 <xsl:when
1216 test="contains($inline_containers, concat('*', name(..), '*'))">
1217 <!-- Used as a custom role -->
1218 <!-- TODO `role' directives must be generated for user-defined raw
1219 roles. -->
1220 <!-- The name of the custom role is not contained in the input -->
1221 <xsl:text>:RAW-ROLE:`</xsl:text>
1222 <xsl:apply-templates/>
1223 <xsl:text>`</xsl:text>
1224 </xsl:when>
1225 <xsl:otherwise>
1226 <!-- A directive -->
1227 <xsl:call-template
1228 name="u:outputClass"/>
1229 <xsl:call-template
1230 name="u:BandI"/>
1231 <xsl:text>.. raw:: </xsl:text>
1232 <xsl:value-of
1233 select="@format"/>
1234 &tEOL;
1235 <xsl:call-template
1236 name="u:params">
1237 <xsl:with-param
1238 name="params"
1239 select="@*[name() != 'format' and name() != 'classes']"/>
1240 </xsl:call-template>
1241 &tCR;
1242 <xsl:call-template
1243 name="u:indent">
1244 <xsl:with-param
1245 name="ancestors"
1246 select="ancestor-or-self::*"/>
1247 </xsl:call-template>
1248 <xsl:apply-templates/>
1249 &tEOL;
1250 </xsl:otherwise>
1251 </xsl:choose>
1252 </xsl:template>
1254 <!-- ******************************************************************** -->
1256 <!-- == simple_body_element == folding_element == directive -->
1257 <xsl:template
1258 match="rubric">
1259 <xsl:call-template
1260 name="u:BandI"/>
1261 <xsl:call-template
1262 name="u:outputFolding">
1263 <xsl:with-param
1264 name="prefix">
1265 <xsl:text>.. rubric:: </xsl:text>
1266 </xsl:with-param>
1267 </xsl:call-template>
1268 <xsl:call-template
1269 name="u:params"/>
1270 </xsl:template>
1272 <!-- ******************************************************************** -->
1274 <!-- == compound_body_element == directive -->
1275 <xsl:template
1276 match="compound">
1277 <xsl:call-template
1278 name="u:BandI"/>
1279 <xsl:text>.. compound::</xsl:text>
1280 &tEOL;
1281 <xsl:call-template
1282 name="u:params"/>
1283 <xsl:apply-templates/>
1284 </xsl:template>
1286 <!-- ******************************************************************** -->
1288 <!-- == compound_body_element == directive -->
1289 <xsl:template
1290 match="container">
1291 <xsl:call-template
1292 name="u:BandI"/>
1293 <xsl:text>.. container::</xsl:text>
1294 <xsl:if
1295 test="@classes">
1296 &tSP;
1297 <xsl:value-of
1298 select="@classes"/>
1299 </xsl:if>
1300 &tEOL;
1301 <xsl:apply-templates/>
1302 </xsl:template>
1304 <!-- ******************************************************************** -->
1306 <!-- == simple_body_element == directive -->
1307 <xsl:template
1308 match="substitution_definition">
1309 <!-- More than one child or not a directive is a replacement text -->
1310 <xsl:variable
1311 name="isReplace"
1312 select="not(* and count(node()) = 1 and contains($directives, concat('*', name(*[1]), '*')))"/>
1313 <xsl:call-template
1314 name="u:BandI"/>
1315 <xsl:variable
1316 name="prefix">
1317 <xsl:text>.. |</xsl:text>
1318 <xsl:call-template
1319 name="u:outputNames"/>
1320 <xsl:text>| </xsl:text>
1321 </xsl:variable>
1322 <xsl:choose>
1323 <xsl:when
1324 test="$isReplace">
1325 <!-- TODO Substitution references for replace can not be found because
1326 they are not marked as such; embedding them in `generated'
1327 would be nice -->
1328 <xsl:call-template
1329 name="u:outputFolding">
1330 <xsl:with-param
1331 name="prefix">
1332 <xsl:value-of
1333 select="$prefix"/>
1334 <xsl:text>replace:: </xsl:text>
1335 </xsl:with-param>
1336 </xsl:call-template>
1337 </xsl:when>
1338 <xsl:otherwise>
1339 <xsl:value-of
1340 select="$prefix"/>
1341 <xsl:apply-templates/>
1342 </xsl:otherwise>
1343 </xsl:choose>
1344 </xsl:template>
1346 <!-- ******************************************************************** -->
1348 <!--
1349 Content Model: ((%body.elements;)+, attribution?)
1350 Attributes: The block_quote element contains only the common attributes:
1351 ids, names, dupnames, source, and classes.
1353 <!-- == compound_body_element -->
1354 <xsl:template
1355 match="block_quote">
1356 <xsl:if
1357 test="@classes = 'epigraph' or @classes = 'highlights' or @classes = 'pull-quote'">
1358 <xsl:call-template
1359 name="u:BandI"/>
1360 <xsl:text>.. </xsl:text>
1361 <xsl:value-of
1362 select="@classes"/>
1363 <xsl:text>::</xsl:text>
1364 &tEOL;
1365 <xsl:call-template
1366 name="u:params"/>
1367 </xsl:if>
1368 <xsl:apply-templates/>
1369 </xsl:template>
1371 <!-- ******************************************************************** -->
1373 <!-- == simple_body_subelement == folding_element -->
1374 <xsl:template
1375 match="attribution">
1376 <xsl:call-template
1377 name="u:outputClass"/>
1378 <!-- blank line between quote and attribution -->
1379 &tCR;
1380 <xsl:call-template
1381 name="u:indent"/>
1382 <xsl:call-template
1383 name="u:outputFolding">
1384 <xsl:with-param
1385 name="prefix">
1386 <xsl:text>-- </xsl:text>
1387 </xsl:with-param>
1388 </xsl:call-template>
1389 </xsl:template>
1391 <!-- ******************************************************************** -->
1393 <!-- == compound_body_element == directive -->
1394 <xsl:template
1395 match="citation">
1396 <xsl:call-template
1397 name="u:outputClass"/>
1398 <xsl:call-template
1399 name="u:BandI"/>
1400 <xsl:text>.. [</xsl:text>
1401 <xsl:value-of
1402 select="label"/>
1403 <xsl:text>] </xsl:text>
1404 <xsl:apply-templates
1405 select="*[not(self::label)]"/>
1406 </xsl:template>
1408 <!-- == simple_body_subelement -->
1409 <xsl:template
1410 match="citation/label">
1411 <xsl:apply-templates/>
1412 </xsl:template>
1414 <!-- ******************************************************************** -->
1416 <!-- == compound_body_element == directive -->
1417 <xsl:template
1418 match="figure">
1419 <xsl:call-template
1420 name="u:BandI"/>
1421 <xsl:text>.. figure:: </xsl:text>
1422 <xsl:apply-templates/>
1423 </xsl:template>
1425 <!-- ******************************************************************** -->
1427 <!-- == simple_body_subelement == folding_element -->
1428 <xsl:template
1429 match="caption">
1430 <xsl:call-template
1431 name="u:indent"/>
1432 <xsl:call-template
1433 name="u:outputFolding"/>
1434 </xsl:template>
1436 <!-- ******************************************************************** -->
1438 <!-- == compound_body_subelement -->
1439 <xsl:template
1440 match="legend">
1441 <xsl:apply-templates/>
1442 </xsl:template>
1444 <!-- ******************************************************************** -->
1446 <!-- TODO Footnotes should continue on line of definition -->
1448 <!-- user-numbered footnotes lack @auto -->
1449 <!-- == compound_body_element == directive -->
1450 <xsl:template
1451 match="footnote[not(@auto)]">
1452 <xsl:call-template
1453 name="u:outputClass"/>
1454 <xsl:call-template
1455 name="u:BandI"/>
1456 <xsl:text>.. [</xsl:text>
1457 <xsl:apply-templates
1458 select="label"/>
1459 <xsl:text>] </xsl:text>
1460 <xsl:apply-templates
1461 select="*[not(self::label)]"/>
1462 </xsl:template>
1464 <!-- autonumbered footnotes have @auto -->
1465 <!-- if the target footnote_reference@names matches its label, it was not a
1466 numbered-name footnote -->
1467 <!-- == compound_body_element == directive -->
1468 <xsl:template
1469 match="footnote[@auto='1']">
1470 <xsl:call-template
1471 name="u:outputClass"/>
1472 <xsl:call-template
1473 name="u:BandI"/>
1474 <xsl:text>.. [#</xsl:text>
1475 <xsl:if
1476 test="@names = @ids">
1477 <xsl:call-template
1478 name="u:outputNames"/>
1479 </xsl:if>
1480 <xsl:text>] </xsl:text>
1481 <xsl:apply-templates
1482 select="*[not(self::label)]"/>
1483 </xsl:template>
1485 <!-- autosymboled footnotes have @auto -->
1486 <!-- == compound_body_element == directive -->
1487 <xsl:template
1488 match="footnote[@auto='*']">
1489 <xsl:call-template
1490 name="u:outputClass"/>
1491 <xsl:call-template
1492 name="u:BandI"/>
1493 <xsl:text>.. [*] </xsl:text>
1494 <xsl:apply-templates
1495 select="*[not(self::label)]"/>
1496 </xsl:template>
1498 <!-- == compound_body_element == directive -->
1499 <xsl:template
1500 match="footnote[starts-with(@names, 'TARGET_NOTE:\ ')]">
1501 <!-- This is not a footnote but a hint for a directive -->
1502 <xsl:if
1503 test="generate-id(//footnote[starts-with(@names, 'TARGET_NOTE:\ ')][1]) = generate-id(.)">
1504 <!-- Only for the first one -->
1505 <xsl:call-template
1506 name="u:BandI"/>
1507 <!-- TODO May have a `classes` attribute -->
1508 <xsl:text>.. target-notes::</xsl:text>
1509 &tEOL;
1510 </xsl:if>
1511 </xsl:template>
1513 <!-- == simple_body_subelement -->
1514 <xsl:template
1515 match="footnote/label">
1516 <xsl:apply-templates/>
1517 </xsl:template>
1519 <!-- ******************************************************************** -->
1521 <!--
1522 Content Model: (list_item +)
1523 Attributes: The bullet_list element contains the common attributes (ids,
1524 names, dupnames, source, and classes), plus bullet.
1525 bullet is used to record the style of bullet from the input data.
1526 In documents processed from reStructuredText, it contains one of "-",
1527 "+", or "*". It may be ignored in processing.
1529 <!-- == compound_body_element -->
1530 <xsl:template
1531 match="bullet_list">
1532 <xsl:call-template
1533 name="u:outputClass"/>
1534 <xsl:apply-templates
1535 mode="bullet_list"/>
1536 </xsl:template>
1538 <!-- ******************************************************************** -->
1540 <!--
1541 Content Model: (definition_list_item +)
1542 Attributes: The definition_list element contains only the common
1543 attributes: ids, names, dupnames, source, and classes.
1545 <!-- == compound_body_element -->
1546 <xsl:template
1547 match="definition_list">
1548 <xsl:call-template
1549 name="u:outputClass"/>
1550 <xsl:apply-templates/>
1551 </xsl:template>
1553 <!-- ******************************************************************** -->
1555 <!--
1556 Content Model: (term, classifier?, definition)
1557 Attributes: The definition_list_item element contains only the common
1558 attributes: ids, names, dupnames, source, and classes.
1560 <!-- == compound_body_subelement -->
1561 <xsl:template
1562 match="definition_list_item">
1563 <xsl:call-template
1564 name="u:outputClass"/>
1565 <xsl:call-template
1566 name="u:BandI"/>
1567 <xsl:apply-templates/>
1568 </xsl:template>
1570 <!-- ******************************************************************** -->
1572 <!--
1573 Content Model: %text.model;
1574 Attributes: The term element contains only the common attributes: ids,
1575 names, dupnames, source, and classes.
1577 <!-- == simple_body_subelement -->
1578 <xsl:template
1579 match="term">
1580 <xsl:apply-templates/>
1581 </xsl:template>
1583 <!-- ******************************************************************** -->
1585 <!--
1586 Content Model: %text.model;
1587 Attributes: The classifier element contains only the common attributes:
1588 ids, names, dupnames, source, and classes.
1590 <!-- == simple_body_subelement -->
1591 <xsl:template
1592 match="classifier">
1593 <xsl:text> : </xsl:text>
1594 <xsl:apply-templates/>
1595 </xsl:template>
1597 <!-- ******************************************************************** -->
1599 <!--
1600 Content Model: (%body.elements;)+
1601 Attributes: The definition element contains only the common attributes:
1602 ids, names, dupnames, source, and classes.
1604 <!-- == compound_body_subelement -->
1605 <xsl:template
1606 match="definition">
1607 <xsl:call-template
1608 name="u:outputClass"/>
1609 <xsl:apply-templates/>
1610 </xsl:template>
1612 <!-- ******************************************************************** -->
1614 <!--
1615 Content Model: (list_item +)
1616 Attributes: The enumerated_list element contains the common attributes
1617 (ids, names, dupnames, source, and classes), plus enumtype, prefix, suffix, and
1618 start.
1619 enumtype is used to record the intended enumeration sequence, one
1620 of "arabic" (1, 2, 3, ...), "loweralpha" (a, b, c, ..., z), "upperalpha" (A,
1621 B, C, ..., Z), "lowerroman" (i, ii, iii, iv, ..., mmmmcmxcix [4999]), or
1622 "upperroman" (I, II, III, IV, ..., MMMMCMXCIX [4999]).
1623 prefix stores the formatting characters used before the enumerator. In
1624 documents originating from reStructuredText data, it will contain either ""
1625 (empty string) or "(" (left parenthesis). It may or may not affect
1626 processing.
1627 suffix stores the formatting characters used after the enumerator. In
1628 documents originating from reStructuredText data, it will contain either "."
1629 (period) or ")" (right parenthesis). Depending on the capabilities of the
1630 output format, this attribute may or may not affect processing.
1631 start contains the ordinal value of the first item in the list, in
1632 decimal. For lists beginning at value 1 ("1", "a", "A", "i", or "I"), this
1633 attribute may be omitted.
1635 <!-- == compound_body_element -->
1636 <xsl:template
1637 match="enumerated_list">
1638 <xsl:call-template
1639 name="u:outputClass"/>
1640 <xsl:apply-templates
1641 mode="enumerated_list"/>
1642 </xsl:template>
1644 <!-- ******************************************************************** -->
1646 <!--
1647 Content Model: (field +)
1648 Attributes: The field_list element contains only the common attributes:
1649 ids, names, dupnames, source, and classes.
1651 <!-- == compound_body_element -->
1652 <xsl:template
1653 match="field_list">
1654 <xsl:call-template
1655 name="u:outputClass"/>
1656 <xsl:apply-templates/>
1657 </xsl:template>
1659 <!-- ******************************************************************** -->
1661 <!--
1662 Content Model: (field_name, field_body)
1663 Attributes: The field element contains only the common attributes: ids,
1664 names, dupnames, source, and classes.
1666 <!-- == compound_body_subelement -->
1667 <xsl:template
1668 match="field">
1669 <xsl:call-template
1670 name="u:outputClass"/>
1671 <xsl:call-template
1672 name="u:BandI"/>
1673 <xsl:apply-templates/>
1674 </xsl:template>
1676 <!-- ********************************************************************** -->
1678 <!--
1679 Content Model: %text.model;
1680 Attributes: The field_name element contains only the common attributes:
1681 ids, names, dupnames, source, and classes.
1683 <!-- == simple_body_subelement -->
1684 <xsl:template
1685 match="field_name">
1686 <xsl:text>:</xsl:text>
1687 <xsl:apply-templates/>
1688 <xsl:text>: </xsl:text>
1689 <!-- no EOL: field_body starts on same line -->
1690 </xsl:template>
1692 <!-- ******************************************************************** -->
1694 <!--
1695 Content Model: (%body.elements;)*
1696 Attributes: The field_body element contains only the common attributes:
1697 ids, names, dupnames, source, and classes.
1699 <!-- == compound_body_subelement -->
1700 <xsl:template
1701 match="field_body">
1702 <xsl:call-template
1703 name="u:outputClass"/>
1704 <xsl:apply-templates/>
1705 </xsl:template>
1707 <!-- ******************************************************************** -->
1709 <!--
1710 Content Model: (option_list_item +)
1711 Attributes: The option_list element contains only the common attributes:
1712 ids, names, dupnames, source, and classes.
1714 <!-- == compound_body_element -->
1715 <xsl:template
1716 match="option_list">
1717 <xsl:call-template
1718 name="u:outputClass"/>
1719 <xsl:call-template
1720 name="u:blank"/>
1721 <xsl:apply-templates/>
1722 </xsl:template>
1724 <!-- ******************************************************************** -->
1726 <!--
1727 Content Model: (option_group, description)
1728 Attributes: The option_list_item element contains only the common
1729 attributes: ids, names, dupnames, source, and classes.
1731 <!-- == compound_body_subelement -->
1732 <xsl:template
1733 match="option_list_item">
1734 <xsl:call-template
1735 name="u:outputClass"/>
1736 <xsl:call-template
1737 name="u:indent"/>
1738 <xsl:apply-templates/>
1739 </xsl:template>
1741 <!-- ******************************************************************** -->
1743 <!--
1744 Content Model: (option_group, description)
1745 Attributes: The option_group element contains only the common attributes:
1746 ids, names, dupnames, source, and classes.
1748 <!-- == compound_body_subelement -->
1749 <xsl:template
1750 match="option_group">
1751 <xsl:apply-templates/>
1752 &tEOL;
1753 </xsl:template>
1755 <!-- ******************************************************************** -->
1757 <!--
1758 Content Model: (option_string, option_argument *)
1759 Attributes: The option element contains only the common attributes: ids,
1760 names, dupnames, source, and classes.
1762 <!-- == compound_body_subelement -->
1763 <xsl:template
1764 match="option">
1765 <xsl:call-template
1766 name="u:outputClass"/>
1767 <xsl:apply-templates/>
1768 <xsl:if
1769 test="generate-id(current()) != generate-id(../*[last()])">
1770 <!-- No comma after final option -->
1771 <xsl:text>, </xsl:text>
1772 </xsl:if>
1773 <!-- no EOL: description on same line -->
1774 </xsl:template>
1776 <!-- ******************************************************************** -->
1778 <!--
1779 Content Model: (#PCDATA)
1780 Attributes: The option_string element contains only the common attributes:
1781 ids, names, dupnames, source, and classes.
1783 <!-- == simple_body_subelement -->
1784 <xsl:template
1785 match="option_string">
1786 <xsl:apply-templates/>
1787 </xsl:template>
1789 <!-- ******************************************************************** -->
1791 <!--
1792 Content Model: (#PCDATA)
1793 Attributes: The option_argument element contains the common attributes
1794 (ids, names, dupnames, source, and classes), plus delimiter.
1795 delimiter contains the text preceding the option_argument:
1796 either the text separating it from the option_string (typically
1797 either "=" or " ")
1798 or the text between option arguments (typically either "," or " ").
1800 <!-- == simple_body_subelement -->
1801 <xsl:template
1802 match="option_argument">
1803 <xsl:value-of
1804 select="@delimiter"/>
1805 <xsl:apply-templates/>
1806 </xsl:template>
1808 <!-- ******************************************************************** -->
1810 <!--
1811 Content Model: (%body.elements;)+
1812 Attributes: The description element contains only the common attributes:
1813 ids, names, dupnames, source, and classes.
1815 <!-- == compound_body_subelement -->
1816 <xsl:template
1817 match="description">
1818 <xsl:call-template
1819 name="u:outputClass"/>
1820 <xsl:apply-templates/>
1821 &tEOL;
1822 </xsl:template>
1824 <!-- ******************************************************************** -->
1826 <!--
1827 Content Model: (%body.elements;)+
1828 Attributes: The list_item element contains only the common attributes:
1829 ids, names, dupnames, source, and classes
1831 BULLET LIST
1832 bullet is used to record the style of bullet from the input data.
1833 In documents processed from reStructuredText, it contains one of "-",
1834 "+", or "*". It may be ignored in processing.
1836 <!-- == compound_body_subelement -->
1837 <xsl:template
1838 match="list_item"
1839 mode="bullet_list">
1840 <xsl:call-template
1841 name="u:outputClass"/>
1842 <xsl:if
1843 test="name(*[1]) != 'bullet_list'">
1844 <!-- Start the list item only if the first child is not another list -->
1845 <xsl:call-template
1846 name="u:BandI"/>
1847 <xsl:value-of
1848 select="../@bullet"/>
1849 &tSP; <!-- space after bullet -->
1850 </xsl:if>
1851 <xsl:apply-templates/>
1852 </xsl:template>
1854 <!-- ******************************************************************** -->
1856 <!--
1857 ENUMERATED LIST
1858 enumtype is used to record the intended enumeration sequence, one of
1859 "arabic" (1, 2, 3, ...), "loweralpha" (a, b, c, ..., z), "upperalpha" (A, B,
1860 C, ..., Z), "lowerroman" (i, ii, iii, iv, ..., mmmmcmxcix [4999]), or
1861 "upperroman" (I, II, III, IV, ..., MMMMCMXCIX [4999]).
1862 prefix stores the formatting characters used before the enumerator. In
1863 documents originating from reStructuredText data, it will contain either ""
1864 (empty string) or "(" (left parenthesis). It may or may not affect
1865 processing.
1866 suffix stores the formatting characters used after the enumerator. In
1867 documents originating from reStructuredText data, it will contain either "."
1868 (period) or ")" (right parenthesis). Depending on the capabilities of the
1869 output format, this attribute may or may not affect processing.
1870 start contains the ordinal value of the first item in the list, in
1871 decimal. For lists beginning at value 1 ("1", "a", "A", "i", or "I"), this
1872 attribute may be omitted.
1875 <!-- == compound_body_subelement -->
1876 <xsl:template
1877 match="list_item"
1878 mode="enumerated_list">
1879 <xsl:call-template
1880 name="u:outputClass"/>
1881 <xsl:call-template
1882 name="u:BandI"/>
1883 <xsl:call-template
1884 name="u:outputEnumerator"/>
1885 <xsl:apply-templates/>
1886 </xsl:template>
1888 <!-- Outputs a complete enumerator when called in an
1889 enumerated_list/list_item -->
1890 <xsl:template
1891 name="u:outputEnumerator">
1892 <!-- Use parent's numeration attribute -->
1893 <xsl:variable
1894 name="enumType"
1895 select="../@enumtype"/>
1896 <!-- Determine starting point -->
1897 <xsl:variable
1898 name="start">
1899 <xsl:choose>
1900 <xsl:when
1901 test="../@start">
1902 <xsl:value-of
1903 select="../@start"/>
1904 </xsl:when>
1905 <xsl:otherwise>
1906 <xsl:value-of
1907 select="1"/>
1908 </xsl:otherwise>
1909 </xsl:choose>
1910 </xsl:variable>
1911 <!-- Determine position of this item in its real context -->
1912 <xsl:variable
1913 name="position">
1914 <xsl:variable
1915 name="wanted"
1916 select="generate-id()"/>
1917 <!-- Generate the right current node list -->
1918 <xsl:for-each
1919 select="../list_item">
1920 <xsl:if
1921 test="generate-id() = $wanted">
1922 <xsl:value-of
1923 select="position()"/>
1924 </xsl:if>
1925 </xsl:for-each>
1926 </xsl:variable>
1927 <!-- Determine encoding of the number for the given numeration -->
1928 <xsl:variable
1929 name="cur">
1930 <xsl:call-template
1931 name="u:position2Enumerator">
1932 <xsl:with-param
1933 name="enumType"
1934 select="$enumType"/>
1935 <xsl:with-param
1936 name="position"
1937 select="$position"/>
1938 <xsl:with-param
1939 name="start"
1940 select="$start"/>
1941 </xsl:call-template>
1942 </xsl:variable>
1943 <!-- Determine encoding of the maximum number -->
1944 <xsl:variable
1945 name="max">
1946 <xsl:call-template
1947 name="u:position2Enumerator">
1948 <xsl:with-param
1949 name="enumType"
1950 select="$enumType"/>
1951 <xsl:with-param
1952 name="position"
1953 select="count(../list_item)"/>
1954 <xsl:with-param
1955 name="start"
1956 select="$start"/>
1957 </xsl:call-template>
1958 </xsl:variable>
1959 <!-- Output complete enumerator -->
1960 <xsl:value-of
1961 select="../@prefix"/>
1962 <xsl:value-of
1963 select="$cur"/>
1964 <xsl:value-of
1965 select="../@suffix"/>
1966 <!-- Output at least one trailing space -->
1967 &tSP;
1968 <!-- Output more whitespace to align with the maximum enumerator -->
1969 <xsl:if
1970 test="$enumType != 'lowerroman' and $enumType != 'upperroman'">
1971 <xsl:call-template
1972 name="u:repeat">
1973 <!-- Assumes that the maximum number has maximum string length -->
1974 <xsl:with-param
1975 name="length"
1976 select="string-length($max) - string-length($cur)"/>
1977 </xsl:call-template>
1978 </xsl:if>
1979 </xsl:template>
1981 <!-- Determine the right ordinal enumerator based on the parameters -->
1982 <xsl:template
1983 name="u:position2Enumerator">
1984 <xsl:param
1985 name="enumType"/>
1986 <xsl:param
1987 name="start"/>
1988 <xsl:param
1989 name="position"/>
1990 <!-- Determine logical number -->
1991 <xsl:variable
1992 name="ordinal"
1993 select="$start - 1 + $position"/>
1994 <xsl:choose>
1995 <xsl:when
1996 test="$enumType = 'arabic'">
1997 <xsl:value-of
1998 select="$ordinal"/>
1999 </xsl:when>
2000 <xsl:when
2001 test="$enumType = 'loweralpha'">
2002 <xsl:value-of
2003 select="substring('abcdefghijklmnopqrstzuvwxyz', $ordinal, 1)"/>
2004 </xsl:when>
2005 <xsl:when
2006 test="$enumType = 'upperalpha'">
2007 <xsl:value-of
2008 select="substring('ABCDEFGHIJKLMNOPQRSTZUVWXYZ', $ordinal, 1)"/>
2009 </xsl:when>
2010 <!-- TODO Support for counting roman numbers -->
2011 <xsl:when
2012 test="$enumType = 'lowerroman'">
2013 <xsl:text>i</xsl:text>
2014 </xsl:when>
2015 <xsl:when
2016 test="$enumType = 'upperroman'">
2017 <xsl:text>I</xsl:text>
2018 </xsl:when>
2019 </xsl:choose>
2020 </xsl:template>
2022 <!-- ******************************************************************** -->
2023 <!-- ******************************************************************** -->
2025 <!--
2026 Content Model: (title?, tgroup+)
2027 Attributes: The table element contains the common attributes and:
2028 frame, colsep, rowsep, pgwide
2030 <!-- == compound_body_element -->
2031 <xsl:template
2032 match="table">
2033 <xsl:call-template
2034 name="u:outputClass"/>
2035 <xsl:call-template
2036 name="u:blank"/>
2037 <xsl:apply-templates
2038 select="tgroup"/>
2039 <xsl:if
2040 test="title">
2041 <!-- TODO A table title must be rendered by using the `.. table::'
2042 directive -->
2043 <xsl:call-template
2044 name="u:BandI"/>
2045 <xsl:apply-templates
2046 select="title"/>
2047 &tEOL;
2048 </xsl:if>
2049 </xsl:template>
2051 <!-- ******************************************************************** -->
2053 <!--
2054 Content Model: (colspec*, thead?, tbody)
2055 Attributes: The tgroup element contains the common attributes and:
2056 cols, colsep, rowsep, align
2058 <!-- == compound_body_subelement -->
2059 <xsl:template
2060 match="tgroup">
2061 <xsl:apply-templates/>
2062 </xsl:template>
2064 <!-- ******************************************************************** -->
2066 <!--
2067 Content Model: EMPTY
2068 Attributes: The colspec element contains the common attributes and:
2069 colnum, colname, colwidth, colsep, rowsep, align, char, charoff
2071 The colwidth attribute gives the width of the respective column in characters
2072 including padding whitespace but no separator markup.
2074 <!-- == simple_body_subelement -->
2075 <!-- @colwidth needed by children but element has no own output -->
2076 <xsl:template
2077 match="colspec"/>
2079 <!-- ******************************************************************** -->
2081 <!--
2082 Content Model: (row+)
2083 Attributes: The thead element contains the common attributes and:
2084 valign
2086 <!-- == compound_body_subelement -->
2087 <xsl:template
2088 match="thead">
2089 <xsl:apply-templates/>
2090 </xsl:template>
2092 <!--
2093 Content Model: (row+)
2094 Attributes: The tbody element contains the common attributes and:
2095 valign
2097 <!-- == compound_body_subelement -->
2098 <xsl:template
2099 match="tbody">
2100 <xsl:apply-templates/>
2101 </xsl:template>
2103 <!-- ******************************************************************** -->
2105 <!--
2106 Content Model: (entry+)
2107 Attributes: The row element contains the common attributes and:
2108 rowsep, valign
2110 <!-- == compound_body_subelement -->
2111 <xsl:template
2112 match="row">
2113 <!-- Separator line above unless first row of a tbody with no previous
2114 thead (in this case the separator line is output already as the
2115 closing separator line of thead) -->
2116 <xsl:if
2117 test="position() > 1 or parent::thead or parent::tbody and not(../../thead)">
2118 <xsl:call-template
2119 name="u:rowSeparatorLine"/>
2120 </xsl:if>
2121 <!-- Determine heights in physical lines of all entries -->
2122 <xsl:variable
2123 name="heights">
2124 <xsl:for-each
2125 select="entry">
2126 <xsl:variable
2127 name="text">
2128 <!-- Catch the text of all entries -->
2129 <xsl:apply-templates/>
2130 </xsl:variable>
2131 <!-- Compute height of this entry; leading and trailing EOL must be
2132 subtracted -->
2133 <xsl:value-of
2134 select="string-length($text) - string-length(translate($text, '&#xA;', '')) - 1"/>
2135 &tSP; <!-- A space as a list separator -->
2136 </xsl:for-each>
2137 </xsl:variable>
2138 <!-- Determine maximum height so every entry must be this high -->
2139 <xsl:variable
2140 name="maxHeight">
2141 <xsl:call-template
2142 name="u:maxNumber">
2143 <xsl:with-param
2144 name="numbers"
2145 select="$heights"/>
2146 </xsl:call-template>
2147 </xsl:variable>
2148 <!-- Output all the physical lines of this row -->
2149 <xsl:call-template
2150 name="u:rowLines">
2151 <xsl:with-param
2152 name="currentLine"
2153 select="1"/>
2154 <xsl:with-param
2155 name="maxLine"
2156 select="$maxHeight"/>
2157 </xsl:call-template>
2158 <!-- Output final separator line if this is the last row -->
2159 <xsl:if
2160 test="position() = last()">
2161 <xsl:call-template
2162 name="u:rowSeparatorLine">
2163 <xsl:with-param
2164 name="char">
2165 <!-- Determine correct character for the separator line -->
2166 <xsl:choose>
2167 <xsl:when
2168 test="parent::thead">
2169 <xsl:value-of
2170 select="'='"/>
2171 </xsl:when>
2172 <xsl:otherwise>
2173 <xsl:value-of
2174 select="'-'"/>
2175 </xsl:otherwise>
2176 </xsl:choose>
2177 </xsl:with-param>
2178 </xsl:call-template>
2179 </xsl:if>
2180 </xsl:template>
2182 <!-- Output physical line $currentLine of a row and continue until
2183 line $maxLine is output -->
2184 <xsl:template
2185 name="u:rowLines">
2186 <xsl:param
2187 name="currentLine"/>
2188 <xsl:param
2189 name="maxLine"/>
2190 <xsl:if
2191 test="$currentLine &lt;= $maxLine">
2192 <!-- If there are still physical lines to output do it -->
2193 <xsl:call-template
2194 name="u:indent"/>
2195 <!-- Leading bar -->
2196 <xsl:text>|</xsl:text>
2197 <xsl:apply-templates>
2198 <xsl:with-param
2199 name="currentLine"
2200 select="$currentLine"/>
2201 </xsl:apply-templates>
2202 <!-- End of this physical line -->
2203 &tEOL;
2204 <!-- Continue with the next physical line -->
2205 <xsl:call-template
2206 name="u:rowLines">
2207 <xsl:with-param
2208 name="currentLine"
2209 select="$currentLine + 1"/>
2210 <xsl:with-param
2211 name="maxLine"
2212 select="$maxLine"/>
2213 </xsl:call-template>
2214 </xsl:if>
2215 </xsl:template>
2217 <!-- Output a separator line with all the right characters -->
2218 <xsl:template
2219 name="u:rowSeparatorLine">
2220 <xsl:param
2221 name="char"
2222 select="'-'"/>
2223 <xsl:call-template
2224 name="u:indent"/>
2225 <xsl:text>+</xsl:text>
2226 <xsl:for-each
2227 select="../../colspec">
2228 <xsl:call-template
2229 name="u:repeat">
2230 <xsl:with-param
2231 name="length"
2232 select="@colwidth"/>
2233 <xsl:with-param
2234 name="chars"
2235 select="$char"/>
2236 </xsl:call-template>
2237 <xsl:text>+</xsl:text>
2238 </xsl:for-each>
2239 &tEOL;
2240 </xsl:template>
2242 <!-- ******************************************************************** -->
2244 <!--
2245 Content Model: (%body.elements;)*
2246 Attributes: The entry element contains the common attributes and:
2247 colname, namest, morerows, colsep, rowsep, align, char, charoff, valign and
2248 morecols
2250 <!-- == compound_body_subelement -->
2251 <xsl:template
2252 match="entry">
2253 <!-- TODO `classes` attribute needs support -->
2254 <!-- This is called in two ways; if $currentLine = 0 all physical lines
2255 of this entry must be output; if $currentLine > 0 the physical line
2256 with exactly this number shall be output -->
2257 <xsl:param
2258 name="currentLine"
2259 select="0"/>
2260 <xsl:variable
2261 name="column"
2262 select="position() + sum(preceding-sibling::entry/@morecols)"/>
2263 <!-- Determine width in characters needed for this entry -->
2264 <xsl:variable
2265 name="width">
2266 <xsl:call-template
2267 name="u:computeEntryWidth">
2268 <xsl:with-param
2269 name="colspecs"
2270 select="../../../colspec"/>
2271 <xsl:with-param
2272 name="column"
2273 select="$column"/>
2274 <xsl:with-param
2275 name="span"
2276 select="@morecols"/>
2277 </xsl:call-template>
2278 </xsl:variable>
2279 <!-- Output the entry completely or a certain physical line -->
2280 <xsl:call-template
2281 name="u:outputEntry">
2282 <xsl:with-param
2283 name="string">
2284 <!-- Capture physical lines of the entry in a variable -->
2285 <xsl:apply-templates/>
2286 </xsl:with-param>
2287 <xsl:with-param
2288 name="width"
2289 select="$width"/>
2290 <xsl:with-param
2291 name="expectedIndent">
2292 <!-- Capture indent for the entry generated by the normal template
2293 rules to remove it later -->
2294 <xsl:call-template
2295 name="u:indent"/>
2296 </xsl:with-param>
2297 <xsl:with-param
2298 name="outputLine"
2299 select="$currentLine"/>
2300 </xsl:call-template>
2301 <!-- Final bar after the entry -->
2302 <xsl:text>|</xsl:text>
2303 </xsl:template>
2305 <!-- Compute width of the entry -->
2306 <xsl:template
2307 name="u:computeEntryWidth">
2308 <!-- The colspec elements of all columns -->
2309 <xsl:param
2310 name="colspecs"/>
2311 <!-- Column of this entry -->
2312 <xsl:param
2313 name="column"/>
2314 <!-- Number of columns this entry spans -->
2315 <xsl:param
2316 name="span"
2317 select="0"/>
2318 <xsl:param
2319 name="sum"
2320 select="0"/>
2321 <xsl:choose>
2322 <xsl:when
2323 test="$span">
2324 <!-- If entry spans multiple columns compute their width -->
2325 <xsl:call-template
2326 name="u:computeEntryWidth">
2327 <xsl:with-param
2328 name="colspecs"
2329 select="$colspecs"/>
2330 <xsl:with-param
2331 name="column"
2332 select="$column + 1"/>
2333 <xsl:with-param
2334 name="span"
2335 select="$span - 1"/>
2336 <!-- Add the separator character and the following column width -->
2337 <xsl:with-param
2338 name="sum"
2339 select="$sum + 1 + $colspecs[$column]/@colwidth"/>
2340 </xsl:call-template>
2341 </xsl:when>
2342 <xsl:otherwise>
2343 <!-- Does not span more columns so return sum and width of this
2344 column -->
2345 <xsl:value-of
2346 select="$sum + $colspecs[$column]/@colwidth"/>
2347 </xsl:otherwise>
2348 </xsl:choose>
2349 </xsl:template>
2351 <!-- Outputs one or all lines of a table entry as a string trimmed left and
2352 padded -->
2353 <xsl:template
2354 name="u:outputEntry">
2355 <!-- Width of the entry; there is no provision for actual physical lines
2356 longer than this width -->
2357 <xsl:param
2358 name="width"/>
2359 <!-- The string containing the remaining physical lines; may be an empty
2360 string -->
2361 <xsl:param
2362 name="string"
2363 select="''"/>
2364 <!-- The indendation which is expected to be prefixed before every
2365 physical line -->
2366 <xsl:param
2367 name="expectedIndent"
2368 select="''"/>
2369 <!-- Is this the first call to this template -->
2370 <xsl:param
2371 name="isFirst"
2372 select="true()"/>
2373 <!-- Number of physical line to output or 0 to output all lines -->
2374 <xsl:param
2375 name="outputLine"
2376 select="0"/>
2377 <!-- Output is wanted if all or the first physical line are to be
2378 output -->
2379 <xsl:variable
2380 name="doOutput"
2381 select="$outputLine = 0 or $outputLine = 1"/>
2382 <xsl:variable
2383 name="stringLFHalfTrimmed">
2384 <xsl:choose>
2385 <xsl:when
2386 test="$isFirst and substring($string, 1, 1) = '&#x0A;'">
2387 <!-- Remove leading linefeed if this is the first time -->
2388 <xsl:value-of
2389 select="substring($string, 2)"/>
2390 </xsl:when>
2391 <xsl:otherwise>
2392 <xsl:value-of
2393 select="$string"/>
2394 </xsl:otherwise>
2395 </xsl:choose>
2396 </xsl:variable>
2397 <xsl:variable
2398 name="stringLFTrimmed">
2399 <xsl:choose>
2400 <xsl:when
2401 test="$isFirst and substring($stringLFHalfTrimmed, string-length($stringLFHalfTrimmed), 1) = '&#x0A;'">
2402 <!-- Remove trailing linefeed if this is the first time -->
2403 <xsl:value-of
2404 select="substring($stringLFHalfTrimmed, 1, string-length($stringLFHalfTrimmed) - 1)"/>
2405 </xsl:when>
2406 <xsl:otherwise>
2407 <xsl:value-of
2408 select="$stringLFHalfTrimmed"/>
2409 </xsl:otherwise>
2410 </xsl:choose>
2411 </xsl:variable>
2412 <!-- Determine remaining lines after the first one -->
2413 <xsl:variable
2414 name="remainingLines">
2415 <xsl:if
2416 test="contains($stringLFTrimmed, '&#x0A;')">
2417 <xsl:value-of
2418 select="substring-after($stringLFTrimmed, '&#x0A;')"/>
2419 </xsl:if>
2420 </xsl:variable>
2421 <xsl:if
2422 test="$doOutput">
2423 <!-- If this physical line must be output determine the first physical
2424 line -->
2425 <xsl:variable
2426 name="firstLine">
2427 <xsl:choose>
2428 <xsl:when
2429 test="string-length($remainingLines)">
2430 <xsl:value-of
2431 select="substring-before($stringLFTrimmed, '&#x0A;')"/>
2432 </xsl:when>
2433 <xsl:otherwise>
2434 <xsl:value-of
2435 select="$stringLFTrimmed"/>
2436 </xsl:otherwise>
2437 </xsl:choose>
2438 </xsl:variable>
2439 <!-- Remove the leading indentation from the physical line which is
2440 brought there by the normal templates -->
2441 <xsl:variable
2442 name="trimmed">
2443 <xsl:if
2444 test="string-length($firstLine)">
2445 <!-- Trim only non-empty lines -->
2446 <xsl:value-of
2447 select="substring-after($firstLine, $expectedIndent)"/>
2448 </xsl:if>
2449 </xsl:variable>
2450 <!-- Pad the line with a leading and a trailing space -->
2451 <xsl:variable
2452 name="padded"
2453 select="concat(' ', $trimmed, ' ')"/>
2454 <!-- Output the padded value -->
2455 <xsl:value-of
2456 select="$padded"/>
2457 <!-- Fill up the width of the entry with spaces -->
2458 <xsl:if
2459 test="$width - string-length($padded) &lt; 0">
2460 <xsl:message>
2461 <xsl:text>WARNING: Table column too narrow (minimum: </xsl:text>
2462 <xsl:value-of
2463 select="string-length($padded)"/>
2464 <xsl:text>)</xsl:text>
2465 &tEOL;
2466 </xsl:message>
2467 </xsl:if>
2468 <xsl:call-template
2469 name="u:repeat">
2470 <xsl:with-param
2471 name="length"
2472 select="$width - string-length($padded)"/>
2473 </xsl:call-template>
2474 </xsl:if>
2475 <xsl:if
2476 test="$outputLine > 1 or $outputLine = 0 and string-length($remainingLines)">
2477 <!-- If a following physical line must be output or if all physical
2478 lines shall be output and there are remaining physical lines -->
2479 <xsl:if
2480 test="$outputLine = 0">
2481 <!-- Output linefeed only if we output all the lines -->
2482 &tEOL;
2483 </xsl:if>
2484 <!-- Output the remaining lines -->
2485 <xsl:call-template
2486 name="u:outputEntry">
2487 <xsl:with-param
2488 name="width"
2489 select="$width"/>
2490 <xsl:with-param
2491 name="string"
2492 select="$remainingLines"/>
2493 <xsl:with-param
2494 name="expectedIndent"
2495 select="$expectedIndent"/>
2496 <xsl:with-param
2497 name="isFirst"
2498 select="false()"/>
2499 <xsl:with-param
2500 name="outputLine">
2501 <xsl:choose>
2502 <xsl:when
2503 test="$outputLine = 0">
2504 <xsl:value-of
2505 select="0"/>
2506 </xsl:when>
2507 <xsl:otherwise>
2508 <xsl:value-of
2509 select="$outputLine - 1"/>
2510 </xsl:otherwise>
2511 </xsl:choose>
2512 </xsl:with-param>
2513 </xsl:call-template>
2514 </xsl:if>
2515 </xsl:template>
2517 <!-- ******************************************************************** -->
2518 <!-- ******************************************************************** -->
2520 <!-- == inline_element -->
2521 <xsl:template
2522 match="citation_reference">
2523 <xsl:call-template
2524 name="u:bkslshEscPre"/>
2525 <xsl:text>[</xsl:text>
2526 <xsl:apply-templates/>
2527 <xsl:text>]_</xsl:text>
2528 <xsl:call-template
2529 name="u:bkslshEscSuf"/>
2530 </xsl:template>
2532 <!-- ******************************************************************** -->
2534 <!-- == inline_element -->
2535 <xsl:template
2536 match="substitution_reference">
2537 <xsl:call-template
2538 name="u:bkslshEscPre"/>
2539 <xsl:text>|</xsl:text>
2540 <xsl:apply-templates/>
2541 <xsl:text>|</xsl:text>
2542 <xsl:call-template
2543 name="u:bkslshEscSuf"/>
2544 </xsl:template>
2546 <!-- ******************************************************************** -->
2548 <!-- == inline_element -->
2549 <xsl:template
2550 match="emphasis">
2551 <xsl:call-template
2552 name="u:bkslshEscPre"/>
2553 <xsl:text>*</xsl:text>
2554 <xsl:apply-templates/>
2555 <xsl:text>*</xsl:text>
2556 <xsl:call-template
2557 name="u:bkslshEscSuf"/>
2558 </xsl:template>
2560 <!-- ******************************************************************** -->
2562 <!-- user-numbered footnotes lack @auto -->
2563 <!-- == inline_element -->
2564 <xsl:template
2565 match="footnote_reference[not(@auto)]">
2566 <xsl:call-template
2567 name="u:bkslshEscPre"/>
2568 <xsl:text>[</xsl:text>
2569 <xsl:value-of
2570 select="text()"/>
2571 <xsl:text>]_</xsl:text>
2572 <xsl:call-template
2573 name="u:bkslshEscSuf"/>
2574 <!-- child paragraph provides blank line -->
2575 </xsl:template>
2577 <!-- automatically numbered footnotes have @auto -->
2578 <!-- if @names is different from label content, it is a named footnote -->
2579 <!-- == inline_element -->
2580 <xsl:template
2581 match="footnote_reference[@auto='1']">
2582 <xsl:variable
2583 name="ref"
2584 select="@refid"/>
2585 <xsl:if
2586 test="not(starts-with(//footnote[@ids=$ref]/@names, 'TARGET_NOTE:\ '))">
2587 <!-- Not a generated footnote reference for a `.. target-notes::';
2588 such footnote reference and the preceding space should be
2589 embedded in `generated'! -->
2590 <xsl:call-template
2591 name="u:bkslshEscPre"/>
2592 <xsl:text>[#</xsl:text>
2593 <xsl:if
2594 test="//footnote[@ids=$ref]/@names != //footnote[@ids=$ref]/label">
2595 <xsl:call-template
2596 name="u:outputNames">
2597 <xsl:with-param
2598 name="names"
2599 select="//footnote[@ids=$ref]/@names"/>
2600 </xsl:call-template>
2601 </xsl:if>
2602 <xsl:text>]_</xsl:text>
2603 <xsl:call-template
2604 name="u:bkslshEscSuf"/>
2605 </xsl:if>
2606 </xsl:template>
2608 <!-- automatically symboled footnotes have @auto=* -->
2609 <!-- == inline_element -->
2610 <xsl:template
2611 match="footnote_reference[@auto='*']">
2612 <xsl:call-template
2613 name="u:bkslshEscPre"/>
2614 <xsl:text>[*]_</xsl:text>
2615 <xsl:call-template
2616 name="u:bkslshEscSuf"/>
2617 </xsl:template>
2619 <!-- ******************************************************************** -->
2621 <!--
2622 Content Model: %text.model;
2624 <!-- == inline_element -->
2625 <xsl:template
2626 match="literal">
2627 <xsl:call-template
2628 name="u:bkslshEscPre"/>
2629 <xsl:text>``</xsl:text>
2630 <xsl:apply-templates/>
2631 <xsl:text>``</xsl:text>
2632 <xsl:call-template
2633 name="u:bkslshEscSuf"/>
2634 </xsl:template>
2636 <!-- ******************************************************************** -->
2638 <!-- Attribute combinations found in `standard' text and other examples:
2639 @refuri = standalone hyperlink
2640 @ids @refid = TOC, probably all in <generated>
2641 @name @refuri with matching <target> in document = named external hyperlink _
2642 @name @refuri immediately followed by matching <target> = named embedded URI _
2643 @name @refuri with no matching <target> in document = anonymous embedded URI __
2644 @anonymous @name @refuri with no matching <target> in document = anonymous explicit URI __
2645 @name @refid = internal cross-reference _
2646 @anonymous @name @refid = anonymous implicit internal reference __
2647 @name @refid image = clickable image to internal reference _
2648 @refuri image = clickable image to standalone hyperlink
2650 A target matches if target/@names contains the lower cased, whitespace
2651 quoted reference/@name
2654 <!-- Standalone hyperlink -->
2655 <!-- == inline_element -->
2656 <xsl:template
2657 match="reference[not(@name or @anonymous)]">
2658 <xsl:call-template
2659 name="u:bkslshEscPre"/>
2660 <xsl:choose>
2661 <xsl:when
2662 test="starts-with(., 'PEP ')">
2663 <xsl:text>:PEP:`</xsl:text>
2664 <xsl:value-of
2665 select="substring-after(., 'PEP ')"/>
2666 <xsl:text>`</xsl:text>
2667 </xsl:when>
2668 <xsl:when
2669 test="starts-with(., 'RFC ')">
2670 <xsl:text>:RFC:`</xsl:text>
2671 <xsl:value-of
2672 select="substring-after(., 'RFC ')"/>
2673 <xsl:text>`</xsl:text>
2674 </xsl:when>
2675 <xsl:otherwise>
2676 <xsl:apply-templates/>
2677 </xsl:otherwise>
2678 </xsl:choose>
2679 <xsl:call-template
2680 name="u:bkslshEscSuf"/>
2681 </xsl:template>
2683 <!-- External references -->
2684 <!-- == inline_element -->
2685 <xsl:template
2686 match="reference[@name and @refuri]">
2687 <!-- Determine normalized name by downcasing it -->
2688 <xsl:variable
2689 name="normalized"
2690 select="translate(normalize-space(@name), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
2691 <xsl:variable
2692 name="quoted">
2693 <xsl:call-template
2694 name="u:quoteWhite">
2695 <xsl:with-param
2696 name="string"
2697 select="$normalized"/>
2698 </xsl:call-template>
2699 </xsl:variable>
2700 <xsl:variable
2701 name="matching"
2702 select="//target[contains(@names, $quoted)]"/>
2703 <xsl:call-template
2704 name="u:inlineReference">
2705 <xsl:with-param
2706 name="anonymous"
2707 select="not($matching) or @anonymous"/>
2708 <xsl:with-param
2709 name="embedded"
2710 select="not(@anonymous) and (not($matching) or generate-id(following-sibling::node()[1]) = generate-id($matching))"/>
2711 </xsl:call-template>
2712 </xsl:template>
2714 <!-- Internal references -->
2715 <!-- == inline_element -->
2716 <xsl:template
2717 match="reference[@name and @refid]">
2718 <xsl:call-template
2719 name="u:inlineReference">
2720 <xsl:with-param
2721 name="anonymous"
2722 select="@anonymous"/>
2723 </xsl:call-template>
2724 </xsl:template>
2726 <!-- Image references -->
2727 <!-- == inline_element -->
2728 <xsl:template
2729 match="reference[image]">
2730 <!-- All done by the `image' tag -->
2731 <xsl:apply-templates/>
2732 </xsl:template>
2734 <!-- ******************************************************************** -->
2736 <!--
2737 Content Model: %text.model;
2739 <!-- == inline_element -->
2740 <xsl:template
2741 match="strong">
2742 <xsl:call-template
2743 name="u:bkslshEscPre"/>
2744 <xsl:text>**</xsl:text>
2745 <xsl:apply-templates/>
2746 <xsl:text>**</xsl:text>
2747 <xsl:call-template
2748 name="u:bkslshEscSuf"/>
2749 </xsl:template>
2751 <!-- ******************************************************************** -->
2753 <!-- == inline_element -->
2754 <xsl:template
2755 match="subscript">
2756 <xsl:call-template
2757 name="u:bkslshEscPre"/>
2758 <xsl:text>:sub:`</xsl:text>
2759 <xsl:apply-templates/>
2760 <xsl:text>`</xsl:text>
2761 <xsl:call-template
2762 name="u:bkslshEscSuf"/>
2763 </xsl:template>
2765 <!-- ******************************************************************** -->
2767 <!-- == inline_element -->
2768 <xsl:template
2769 match="superscript">
2770 <xsl:call-template
2771 name="u:bkslshEscPre"/>
2772 <xsl:text>:sup:`</xsl:text>
2773 <xsl:apply-templates/>
2774 <xsl:text>`</xsl:text>
2775 <xsl:call-template
2776 name="u:bkslshEscSuf"/>
2777 </xsl:template>
2779 <!-- ******************************************************************** -->
2781 <!-- The target element has various roles depending on context; they are
2782 all handled here -->
2783 <!-- == simple_body_element == inline_element == directive -->
2784 <xsl:template
2785 match="target">
2786 <xsl:choose>
2787 <xsl:when
2788 test="name(preceding-sibling::*[1]) = 'reference'">
2789 <!-- An embedded inline target - handled by the reference itself -->
2790 </xsl:when>
2791 <xsl:when
2792 test="contains($inline_containers, concat('*', name(..), '*'))">
2793 <!-- An inline target of some sort -->
2794 <xsl:call-template
2795 name="u:inlineReference">
2796 <xsl:with-param
2797 name="isTarget"
2798 select="true()"/>
2799 </xsl:call-template>
2800 </xsl:when>
2801 <xsl:when
2802 test="@anonymous">
2803 <!-- An anonymous target directive -->
2804 <xsl:call-template
2805 name="u:outputClass"/>
2806 <xsl:call-template
2807 name="u:BandI"/>
2808 <xsl:text>__ </xsl:text>
2809 <xsl:choose>
2810 <xsl:when
2811 test="@refid">
2812 <xsl:call-template
2813 name="u:outputNamesRefid"/>
2814 <xsl:text>_</xsl:text>
2815 </xsl:when>
2816 <xsl:when
2817 test="@refuri">
2818 <xsl:value-of
2819 select="@refuri"/>
2820 </xsl:when>
2821 </xsl:choose>
2822 &tEOL;
2823 </xsl:when>
2824 <xsl:when
2825 test="@names | @refid">
2826 <!-- A target directive -->
2827 <xsl:call-template
2828 name="u:outputClass"/>
2829 <xsl:call-template
2830 name="u:BandI"/>
2831 <xsl:text>.. _</xsl:text>
2832 <xsl:choose>
2833 <xsl:when
2834 test="@refid">
2835 <xsl:call-template
2836 name="u:outputNamesRefid"/>
2837 </xsl:when>
2838 <xsl:otherwise>
2839 <xsl:variable
2840 name="quoteNeeded"
2841 select="contains(@names, ':')"/>
2842 <xsl:if
2843 test="$quoteNeeded">
2844 <xsl:text>`</xsl:text>
2845 </xsl:if>
2846 <xsl:call-template
2847 name="u:outputNames"/>
2848 <xsl:if
2849 test="$quoteNeeded">
2850 <xsl:text>`</xsl:text>
2851 </xsl:if>
2852 </xsl:otherwise>
2853 </xsl:choose>
2854 <xsl:text>:</xsl:text>
2855 <xsl:if
2856 test="@refuri">
2857 <xsl:text> </xsl:text>
2858 <xsl:value-of
2859 select="@refuri"/>
2860 </xsl:if>
2861 &tEOL;
2862 </xsl:when>
2863 <xsl:otherwise>
2864 <!-- Should not happen -->
2865 <xsl:call-template
2866 name="u:notSupported"/>
2867 </xsl:otherwise>
2868 </xsl:choose>
2869 </xsl:template>
2871 <!-- ******************************************************************** -->
2873 <!--
2874 Content Model: %text.model;
2876 <!-- == inline_element -->
2877 <xsl:template
2878 match="title_reference">
2879 <xsl:call-template
2880 name="u:bkslshEscPre"/>
2881 <xsl:text>`</xsl:text>
2882 <xsl:apply-templates/>
2883 <xsl:text>`</xsl:text>
2884 <xsl:call-template
2885 name="u:bkslshEscSuf"/>
2886 </xsl:template>
2888 <!-- ******************************************************************** -->
2890 <!--
2891 Content Model: %text.model;
2893 <!-- == inline_element -->
2894 <xsl:template
2895 match="inline">
2896 <!-- TODO `role' directives must be generated for plain and derived
2897 user-defined roles. -->
2898 <xsl:call-template
2899 name="u:bkslshEscPre"/>
2900 <xsl:text>:</xsl:text>
2901 <xsl:value-of
2902 select="@classes"/>
2903 <xsl:text>:`</xsl:text>
2904 <xsl:apply-templates/>
2905 <xsl:text>`</xsl:text>
2906 <xsl:call-template
2907 name="u:bkslshEscSuf"/>
2908 </xsl:template>
2910 <!-- ******************************************************************** -->
2912 <!-- TODO `meta` directive must be implemented. -->
2914 <!-- ******************************************************************** -->
2916 <!--
2917 Docutils wraps generated elements around text that is inserted (generated) by
2918 Docutils; i.e., text that was not in the document, like section numbers
2919 inserted by the "sectnum" directive.
2921 <!-- == inline_element -->
2922 <xsl:template
2923 match="generated"/>
2925 <!-- == inline_element -->
2926 <xsl:template
2927 match="problematic">
2928 <!-- Simply output the contained text because this is probably the
2929 original text-->
2930 <xsl:value-of
2931 select="text()"/>
2932 </xsl:template>
2934 <!-- == compound_body_element -->
2935 <xsl:template
2936 match="system_message"/>
2938 <!-- ******************************************************************** -->
2939 <!-- ******************************************************************** -->
2941 <!--
2942 When a block of text contains linefeeds, it was indented relative to a marker
2943 on the first line
2945 <xsl:template
2946 match="text()">
2947 <xsl:call-template
2948 name="u:indentLF"/>
2949 </xsl:template>
2951 <!-- ******************************************************************** -->
2952 <!-- ******************************************************************** -->
2954 <!-- Add a blank line if necessary and indent -->
2955 <xsl:template
2956 name="u:BandI">
2957 <xsl:call-template
2958 name="u:blank"/>
2959 <xsl:call-template
2960 name="u:indent"/>
2961 </xsl:template>
2963 <!-- ******************************************************************** -->
2965 <!-- Add a blank line in certain contexts -->
2966 <xsl:template
2967 name="u:blank">
2968 <xsl:apply-templates
2969 mode="blankSkipInline"
2970 select="preceding::*[1]"/>
2971 </xsl:template>
2973 <!-- Find the preceding element we are really interested in and act
2974 according to this element -->
2975 <xsl:template
2976 mode="blankSkipInline"
2977 match="*">
2978 <xsl:choose>
2979 <!-- Skip all inline elements and body subelements and check their
2980 parents -->
2981 <xsl:when
2982 test="contains(concat($inline_elements, $simple_body_subelements, $compound_body_subelements), concat('*', name(.), '*'))">
2983 <xsl:apply-templates
2984 mode="blankSkipInline"
2985 select=".."/>
2986 </xsl:when>
2987 <xsl:otherwise>
2988 <!-- Reached the type of element we decide on -->
2989 <xsl:if
2990 test="contains($blank_after, concat('*', name(.), '*'))">
2991 &tCR;
2992 </xsl:if>
2993 </xsl:otherwise>
2994 </xsl:choose>
2995 </xsl:template>
2997 <!-- ******************************************************************** -->
2999 <!--
3000 Indent a block if it's a child of...
3002 <data:lookup>
3003 <node
3004 name="address"
3005 indent="10"/>
3006 <node
3007 name="author"
3008 indent="9"/>
3009 <node
3010 name="authors"
3011 indent="10"/>
3012 <node
3013 name="contact"
3014 indent="10"/>
3015 <node
3016 name="copyright"
3017 indent="12"/>
3018 <node
3019 name="date"
3020 indent="7"/>
3021 <node
3022 name="organization"
3023 indent="15"/>
3024 <node
3025 name="revision"
3026 indent="11"/>
3027 <node
3028 name="status"
3029 indent="9"/>
3030 <node
3031 name="version"
3032 indent="10"/>
3033 <!-- This is only for `bullet_list/list_item';
3034 `enumerated_list/list_item' is handled special -->
3035 <node
3036 name="list_item"
3037 indent="2"/>
3038 <node
3039 name="definition_list_item"
3040 indent="4"/>
3041 <node
3042 name="field_body"
3043 indent="4"/>
3044 <node
3045 name="option_list_item"
3046 indent="4"/>
3047 <!-- This is also the indentation if block_quote comes as one of the
3048 special directives -->
3049 <node
3050 name="block_quote"
3051 indent="4"/>
3052 <node
3053 name="literal_block"
3054 indent="4"/>
3055 <node
3056 name="attribution"
3057 indent="3"/>
3058 <node
3059 name="line"
3060 indent="2"/>
3061 </data:lookup>
3063 <!-- Do indent according to ancestor -->
3064 <xsl:template
3065 name="u:indent">
3066 <!-- In some cases the ancestors to indent for need to be determined
3067 by the calling template -->
3068 <xsl:param
3069 name="ancestors"
3070 select="ancestor::*"/>
3071 <xsl:for-each
3072 select="$ancestors">
3073 <xsl:variable
3074 name="this"
3075 select="name()"/>
3076 <xsl:choose>
3077 <xsl:when
3078 test="contains($directives, concat('*', $this, '*'))">
3079 <xsl:call-template
3080 name="u:repeat">
3081 <!-- TODO Indentation of lines after some directives must be
3082 indented to align with the directive instead of a
3083 fixed indentation; however, this is rather complicated
3084 since identation for parameters should be fixed -->
3085 <xsl:with-param
3086 name="length"
3087 select="3"/>
3088 </xsl:call-template>
3089 </xsl:when>
3090 <xsl:when
3091 test="$this = 'list_item' and parent::enumerated_list">
3092 <!-- Enumerated list items base their indentation on the
3093 numeration -->
3094 <xsl:variable
3095 name="enumerator">
3096 <xsl:call-template
3097 name="u:outputEnumerator"/>
3098 </xsl:variable>
3099 <xsl:call-template
3100 name="u:repeat">
3101 <xsl:with-param
3102 name="length"
3103 select="string-length($enumerator)"/>
3104 </xsl:call-template>
3105 </xsl:when>
3106 <xsl:otherwise>
3107 <xsl:call-template
3108 name="u:repeat">
3109 <xsl:with-param
3110 name="length"
3111 select="document('')//data:lookup/node[@name=$this]/@indent"/>
3112 </xsl:call-template>
3113 </xsl:otherwise>
3114 </xsl:choose>
3115 </xsl:for-each>
3116 </xsl:template>
3118 <!-- ******************************************************************** -->
3120 <!--
3121 Create a repeated character string
3122 Shamelessly borrowed from Jeni Tennison's work on EXSLT
3124 <xsl:template
3125 name="u:repeat">
3126 <xsl:param
3127 name="length"
3128 select="0"/>
3129 <xsl:param
3130 name="chars"
3131 select="' '"/>
3132 <xsl:choose>
3133 <xsl:when
3134 test="not($length) or $length &lt;= 0 or not($chars)"/>
3135 <xsl:otherwise>
3136 <xsl:variable
3137 name="string"
3138 select="concat($chars, $chars, $chars, $chars, $chars, $chars, $chars, $chars, $chars, $chars)"/>
3139 <xsl:choose>
3140 <xsl:when
3141 test="string-length($string) >= $length">
3142 <xsl:value-of
3143 select="substring($string, 1, $length)"/>
3144 </xsl:when>
3145 <xsl:otherwise>
3146 <xsl:call-template
3147 name="u:repeat">
3148 <xsl:with-param
3149 name="length"
3150 select="$length"/>
3151 <xsl:with-param
3152 name="chars"
3153 select="$string"/>
3154 </xsl:call-template>
3155 </xsl:otherwise>
3156 </xsl:choose>
3157 </xsl:otherwise>
3158 </xsl:choose>
3159 </xsl:template>
3161 <!-- ******************************************************************** -->
3163 <!-- Indent a text containing line feeds correctly -->
3164 <xsl:template
3165 name="u:indentLF">
3166 <xsl:param
3167 name="string"
3168 select="."/>
3169 <!-- A fixed indentation may be given by caller -->
3170 <xsl:param
3171 name="indent">
3172 <!-- If not given compute it -->
3173 <xsl:call-template
3174 name="u:indent"/>
3175 </xsl:param>
3176 <xsl:choose>
3177 <xsl:when
3178 test="contains($string,'&#x0A;')">
3179 <!-- Output first physical line -->
3180 <xsl:value-of
3181 select="substring-before($string, '&#x0A;')"/>
3182 &tEOL;
3183 <!-- Indent before the next line -->
3184 <xsl:value-of
3185 select="$indent"/>
3186 <!-- Output remaining physical lines -->
3187 <xsl:call-template
3188 name="u:indentLF">
3189 <xsl:with-param
3190 name="string"
3191 select="substring-after($string, '&#x0A;')"/>
3192 <xsl:with-param
3193 name="indent"
3194 select="$indent"/>
3195 </xsl:call-template>
3196 </xsl:when>
3197 <!-- String does not contain newline, so just output it -->
3198 <xsl:otherwise>
3199 <xsl:value-of
3200 select="$string"/>
3201 </xsl:otherwise>
3202 </xsl:choose>
3203 </xsl:template>
3205 <!-- ******************************************************************** -->
3207 <!-- Do output for those elements which do fold their inline content -->
3208 <xsl:template
3209 name="u:outputFolding">
3210 <!-- The prefix text to be output before the body -->
3211 <xsl:param
3212 name="prefix"
3213 select="''"/>
3214 <!-- The indentation for this body -->
3215 <xsl:param
3216 name="indent">
3217 <xsl:call-template
3218 name="u:indent">
3219 <xsl:with-param
3220 name="ancestors"
3221 select="ancestor-or-self::*"/>
3222 </xsl:call-template>
3223 </xsl:param>
3224 <xsl:variable
3225 name="string">
3226 <!-- TODO Whitespace count of inline literals must be preserved -->
3227 <xsl:apply-templates/>
3228 </xsl:variable>
3229 <!-- Always output prefix with all trailing and leading spaces -->
3230 <xsl:value-of
3231 select="$prefix"/>
3232 <xsl:choose>
3233 <xsl:when
3234 test="$fold &gt; 0">
3235 <xsl:variable
3236 name="normalized"
3237 select="normalize-space($string)"/>
3238 <xsl:choose>
3239 <xsl:when
3240 test="$string = ''">
3241 <!-- Empty strings need no output -->
3242 </xsl:when>
3243 <xsl:when
3244 test="$normalized = ''">
3245 <!-- Only white-space in string; output a single space here -->
3246 &tSP;
3247 </xsl:when>
3248 <xsl:otherwise>
3249 <!-- Output leading white-space here -->
3250 <xsl:if
3251 test="normalize-space(substring($string, 1, 1)) = ''">
3252 &tSP;
3253 </xsl:if>
3254 <xsl:call-template
3255 name="u:indentFold">
3256 <xsl:with-param
3257 name="string"
3258 select="$normalized"/>
3259 <xsl:with-param
3260 name="indent"
3261 select="$indent"/>
3262 <xsl:with-param
3263 name="cursorColumn"
3264 select="string-length($indent) + string-length($prefix)"/>
3265 </xsl:call-template>
3266 <!-- Output trailing white-space here -->
3267 <xsl:if
3268 test="normalize-space(substring($string, string-length($string), 1)) = ''">
3269 &tSP;
3270 </xsl:if>
3271 </xsl:otherwise>
3272 </xsl:choose>
3273 </xsl:when>
3274 <xsl:otherwise>
3275 <xsl:value-of
3276 select="$string"/>
3277 </xsl:otherwise>
3278 </xsl:choose>
3279 &tEOL;
3280 </xsl:template>
3282 <!-- ******************************************************************** -->
3284 <!-- Indent a string with folding -->
3285 <xsl:template
3286 name="u:indentFold">
3287 <!-- Normalized string to output -->
3288 <xsl:param
3289 name="string"/>
3290 <!-- Indentation to use for a new line -->
3291 <xsl:param
3292 name="indent"/>
3293 <!-- Current output column -->
3294 <!-- TODO This is not a correct assumption for field definitions where
3295 the field name effectively determines the column of the first
3296 line -->
3297 <xsl:param
3298 name="cursorColumn"
3299 select="string-length($indent)"/>
3300 <!-- Do we start on a new (indented) line? -->
3301 <xsl:param
3302 name="isNewLine"
3303 select="true()"/>
3304 <xsl:variable
3305 name="firstWord">
3306 <xsl:choose>
3307 <!-- TODO Quoted spaces must not end a word -->
3308 <xsl:when
3309 test="contains($string, ' ')">
3310 <xsl:value-of
3311 select="substring-before($string, ' ')"/>
3312 </xsl:when>
3313 <xsl:otherwise>
3314 <xsl:value-of
3315 select="$string"/>
3316 </xsl:otherwise>
3317 </xsl:choose>
3318 </xsl:variable>
3319 <xsl:variable
3320 name="rest"
3321 select="substring-after($string, ' ')"/>
3322 <xsl:choose>
3323 <xsl:when
3324 test="$string = ''"/>
3325 <xsl:when
3326 test="$isNewLine">
3327 <!-- Output at least first word -->
3328 <xsl:value-of
3329 select="$firstWord"/>
3330 <xsl:call-template
3331 name="u:indentFold">
3332 <xsl:with-param
3333 name="string"
3334 select="$rest"/>
3335 <xsl:with-param
3336 name="indent"
3337 select="$indent"/>
3338 <xsl:with-param
3339 name="cursorColumn"
3340 select="$cursorColumn + string-length($firstWord)"/>
3341 <xsl:with-param
3342 name="isNewLine"
3343 select="false()"/>
3344 </xsl:call-template>
3345 </xsl:when>
3346 <xsl:when
3347 test="$cursorColumn + 1 + string-length($firstWord) &gt; $fold">
3348 <!-- Line would get too long; start new line, indent and continue -->
3349 &tEOL;
3350 <xsl:value-of
3351 select="$indent"/>
3352 <xsl:call-template
3353 name="u:indentFold">
3354 <xsl:with-param
3355 name="string"
3356 select="$string"/>
3357 <xsl:with-param
3358 name="indent"
3359 select="$indent"/>
3360 <xsl:with-param
3361 name="cursorColumn"
3362 select="string-length($indent)"/>
3363 <xsl:with-param
3364 name="isNewLine"
3365 select="true()"/>
3366 </xsl:call-template>
3367 </xsl:when>
3368 <xsl:otherwise>
3369 <!-- In a line and first word fits; separate and add word -->
3370 &tSP;
3371 <xsl:value-of
3372 select="$firstWord"/>
3373 <xsl:call-template
3374 name="u:indentFold">
3375 <xsl:with-param
3376 name="string"
3377 select="$rest"/>
3378 <xsl:with-param
3379 name="indent"
3380 select="$indent"/>
3381 <xsl:with-param
3382 name="cursorColumn"
3383 select="$cursorColumn + 1 + string-length($firstWord)"/>
3384 <xsl:with-param
3385 name="isNewLine"
3386 select="false()"/>
3387 </xsl:call-template>
3388 </xsl:otherwise>
3389 </xsl:choose>
3390 </xsl:template>
3392 <!-- ******************************************************************** -->
3394 <!-- Output attributes of the current element as a field list -->
3395 <xsl:template
3396 name="u:params">
3397 <xsl:param
3398 name="params"
3399 select="@*"/>
3400 <!-- Ancestors are needed for determining indentation; caller may give
3401 them -->
3402 <xsl:param
3403 name="ancestors"
3404 select="ancestor-or-self::*"/>
3405 <xsl:for-each
3406 select="$params">
3407 <!-- Skip URIs based on parent -->
3408 <xsl:if
3409 test="name() != 'uri' and name() != 'xml:space'">
3410 <xsl:call-template
3411 name="u:param">
3412 <xsl:with-param
3413 name="ancestors"
3414 select="$ancestors"/>
3415 </xsl:call-template>
3416 </xsl:if>
3417 </xsl:for-each>
3418 </xsl:template>
3420 <!-- Output one attribute of the current element as a field list -->
3421 <xsl:template
3422 name="u:param">
3423 <xsl:param
3424 name="name"
3425 select="name()"/>
3426 <xsl:param
3427 name="value"
3428 select="."/>
3429 <!-- Ancestors are needed for determining indentation; caller may give
3430 them -->
3431 <xsl:param
3432 name="ancestors"
3433 select="ancestor::*"/>
3434 <xsl:call-template
3435 name="u:indent">
3436 <xsl:with-param
3437 name="ancestors"
3438 select="$ancestors"/>
3439 </xsl:call-template>
3440 <xsl:text>:</xsl:text>
3441 <xsl:choose>
3442 <xsl:when
3443 test="$name = 'classes'">
3444 <xsl:text>class</xsl:text>
3445 </xsl:when>
3446 <xsl:otherwise>
3447 <xsl:value-of
3448 select="$name"/>
3449 </xsl:otherwise>
3450 </xsl:choose>
3451 <xsl:text>:</xsl:text>
3452 <xsl:if
3453 test="$value">
3454 <xsl:text> </xsl:text>
3455 <xsl:value-of
3456 select="$value"/>
3457 </xsl:if>
3458 &tEOL;
3459 </xsl:template>
3461 <!-- ******************************************************************** -->
3463 <!-- Output `\' or `\ ' before some inline element if necessary -->
3464 <xsl:template
3465 name="u:bkslshEscPre">
3466 <!-- Get the sibling node directly before the current element -->
3467 <xsl:variable
3468 name="before"
3469 select="preceding-sibling::node()[1]"/>
3470 <xsl:choose>
3471 <!-- No sibling before this node -->
3472 <xsl:when
3473 test="not($before)"/>
3474 <!-- Element directly before this - must be another inline element -->
3475 <xsl:when
3476 test="name($before)">
3477 <!-- So separate it by a quoted space -->
3478 <xsl:text>\ </xsl:text>
3479 </xsl:when>
3480 <!-- Node directly before this is text - check it -->
3481 <xsl:when
3482 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;([{&lt;-/:'), substring($before, string-length($before), 1)))">
3483 <!-- Does not end in one of the allowed characters so separate it -->
3484 <xsl:text>\ </xsl:text>
3485 </xsl:when>
3486 </xsl:choose>
3487 </xsl:template>
3489 <!-- Output `\' or `\ ' after some inline element if necessary -->
3490 <xsl:template
3491 name="u:bkslshEscSuf">
3492 <!-- Get the sibling node directly after the current element -->
3493 <xsl:variable
3494 name="after"
3495 select="following-sibling::node()[1]"/>
3496 <xsl:choose>
3497 <!-- No sibling after this node -->
3498 <xsl:when
3499 test="not($after)"/>
3500 <!-- Element directly after this - must be another inline element
3501 handling itself -->
3502 <xsl:when
3503 test="name($after)"/>
3504 <!-- Node directly after this is text - check it -->
3505 <xsl:when
3506 test="not(contains(concat($apos, ' &#xA;&#x9;&#xD;&quot;)]}&gt;-/:.,;!?\'), substring($after, 1, 1)))">
3507 <!-- Does not start with one of the allowed characters so separate
3508 it -->
3509 <xsl:text>\</xsl:text>
3510 </xsl:when>
3511 </xsl:choose>
3512 </xsl:template>
3514 <!-- ******************************************************************** -->
3516 <xsl:template
3517 name="u:notSupported">
3518 <xsl:call-template
3519 name="u:BandI"/>
3520 <xsl:text>######## NOT SUPPORTED: `</xsl:text>
3521 <xsl:value-of
3522 select="name(.)"/>
3523 <xsl:text>' ########</xsl:text>
3524 &tEOL;
3525 </xsl:template>
3527 <!-- ******************************************************************** -->
3529 <xsl:template
3530 name="u:overline">
3531 <!-- Length of the rendered(!) text -->
3532 <xsl:param
3533 name="length"/>
3534 <!-- Depth 1 and 2 are document title and subtitle while depths
3535 greater than 2 are normal section titles -->
3536 <xsl:param
3537 name="depth"/>
3538 <!-- Test whether a overline is wanted at all -->
3539 <xsl:if
3540 test="substring($adornment, 2 * ($depth - 1) + 1, 1) = 'o'">
3541 <xsl:call-template
3542 name="u:repeat">
3543 <xsl:with-param
3544 name="length"
3545 select="$length"/>
3546 <xsl:with-param
3547 name="chars"
3548 select="substring($adornment, 2 * ($depth - 1) + 2, 1)"/>
3549 </xsl:call-template>
3550 &tEOL;
3551 </xsl:if>
3552 </xsl:template>
3554 <xsl:template
3555 name="u:underline">
3556 <!-- Length of the rendered(!) text -->
3557 <xsl:param
3558 name="length"/>
3559 <!-- Depth 1 and 2 are document title and subtitle while depths
3560 greater than 2 are normal section titles -->
3561 <xsl:param
3562 name="depth"/>
3563 <xsl:call-template
3564 name="u:repeat">
3565 <xsl:with-param
3566 name="length"
3567 select="$length"/>
3568 <xsl:with-param
3569 name="chars"
3570 select="substring($adornment, 2 * ($depth - 1) + 2, 1)"/>
3571 </xsl:call-template>
3572 &tEOL;
3573 </xsl:template>
3575 <!-- ******************************************************************** -->
3577 <!-- Output a non-standalone reference or target -->
3578 <xsl:template
3579 name="u:inlineReference">
3580 <xsl:param
3581 name="anonymous"
3582 select="false()"/>
3583 <xsl:param
3584 name="embedded"
3585 select="false()"/>
3586 <!-- Is this a target instead of a reference? -->
3587 <xsl:param
3588 name="isTarget"
3589 select="false()"/>
3590 <xsl:param
3591 name="text"
3592 select="node()"/>
3593 <xsl:call-template
3594 name="u:bkslshEscPre"/>
3595 <!-- Delimiter only if link contains other than alphanumerics -->
3596 <xsl:variable
3597 name="delimiter">
3598 <xsl:if
3599 test="* or translate($text, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '') or $embedded">
3600 <xsl:text>`</xsl:text>
3601 </xsl:if>
3602 </xsl:variable>
3603 <xsl:if
3604 test="$isTarget">
3605 <xsl:text>_</xsl:text>
3606 </xsl:if>
3607 <xsl:value-of
3608 select="$delimiter"/>
3609 <xsl:apply-templates
3610 select="$text"/>
3611 <xsl:if
3612 test="$embedded">
3613 <xsl:text> &lt;</xsl:text>
3614 <xsl:value-of
3615 select="@refuri"/>
3616 <xsl:text>&gt;</xsl:text>
3617 </xsl:if>
3618 <xsl:value-of
3619 select="$delimiter"/>
3620 <xsl:if
3621 test="not($isTarget)">
3622 <xsl:text>_</xsl:text>
3623 <xsl:if
3624 test="$anonymous">
3625 <xsl:text>_</xsl:text>
3626 </xsl:if>
3627 </xsl:if>
3628 <xsl:call-template
3629 name="u:bkslshEscSuf"/>
3630 </xsl:template>
3632 <!-- ******************************************************************** -->
3634 <!-- Determine the maximum number from a whitespace separated number list -->
3635 <xsl:template
3636 name="u:maxNumber">
3637 <xsl:param
3638 name="numbers"/>
3639 <!-- If this is not given by the caller a list of negative numbers will
3640 not work -->
3641 <xsl:param
3642 name="currentMax"
3643 select="0"/>
3644 <xsl:variable
3645 name="cleanNumbers"
3646 select="normalize-space($numbers)"/>
3647 <xsl:choose>
3648 <xsl:when
3649 test="contains($cleanNumbers, ' ')">
3650 <xsl:variable
3651 name="head"
3652 select="substring-before($cleanNumbers, ' ')"/>
3653 <xsl:choose>
3654 <xsl:when
3655 test="$head > $currentMax">
3656 <xsl:call-template
3657 name="u:maxNumber">
3658 <xsl:with-param
3659 name="numbers"
3660 select="substring-after($cleanNumbers, ' ')"/>
3661 <xsl:with-param
3662 name="currentMax"
3663 select="$head"/>
3664 </xsl:call-template>
3665 </xsl:when>
3666 <xsl:otherwise>
3667 <xsl:call-template
3668 name="u:maxNumber">
3669 <xsl:with-param
3670 name="numbers"
3671 select="substring-after($cleanNumbers, ' ')"/>
3672 <xsl:with-param
3673 name="currentMax"
3674 select="$currentMax"/>
3675 </xsl:call-template>
3676 </xsl:otherwise>
3677 </xsl:choose>
3678 </xsl:when>
3679 <xsl:otherwise>
3680 <xsl:choose>
3681 <xsl:when
3682 test="$cleanNumbers > $currentMax">
3683 <xsl:value-of
3684 select="$cleanNumbers"/>
3685 </xsl:when>
3686 <xsl:otherwise>
3687 <xsl:value-of
3688 select="$currentMax"/>
3689 </xsl:otherwise>
3690 </xsl:choose>
3691 </xsl:otherwise>
3692 </xsl:choose>
3693 </xsl:template>
3695 <!-- ******************************************************************** -->
3697 <!-- Output a class directive for the directly following element. -->
3698 <!-- TODO A class directive can also be used as a container putting the
3699 respective attribute to its content; however, this is not
3700 reflected in XML - you'd need to check a sequence of elements
3701 whether they all have the same attribute; furthermore class
3702 settings for block quotes needs to be treated special -->
3703 <xsl:template
3704 name="u:outputClass">
3705 <!-- Blank line already output? -->
3706 <xsl:param
3707 name="alreadyBlanked"
3708 select="false()"/>
3709 <!-- Indentation already output? -->
3710 <xsl:param
3711 name="alreadyIndented"
3712 select="false()"/>
3713 <!-- Add a blank line after class directive? -->
3714 <xsl:param
3715 name="blankAfter"
3716 select="false()"/>
3717 <xsl:if
3718 test="@classes">
3719 <xsl:if
3720 test="not($alreadyBlanked)">
3721 <xsl:call-template
3722 name="u:blank"/>
3723 </xsl:if>
3724 <xsl:if
3725 test="not($alreadyIndented)">
3726 <xsl:call-template
3727 name="u:indent"/>
3728 </xsl:if>
3729 <xsl:text>.. class:: </xsl:text>
3730 <xsl:value-of
3731 select="@classes"/>
3732 &tEOL;
3733 <xsl:if
3734 test="$blankAfter">
3735 &tCR;
3736 </xsl:if>
3737 </xsl:if>
3738 </xsl:template>
3740 <!-- ******************************************************************** -->
3742 <!-- Output a string with backslashed stripped -->
3743 <xsl:template
3744 name="u:outputUnbackslashed">
3745 <xsl:param
3746 name="string"/>
3747 <xsl:choose>
3748 <xsl:when
3749 test="not(contains($string, '\'))">
3750 <xsl:value-of
3751 select="$string"/>
3752 </xsl:when>
3753 <xsl:otherwise>
3754 <xsl:value-of
3755 select="substring-before($string, '\')"/>
3756 <xsl:call-template
3757 name="u:outputUnbackslashed">
3758 <xsl:with-param
3759 name="string"
3760 select="substring-after($string, '\')"/>
3761 </xsl:call-template>
3762 </xsl:otherwise>
3763 </xsl:choose>
3764 </xsl:template>
3766 <!-- Returns a name at an index -->
3767 <xsl:template
3768 name="u:name4Index">
3769 <xsl:param
3770 name="names"/>
3771 <xsl:param
3772 name="index"/>
3773 <xsl:param
3774 name="name0"
3775 select="''"/>
3776 <xsl:choose>
3777 <xsl:when
3778 test="not(contains($names, ' '))">
3779 <xsl:choose>
3780 <xsl:when
3781 test="not($index)">
3782 <xsl:value-of
3783 select="concat($name0, $names)"/>
3784 </xsl:when>
3785 <xsl:otherwise>
3786 <!-- No string with this index -->
3787 <xsl:value-of
3788 select="''"/>
3789 </xsl:otherwise>
3790 </xsl:choose>
3791 </xsl:when>
3792 <xsl:otherwise>
3793 <xsl:variable
3794 name="before"
3795 select="substring-before($names, ' ')"/>
3796 <xsl:choose>
3797 <xsl:when
3798 test="substring($before, string-length($before)) = '\'">
3799 <!-- Quoted space found -->
3800 <xsl:call-template
3801 name="u:name4Index">
3802 <xsl:with-param
3803 name="names"
3804 select="substring-after($names, ' ')"/>
3805 <xsl:with-param
3806 name="index"
3807 select="$index"/>
3808 <xsl:with-param
3809 name="name0"
3810 select="concat($name0, $before, ' ')"/>
3811 </xsl:call-template>
3812 </xsl:when>
3813 <xsl:otherwise>
3814 <!-- Separating space found -->
3815 <xsl:choose>
3816 <xsl:when
3817 test="not($index)">
3818 <xsl:value-of
3819 select="concat($name0, $before)"/>
3820 </xsl:when>
3821 <xsl:otherwise>
3822 <xsl:call-template
3823 name="u:name4Index">
3824 <xsl:with-param
3825 name="names"
3826 select="substring-after($names, ' ')"/>
3827 <xsl:with-param
3828 name="index"
3829 select="$index - 1"/>
3830 </xsl:call-template>
3831 </xsl:otherwise>
3832 </xsl:choose>
3833 </xsl:otherwise>
3834 </xsl:choose>
3835 </xsl:otherwise>
3836 </xsl:choose>
3837 </xsl:template>
3839 <!-- Output a names attribute at index considering quoted spaces. -->
3840 <xsl:template
3841 name="u:outputNames">
3842 <!-- Blank line already output? -->
3843 <xsl:param
3844 name="names"
3845 select="@names"/>
3846 <xsl:param
3847 name="index"
3848 select="0"/>
3849 <xsl:variable
3850 name="name">
3851 <xsl:call-template
3852 name="u:name4Index">
3853 <xsl:with-param
3854 name="names"
3855 select="$names"/>
3856 <xsl:with-param
3857 name="index"
3858 select="$index"/>
3859 </xsl:call-template>
3860 </xsl:variable>
3861 <xsl:call-template
3862 name="u:outputUnbackslashed">
3863 <xsl:with-param
3864 name="string"
3865 select="$name"/>
3866 </xsl:call-template>
3867 </xsl:template>
3869 <!-- ******************************************************************** -->
3871 <!-- Finds an id in a list and returns its index or empty string if not
3872 contained exactly. -->
3873 <xsl:template
3874 name="u:findId">
3875 <xsl:param
3876 name="list"/>
3877 <xsl:param
3878 name="id"/>
3879 <xsl:param
3880 name="index"
3881 select="0"/>
3882 <xsl:choose>
3883 <xsl:when
3884 test="$list = ''">
3885 <xsl:value-of
3886 select="''"/>
3887 </xsl:when>
3888 <xsl:when
3889 test="$list = $id or starts-with($list, concat($id, ' '))">
3890 <xsl:value-of
3891 select="$index"/>
3892 </xsl:when>
3893 <xsl:otherwise>
3894 <xsl:call-template
3895 name="u:findId">
3896 <xsl:with-param
3897 name="list"
3898 select="substring-after($list, ' ')"/>
3899 <xsl:with-param
3900 name="id"
3901 select="$id"/>
3902 <xsl:with-param
3903 name="index"
3904 select="$index + 1"/>
3905 </xsl:call-template>
3906 </xsl:otherwise>
3907 </xsl:choose>
3908 </xsl:template>
3910 <!-- In a number of elements find the one containing exactly id and return
3911 the index of the element as well as the index of the id -->
3912 <xsl:template
3913 name="u:findRefElem">
3914 <xsl:param
3915 name="possibleElems"/>
3916 <xsl:param
3917 name="id"/>
3918 <!-- XSLT is 1-based -->
3919 <xsl:param
3920 name="elemIndex"
3921 select="1"/>
3922 <xsl:variable
3923 name="elem"
3924 select="$possibleElems[1]"/>
3925 <xsl:choose>
3926 <!-- No more elements - return empty string -->
3927 <xsl:when
3928 test="not($possibleElems)">
3929 <xsl:value-of
3930 select="''"/>
3931 </xsl:when>
3932 <xsl:otherwise>
3933 <!-- Check whether the first element contains the id -->
3934 <xsl:variable
3935 name="fnd">
3936 <xsl:call-template
3937 name="u:findId">
3938 <xsl:with-param
3939 name="list"
3940 select="$elem/@ids"/>
3941 <xsl:with-param
3942 name="id"
3943 select="$id"/>
3944 </xsl:call-template>
3945 </xsl:variable>
3946 <xsl:choose>
3947 <xsl:when
3948 test="$fnd != ''">
3949 <xsl:value-of
3950 select="concat($elemIndex, ' ', $fnd)"/>
3951 </xsl:when>
3952 <xsl:otherwise>
3953 <xsl:call-template
3954 name="u:findRefElem">
3955 <xsl:with-param
3956 name="possibleElems"
3957 select="$possibleElems[position() != 1]"/>
3958 <xsl:with-param
3959 name="id"
3960 select="$id"/>
3961 <xsl:with-param
3962 name="elemIndex"
3963 select="$elemIndex + 1"/>
3964 </xsl:call-template>
3965 </xsl:otherwise>
3966 </xsl:choose>
3967 </xsl:otherwise>
3968 </xsl:choose>
3969 </xsl:template>
3971 <!-- Output a names attribute for a refid. -->
3972 <xsl:template
3973 name="u:outputNamesRefid">
3974 <xsl:param
3975 name="refid"
3976 select="@refid"/>
3977 <!-- Determine all possible elements which might be referred -->
3978 <xsl:variable
3979 name="possibleElems"
3980 select="//*[contains(@ids, $refid)]"/>
3981 <xsl:variable
3982 name="refElem_index">
3983 <xsl:call-template
3984 name="u:findRefElem">
3985 <xsl:with-param
3986 name="possibleElems"
3987 select="$possibleElems"/>
3988 <xsl:with-param
3989 name="id"
3990 select="$refid"/>
3991 </xsl:call-template>
3992 </xsl:variable>
3993 <xsl:call-template
3994 name="u:outputNames">
3995 <xsl:with-param
3996 name="names"
3997 select="$possibleElems[position() = substring-before($refElem_index, ' ')]/@names"/>
3998 <xsl:with-param
3999 name="index"
4000 select="number(substring-after($refElem_index, ' '))"/>
4001 </xsl:call-template>
4002 </xsl:template>
4004 <!-- ******************************************************************** -->
4006 <!-- Output a string with each space character quoted -->
4007 <xsl:template
4008 name="u:quoteWhite">
4009 <xsl:param
4010 name="string"/>
4011 <xsl:variable
4012 name="head"
4013 select="substring-before($string, ' ')"/>
4014 <xsl:choose>
4015 <xsl:when
4016 test="$head = ''">
4017 <xsl:value-of
4018 select="$string"/>
4019 </xsl:when>
4020 <xsl:otherwise>
4021 <xsl:value-of
4022 select="concat($head, '\ ')"/>
4023 <xsl:call-template
4024 name="u:quoteWhite">
4025 <xsl:with-param
4026 name="string"
4027 select="substring-after($string, ' ')"/>
4028 </xsl:call-template>
4029 </xsl:otherwise>
4030 </xsl:choose>
4031 </xsl:template>
4033 <!-- ******************************************************************** -->
4034 <!-- ******************************************************************** -->
4036 <!-- Report unknown tags -->
4037 <xsl:template
4038 match="*">
4039 <xsl:message>
4040 <xsl:text>`</xsl:text>
4041 <xsl:value-of
4042 select="name(.)"/>
4043 <xsl:text>' encountered</xsl:text>
4044 <xsl:if
4045 test="parent::*">
4046 <xsl:text> in `</xsl:text>
4047 <xsl:value-of
4048 select="name(parent::*)"/>
4049 <xsl:text>'</xsl:text>
4050 </xsl:if>
4051 <xsl:text>, but no template matches.</xsl:text>
4052 </xsl:message>
4053 </xsl:template>
4055 </xsl:stylesheet>
4057 <!-- ********************************************************************** -->
4058 <!-- ********************************************************************** -->
4059 <!-- ********************************************************************** -->
4060 <!-- POD manual page
4062 =head1 NAME
4064 xml2rst-noexslt.xsl - An XSLT script to convert Docutils XML to reStructuredText
4066 =head1 SYNOPSIS
4068 Xalan docutils.xml xml2rst.xsl
4070 =head1 NOTE
4072 Today B<xml2rst-noexslt.xsl> is not the recommended way to use
4073 B<xml2rst>. The preferred way is to install B<lxml> and use
4074 B<xml2rst.py> instead.
4076 =head1 DESCRIPTION
4078 B<xml2rst-noexslt.xsl> is an XSLT script to convert Docutils XML to
4079 reStructuredText. You can use your favorite XSLT processor (e.g. Xalan
4080 from the Apache project) to generate reStructuredText from the
4081 Docutils intermediate XML representation. Its main use is to generate
4082 reStructuredText from some other format where a converter to Docutils
4083 XML already exists.
4085 =head2 Options
4087 The following options are supported. They are XSLT parameters for the
4088 whole script and must be given to the XSLT processor by the respective
4089 option (Xalan: B<-p>).
4091 =over 4
4093 =item adornment
4095 Configures title markup to use so different styles can be requested
4096 easily.
4098 The value of the parameter must be a string made up of a sequence of
4099 character pairs. The first character of a pair is C<o> (overline) or
4100 C<u> (underline) and the second character is the character to use for
4101 the markup.
4103 The first and the second character pair is used for document title and
4104 subtitle, the following pairs are used for section titles where the
4105 third pair is used for the top level section title.
4107 Defaults to C<o=o-u=u-u~u:u.u`>.
4109 =item fold
4111 Configures whether long text lines in paragraphs should be folded and
4112 to which length. This option is for input not coming from reST which
4113 may have no internal line feeds in plain text strings.
4115 If folding is enabled text strings not in a line feed preserving
4116 context are first white-space normalized and then broken according to
4117 the folding rules. Folding rules put out the first word and continue
4118 to do so with the following words unless the next word would cross
4119 the folding boundary. Words are delimited by white-space.
4121 Defaults to C<0>, i.e. no folding.
4123 =back
4125 =head2 Unsupported features
4127 It is generally not possible to create an exact reproduction of an
4128 original reStructuredText source from an intermediate XML file. The
4129 reason is that Docutils transports pretty much but not all information
4130 of the original source into the XML. Also the sequence is changed
4131 sometimes.
4133 However, the coverage of Docutils features of B<xml2rst-noexslt.xsl> is
4134 pretty good. A few minor features are not supported:
4136 =over 4
4138 =item * Fully minimized style for literal blocks
4140 =item * Substitution references for C<replace::> substitutions
4142 =item * Counting roman numbers in enumerated lists
4144 =item * Special table types like C<list-table::> and C<csv-table::>
4146 =item * Custom role definitions
4148 =back
4150 =head1 INSTALLATION
4152 Installation is not necessary. Just use the file as downloaded with
4153 your favorite XSLT processor.
4155 =head1 AUTHOR
4157 Stefan Merten <smerten@oekonux.de> based on works by David Priest.
4159 =head1 LICENSE
4161 This program is licensed under the terms of the GPL. See
4163 http://www.gnu.org/licenses/gpl.txt
4165 =head1 AVAILABILTY
4169 http://www.merten-home.de/FreeSoftware/xml2rst/
4171 =cut