1 <!DOCTYPE xsl:stylesheet [
2 <!-- External DTD defines entities:
3 components :- QNames of component-level elements
4 blocks :- QNames of block-level elements
5 metadata-content :- XPath expression matching metadata styles
6 author-content :- XPath expression matching author styles
7 admonition :- XPath expression matching admonition styles
8 admonition-title :- XPath expression matching admonition title styles
10 <!ENTITY % ext SYSTEM "blocks2dbk.dtd">
13 <xsl:stylesheet exclude-result-prefixes="d"
15 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16 xmlns:d="http://docbook.org/ns/docbook"
17 xmlns:dbk='http://docbook.org/ns/docbook'
18 xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
19 xmlns:xlink='http://www.w3.org/1999/xlink'>
21 <!-- Stylesheet to convert word processing docs to DocBook -->
22 <!-- This stylesheet processes the output of sections2blocks.xsl -->
24 <xsl:output indent="yes" method="xml"
25 cdata-section-elements='dbk:programlisting dbk:literallayout'/>
27 <!-- ================================================== -->
29 <!-- ================================================== -->
31 <xsl:param name='docbook5'>0</xsl:param>
32 <xsl:param name="nest.sections">1</xsl:param>
34 <xsl:strip-space elements='*'/>
35 <xsl:preserve-space elements='dbk:para dbk:emphasis'/>
37 <xsl:template match="&components; |
40 <xsl:when test='self::dbk:article and
41 count(dbk:book) = 1 and
42 count(dbk:info|dbk:book) <= 2'>
43 <xsl:apply-templates select='dbk:book'/>
45 <xsl:when test='self::dbk:article and
46 *[1][self::dbk:para] and
47 *[1]/@rnd:style != "article-title" and
48 contains(*[1]/@rnd:style, "-title")'>
49 <xsl:variable name='element-name'
50 select='substring-before(*[1]/@rnd:style, "-title")'/>
51 <xsl:element name='{$element-name}'
52 namespace='http://docbook.org/ns/docbook'>
54 <xsl:apply-templates select='*[1]'
57 <xsl:apply-templates/>
62 <xsl:call-template name='rnd:attributes'/>
64 <xsl:variable name='metadata'>
65 <xsl:apply-templates select='*[1]'
68 <xsl:if test='$metadata'>
70 <xsl:copy-of select='$metadata'/>
74 <xsl:apply-templates/>
80 <xsl:template match='dbk:book-component'>
81 <xsl:variable name='element-name'
82 select='substring-before(*[1]/@rnd:style, "-title")'/>
84 <xsl:element name='{$element-name}'
85 namespace='http://docbook.org/ns/docbook'>
87 <xsl:apply-templates select='*[1]'
90 <xsl:apply-templates/>
94 <xsl:template match="dbk:para" name='rnd:para'>
95 <!-- Some elements are normally suppressed,
96 since they are processed in a different context.
97 If this parameter is false then the element will be processed normally.
99 <xsl:param name='suppress' select='true()'/>
101 <!-- This paragraph may be in a sidebar -->
102 <xsl:variable name='sidebar'
103 select='preceding-sibling::*[self::dbk:para and @rnd:style = "sidebar-title"][1]'/>
105 <!-- This paragraph may be in the textobject of a table or figure -->
106 <xsl:variable name='table'
107 select='preceding-sibling::dbk:informaltable[1]'/>
108 <xsl:variable name='figure'
109 select='preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]'/>
110 <xsl:variable name='caption'
111 select='following-sibling::dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"]'/>
114 <!-- continue style paragraphs are handled in context -->
115 <xsl:when test='$suppress and
116 @rnd:style = "para-continue"'/>
118 <!-- Certain elements gather the following paragraph -->
119 <xsl:when test='$suppress and
120 preceding-sibling::*[1][self::dbk:para and
121 @rnd:style = "example-title"]'/>
123 <xsl:when test='$suppress and
125 not(preceding-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
126 preceding-sibling::*[preceding-sibling::*[generate-id() = generate-id($sidebar)]]])'/>
128 <!-- Separate processing is performed for table/figure titles and captions -->
129 <xsl:when test='$suppress and
130 @rnd:style = "table-title" and
131 following-sibling::*[1][self::dbk:informaltable|self::dbk:para[@rnd:style = "informalfigure-imagedata"]|self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]]'/>
132 <xsl:when test='$suppress and
133 @rnd:style = "figure-title" and
134 following-sibling::*[1][self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")]'/>
135 <xsl:when test='$suppress and
136 (@rnd:style = "d:caption" or @rnd:style = "Caption") and
137 (preceding-sibling::*[self::dbk:informaltable] or
138 preceding-sibling::*[self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")])'/>
140 <xsl:when test='$suppress and
143 generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id($table)'/>
144 <xsl:when test='$suppress and
147 generate-id($caption/preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]) = generate-id($figure)'/>
149 <xsl:when test='@rnd:style = "imagedata-metadata" or
150 @rnd:style = "table-metadata"'/>
152 <!-- Ignore empty paragraphs -->
153 <xsl:when test='(not(@rnd:style) or
155 normalize-space(.) = "" and
158 <!-- Image inline or block? -->
159 <xsl:when test='(not(@rnd:style) or
161 normalize-space(.) = "" and
163 dbk:inlinemediaobject'>
164 <xsl:apply-templates/>
166 <xsl:when test='not(@rnd:style) or
168 @rnd:style = "para-continue"'>
170 <xsl:call-template name='rnd:attributes'/>
171 <xsl:apply-templates/>
175 <xsl:when test='@rnd:style = "d:xinclude"'
176 xmlns:xi='http://www.w3.org/2001/XInclude'>
178 <xsl:attribute name='href'>
179 <xsl:apply-templates mode='rnd:xinclude'/>
184 <xsl:when test='$suppress and
185 preceding-sibling::*[1]/self::dbk:para[&admonition-title;]'/>
186 <xsl:when test='&admonition-title;'>
187 <xsl:element name='{substring-before(@rnd:style, "-title")}'
188 namespace='http://docbook.org/ns/docbook'>
189 <xsl:call-template name='rnd:attributes'/>
191 <xsl:apply-templates/>
193 <xsl:apply-templates select='following-sibling::*[1]'>
194 <xsl:with-param name='suppress' select='false()'/>
195 </xsl:apply-templates>
196 <xsl:apply-templates select='following-sibling::*[2]'
197 mode='rnd:continue'/>
201 <xsl:when test='starts-with(@rnd:style, "d:itemizedlist") or
202 starts-with(@rnd:style, "d:orderedlist")'>
204 <xsl:variable name='stop.node'
205 select='following-sibling::dbk:para[not(@rnd:style) or
206 (not(starts-with(@rnd:style, "d:itemizedlist") or starts-with(@rnd:style, "d:orderedlist")) and @rnd:style != "para-continue")][1]'/>
209 <xsl:when test='translate(substring-after(@rnd:style, "d:list"), "0123456789", "") != "" or
210 substring-after(@rnd:style, "d:list") = ""'>
211 <xsl:call-template name='rnd:error'>
212 <xsl:with-param name='code' select='"list-bad-level"'/>
213 <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" is not a valid list style</xsl:with-param>
217 <!-- TODO: the previous para-continue may not be associated with a list -->
219 <!-- NB. Look back at the previous paragraph. There may be intervening tables or images. -->
220 <xsl:when test='preceding-sibling::dbk:para[1][starts-with(@rnd:style, "d:itemizedlist") or starts-with(@rnd:style, "d:orderedlist") or @rnd:style = "para-continue"]'/>
221 <xsl:when test='substring-after(@rnd:style, "d:list") != 1'>
222 <xsl:call-template name='rnd:error'>
223 <xsl:with-param name='code'>list-wrong-level</xsl:with-param>
224 <xsl:with-param name='message'>list started at the wrong level</xsl:with-param>
227 <xsl:when test='$stop.node'>
228 <xsl:element name='{substring-before(@rnd:style, "1")}'
229 namespace='http://docbook.org/ns/docbook'>
230 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style][following-sibling::*[generate-id() = generate-id($stop.node)]]'
231 mode='rnd:listitem'/>
235 <xsl:element name='{substring-before(@rnd:style, "1")}'
236 namespace='http://docbook.org/ns/docbook'>
237 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style]'
238 mode='rnd:listitem'/>
244 <xsl:when test='@rnd:style = "d:programlisting" and
245 preceding-sibling::*[1][self::dbk:para and @rnd:style = "d:programlisting"]'/>
246 <xsl:when test='@rnd:style = "d:literallayout" and
247 preceding-sibling::*[1][self::dbk:para and @rnd:style = "d:literallayout"]'/>
248 <xsl:when test='@rnd:style = "d:programlisting" or
249 @rnd:style = "d:literallayout"'>
251 <xsl:variable name='stop.node'
252 select='following-sibling::dbk:para[@rnd:style != current()/@rnd:style][1]'/>
254 <xsl:element name='{@rnd:style}'
255 namespace='http://docbook.org/ns/docbook'>
256 <xsl:apply-templates/>
259 <xsl:when test='$stop.node'>
260 <xsl:apply-templates select='following-sibling::dbk:para[following-sibling::*[generate-id() = generate-id($stop.node)]]'
261 mode='rnd:programlisting'/>
264 <xsl:apply-templates select='following-sibling::dbk:para'
265 mode='rnd:programlisting'/>
271 <xsl:when test='@rnd:style = "example-title"'>
272 <xsl:element name='{substring-before(@rnd:style, "-title")}'
273 namespace='http://docbook.org/ns/docbook'>
274 <xsl:call-template name='rnd:attributes'/>
276 <xsl:apply-templates/>
279 <xsl:apply-templates select='following-sibling::*[1]'>
280 <xsl:with-param name='suppress' select='false()'/>
281 </xsl:apply-templates>
285 <xsl:when test='@rnd:style = "sidebar-title"'>
286 <!-- TODO: next sidebar should stop this sidebar -->
287 <xsl:variable name='stop.node'
288 select='following-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
289 normalize-space(.) = ""][1]'/>
292 <xsl:call-template name='rnd:attributes'/>
295 <xsl:apply-templates/>
300 <xsl:when test='$stop.node'>
301 <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
305 <xsl:apply-templates select='following-sibling::*'
312 <xsl:when test='&admonition;'>
313 <xsl:element name='{@rnd:style}'
314 namespace='http://docbook.org/ns/docbook'>
315 <xsl:call-template name='rnd:attributes'/>
317 <xsl:apply-templates/>
319 <xsl:apply-templates select='following-sibling::*[1]'
320 mode='rnd:continue'/>
324 <!-- TODO: make sure this is in a bibliography.
325 If not, create a bibliolist.
327 <xsl:when test='@rnd:style = "d:bibliomixed"'>
329 <xsl:call-template name='rnd:attributes'/>
330 <xsl:apply-templates/>
333 <xsl:when test='@rnd:style = "biblioentry-title"'>
335 <xsl:call-template name='rnd:attributes'/>
337 <xsl:apply-templates/>
339 <xsl:if test='following-sibling::*[1][&metadata-content;]'>
340 <xsl:apply-templates select='following-sibling::*[1]'
341 mode='rnd:metadata'/>
346 <xsl:when test='@rnd:style = "blockquote-attribution" and
347 preceding-sibling::*[1][self::dbk:para][@rnd:style = "blockquote-title" or @rnd:style = "d:blockquote"]'/>
348 <xsl:when test='@rnd:style = "blockquote-attribution"'>
349 <xsl:call-template name='rnd:error'>
350 <xsl:with-param name='code'>improper-blockquote-attribution</xsl:with-param>
351 <xsl:with-param name='message'>blockquote attribution must follow a blockquote title</xsl:with-param>
354 <xsl:when test='@rnd:style = "d:blockquote" or
355 @rnd:style = "blockquote-title"'>
357 <xsl:when test='@rnd:style = "d:blockquote" and
358 preceding-sibling::*[1][self::dbk:para][starts-with(@rnd:style, "d:blockquote")]'/>
361 <xsl:variable name='stop.node'
362 select='following-sibling::*[not(@rnd:style = "d:blockquote" or
363 @rnd:style = "blockquote-attribution")][1]'/>
366 <xsl:call-template name='rnd:attributes'/>
367 <xsl:if test='@rnd:style = "blockquote-title"'>
370 <xsl:apply-templates/>
375 <xsl:when test='$stop.node'>
376 <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]][@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
377 <xsl:apply-templates select='self::*[@rnd:style = "d:blockquote"] |
378 following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
379 mode='rnd:blockquote'/>
382 <xsl:apply-templates select='following-sibling::*[@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
383 <xsl:apply-templates select='self::*[@rnd:style = "d:blockquote"] |
384 following-sibling::*'
385 mode='rnd:blockquote'/>
393 <xsl:when test='@rnd:style = "d:bridgehead"'>
394 <xsl:element name='{@rnd:style}'
395 namespace='http://docbook.org/ns/docbook'>
396 <xsl:call-template name='rnd:attributes'/>
397 <xsl:apply-templates/>
401 <xsl:when test='@rnd:style = "formalpara-title"'>
404 <xsl:call-template name='rnd:attributes'/>
405 <xsl:apply-templates/>
408 <xsl:when test='following-sibling::*[1][self::dbk:para][@rnd:style = "d:formalpara"]'>
410 <xsl:call-template name='rnd:attributes'>
411 <xsl:with-param name='node'
412 select='following-sibling::*[1]'/>
414 <xsl:apply-templates select='following-sibling::*[1]/node()'/>
420 <xsl:when test='@rnd:style = "d:formalpara" and
421 preceding-sibling::*[1][self::dbk:para][@rnd:style = "formalpara-title"]'/>
422 <xsl:when test='@rnd:style = "d:formalpara"'>
423 <xsl:call-template name='rnd:error'>
424 <xsl:with-param name='code'>formalpara-notitle</xsl:with-param>
425 <xsl:with-param name='message'>formalpara used without a title</xsl:with-param>
429 <xsl:when test='@rnd:style = "informalfigure-imagedata"'>
430 <xsl:variable name='caption.next'
431 select='following-sibling::dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"][1]'/>
433 <xsl:variable name='metadata'
434 select='preceding-sibling::*[1][self::dbk:para][@rnd:style = "imagedata-metadata"]'/>
437 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
438 ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "figure-title"])'>
440 <xsl:call-template name='rnd:attributes'/>
444 <xsl:when test='$metadata'>
446 select='preceding-sibling::*[2]/node()'/>
450 select='preceding-sibling::*[1]/node()'/>
458 <xsl:attribute name='fileref'>
460 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
461 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
464 <xsl:value-of select='.'/>
468 <xsl:call-template name='rnd:imagedata-attributes'>
469 <xsl:with-param name='metadata' select='$metadata'/>
474 <xsl:call-template name='rnd:figure-text-caption'>
475 <xsl:with-param name='caption' select='$caption.next'/>
479 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "table-title"] or
480 ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "table-title"])'>
482 <xsl:call-template name='rnd:attributes'/>
486 <xsl:when test='$metadata'>
488 select='preceding-sibling::*[2]/node()'/>
492 select='preceding-sibling::*[1]/node()'/>
501 <xsl:attribute name='fileref'>
503 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
504 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
507 <xsl:value-of select='.'/>
511 <xsl:call-template name='rnd:imagedata-attributes'>
512 <xsl:with-param name='metadata' select='$metadata'/>
517 <xsl:call-template name='rnd:figure-text-caption'>
518 <xsl:with-param name='caption' select='$caption.next'/>
524 <xsl:call-template name='rnd:attributes'/>
528 <xsl:attribute name='fileref'>
530 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
531 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
534 <xsl:value-of select='.'/>
538 <xsl:call-template name='rnd:imagedata-attributes'>
539 <xsl:with-param name='metadata' select='$metadata'/>
544 <xsl:call-template name='rnd:figure-text-caption'>
545 <xsl:with-param name='caption' select='$caption.next'/>
547 </dbk:informalfigure>
552 <xsl:when test='(@rnd:style = "d:caption" or @rnd:style = "Caption") and
553 preceding-sibling::*[(self::dbk:para and contains(@rnd:style, "d:imagedata")) or self::dbk:informaltable]'/>
554 <xsl:when test='@rnd:style = "d:caption" or @rnd:style = "Caption"'>
555 <xsl:call-template name='rnd:error'>
556 <xsl:with-param name='code'>bad-caption</xsl:with-param>
557 <xsl:with-param name='message'>caption does not follow table or figure</xsl:with-param>
561 <xsl:when test='(contains(@rnd:style, "-title") or
562 contains(@rnd:style, "-titleabbrev") or
563 contains(@rnd:style, "-subtitle")) and
564 not(starts-with(@rnd:style, "d:blockquote") or starts-with(@rnd:style, "d:formal"))'>
565 <!-- TODO: check that no non-metadata elements occur before this paragraph -->
568 <!-- Metadata elements are handled in rnd:metadata mode -->
569 <!-- TODO: check that no non-metadata elements occur before this paragraph -->
570 <xsl:when test='&metadata-content;'/>
573 <xsl:call-template name='rnd:error'>
574 <xsl:with-param name='code'>unknown-style</xsl:with-param>
575 <xsl:with-param name='message'>unknown paragraph style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
581 <!-- Determine if the caption belongs to the current figure.
582 If so, then process the textobject content and the caption.
584 <xsl:template name='rnd:figure-text-caption'>
585 <xsl:param name='caption' select='/..'/>
587 <xsl:variable name='textobjs'
588 select='following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]]'/>
591 <xsl:when test='not($caption)'/> <!-- nothing to do -->
592 <xsl:when test='$textobjs[self::dbk:informaltable |
593 self::dbk:inlinemediaobject |
594 self::dbk:para[@rnd:style = "informalfigure-imagedata" or
595 @rnd:style = "mediaobject-imagedata"]]'/> <!-- caption belongs to something else -->
597 <xsl:apply-templates select='$textobjs' mode='rnd:textobject'/>
599 <xsl:apply-templates select='$caption' mode='rnd:caption'/>
604 <xsl:template match='dbk:para' mode='rnd:caption'>
606 <xsl:call-template name='rnd:attributes'/>
607 <xsl:apply-templates/>
611 <xsl:template name='rnd:imagedata-attributes'>
612 <xsl:param name='metadata' select='""'/>
615 <xsl:when test='not($metadata)'/>
616 <xsl:when test='contains($metadata, " ")'>
617 <xsl:call-template name='rnd:imagedata-attributes'>
618 <xsl:with-param name='metadata'
619 select='substring-before($metadata, " ")'/>
621 <xsl:call-template name='rnd:imagedata-attributes'>
622 <xsl:with-param name='metadata'
623 select='substring-after($metadata, " ")'/>
626 <xsl:when test='not(contains($metadata, "="))'>
627 <xsl:call-template name='rnd:warning'>
628 <xsl:with-param name='code' select='"imagedata-missing-value"'/>
629 <xsl:with-param name='message'>
630 <xsl:text>imagedata-metadata missing value for attribute "</xsl:text>
631 <xsl:value-of select='$metadata'/>
632 <xsl:text>"</xsl:text>
637 <xsl:variable name='name'
638 select='translate(normalize-space(substring-before($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "d:abcdefghijklmnopqrstuvwxyz")'/>
639 <xsl:variable name='value'
640 select='translate(normalize-space(substring-after($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "d:abcdefghijklmnopqrstuvwxyz")'/>
643 <xsl:when test='$name = "d:scalefit"'>
644 <xsl:attribute name='scalefit'>
646 <xsl:when test='$value = "1" or
648 $value = "d:true"'>1</xsl:when>
649 <xsl:otherwise>0</xsl:otherwise>
653 <xsl:when test='$name = "d:align" or
654 $name = "d:contentdepth" or
655 $name = "d:contentwidth" or
658 $name = "d:valign" or
660 <!-- TODO: check enumerate values-->
661 <xsl:attribute name='{$name}'>
662 <xsl:value-of select='$value'/>
666 <xsl:call-template name='rnd:error'>
667 <xsl:with-param name='code' select='"imagedata-unknown-attribute"'/>
668 <xsl:with-param name='message'>
669 <xsl:text>imagedata-metadata unknown attribute "</xsl:text>
670 <xsl:value-of select='$name'/>
671 <xsl:text>"</xsl:text>
680 <xsl:template match='dbk:emphasis'>
682 <xsl:when test='not(@rnd:style) and @role = "italic"'>
684 <xsl:apply-templates mode='rnd:copy'/>
687 <xsl:when test='not(@rnd:style) or @role'>
689 <xsl:call-template name='rnd:attributes'/>
690 <xsl:apply-templates mode='rnd:copy'/>
694 <xsl:when test='@rnd:style = preceding-sibling::node()[1][self::dbk:emphasis]/@rnd:style'/>
696 <xsl:when test='@rnd:style = "d:emphasis"'>
698 <xsl:call-template name='rnd:attributes'/>
699 <xsl:apply-templates mode='rnd:copy'/>
700 <xsl:apply-templates select='following-sibling::node()[1]'
701 mode='rnd:emphasis'/>
704 <xsl:when test='@rnd:style = "emphasis-bold" or
705 @rnd:style = "emphasis-strong"'>
707 <xsl:attribute name='role'>bold</xsl:attribute>
708 <xsl:call-template name='rnd:attributes'/>
709 <xsl:apply-templates mode='rnd:copy'/>
710 <xsl:apply-templates select='following-sibling::node()[1]'
711 mode='rnd:emphasis'/>
714 <xsl:when test='@rnd:style = "emphasis-underline"'>
716 <xsl:attribute name='role'>underline</xsl:attribute>
717 <xsl:call-template name='rnd:attributes'/>
718 <xsl:apply-templates mode='rnd:copy'/>
719 <xsl:apply-templates select='following-sibling::node()[1]'
720 mode='rnd:emphasis'/>
724 <xsl:when test='@rnd:style = "d:citetitle" or
725 @rnd:style = "d:literal" or
726 @rnd:style = "d:sgmltag"'>
727 <xsl:element name='{@rnd:style}'
728 namespace='http://docbook.org/ns/docbook'>
729 <xsl:call-template name='rnd:attributes'/>
730 <xsl:apply-templates/>
731 <xsl:apply-templates select='following-sibling::node()[1]'
732 mode='rnd:emphasis'/>
736 <xsl:when test='@rnd:style = "Hyperlink" and
738 <!-- This occurs in a hyperlink; parent should be dbk:link -->
739 <xsl:apply-templates/>
741 <xsl:when test='@rnd:style = "Hyperlink"'>
742 <!-- dbk:link is missing -->
743 <dbk:link xlink:href='{.}'>
744 <xsl:apply-templates/>
748 <!-- In rare circumstances, Word inserts an empty element that appears to be something like a space in the editor -->
749 <xsl:when test='(@rnd:style = "EndnoteReference" or
750 @rnd:style = "FootnoteReference") and
752 <xsl:text> </xsl:text>
756 <xsl:call-template name='rnd:error'>
757 <xsl:with-param name='code'>unknown-style</xsl:with-param>
758 <xsl:with-param name='message'>unknown character span style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
764 <!-- Coalesce emphasis elements into a single element -->
765 <xsl:template match='dbk:emphasis' mode='rnd:emphasis'>
767 <xsl:when test='@rnd:style = preceding-sibling::node()[self::dbk:emphasis]/@rnd:style'>
768 <xsl:apply-templates/>
769 <xsl:apply-templates select='following-sibling::node()[1]'
770 mode='rnd:emphasis'/>
774 <xsl:template match='*|text()' mode='rnd:emphasis'/>
776 <xsl:template match='dbk:emphasis' mode='rnd:personname-emphasis'>
777 <xsl:param name='style'/>
780 <xsl:when test='@rnd:style = $style'>
781 <xsl:apply-templates/>
782 <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
783 mode='rnd:personname-emphasis'>
784 <xsl:with-param name='style' select='$style'/>
785 </xsl:apply-templates>
789 <xsl:template match='*|text()' mode='rnd:emphasis'/>
791 <xsl:template match='dbk:subscript|dbk:superscript'>
793 <xsl:apply-templates select='@*' mode='rnd:copy'/>
794 <xsl:apply-templates/>
800 <xsl:template match='dbk:inlinemediaobject'>
802 <xsl:when test='not(preceding-sibling::*|following-sibling::*) and
803 normalize-space(..) = ""'>
805 <xsl:variable name='next.captioned'
806 select='ancestor::dbk:para/following-sibling::*[self::dbk:informaltable or self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]][1]'/>
808 <xsl:variable name='caption'
809 select='ancestor::dbk:para/following-sibling::dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"]'/>
811 <xsl:variable name='metadata'>
812 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[1]'
813 mode='rnd:metadata'/>
817 <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
820 <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"]'>
822 <xsl:apply-templates select='ancestor::dbk:para/preceding-sibling::*[1]/node()'/>
825 <xsl:copy-of select='$metadata'/>
830 <xsl:apply-templates mode='rnd:copy'/>
834 <xsl:when test='not($caption)'/>
835 <xsl:when test='not($next.captioned)'>
836 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
838 <xsl:apply-templates select='$caption'
841 <!-- Does caption belong to this image or next.captioned?
842 - Only if it belongs to this image do we process it here.
844 <xsl:when test='$next.captioned[preceding-sibling::*[generate-id() = generate-id($caption)]]'>
845 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
847 <xsl:apply-templates select='$caption'
850 <!-- otherwise caption does not belong to this figure -->
855 <xsl:call-template name='rnd:copy'/>
860 <xsl:template match='dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"]'
864 <xsl:apply-templates/>
868 <xsl:template match='*' mode='rnd:caption'/>
870 <xsl:template match='*' mode='rnd:figure'>
871 <xsl:call-template name='rnd:para'>
872 <xsl:with-param name='suppress' select='false()'/>
878 <xsl:template match='*' mode='rnd:sidebar'>
879 <xsl:call-template name='rnd:para'>
880 <xsl:with-param name='suppress' select='false()'/>
886 <xsl:template match='dbk:para' mode='rnd:listitem'>
889 <xsl:call-template name='rnd:attributes'/>
890 <xsl:apply-templates/>
892 <xsl:apply-templates select='following-sibling::*[1]'
893 mode='rnd:continue'/>
895 <!-- Handle nested lists -->
896 <xsl:variable name='list-type'
897 select='concat(substring-before(@rnd:style, "d:list"), "d:list")'/>
898 <xsl:variable name='list-level'
899 select='substring-after(@rnd:style, $list-type)'/>
901 <!-- Assuming only five levels of list nesting.
902 - This is probably better done in a previous stage using grouping.
904 <xsl:variable name='stop.node'
905 select='following-sibling::dbk:para[@rnd:style != concat("d:itemizedlist", $list-level + 1) and
906 @rnd:style != concat("d:orderedlist", $list-level + 1) and
907 @rnd:style != concat("d:itemizedlist", $list-level + 2) and
908 @rnd:style != concat("d:orderedlist", $list-level + 2) and
909 @rnd:style != concat("d:itemizedlist", $list-level + 3) and
910 @rnd:style != concat("d:orderedlist", $list-level + 3) and
911 @rnd:style != "para-continue"][1]'/>
913 <xsl:variable name='nested'
914 select='following-sibling::dbk:para[@rnd:style = concat("d:itemizedlist", $list-level + 1) or @rnd:style = concat("d:orderedlist", $list-level + 1)][1]'/>
917 <!-- Is there a nested list at all? -->
918 <xsl:when test='following-sibling::*[self::dbk:para and @rnd:style != "para-continue"][1][@rnd:style != concat("d:itemizedlist", $list-level + 1) and @rnd:style != concat("d:orderedlist", $list-level + 1)]'/>
920 <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("d:itemizedlist", $list-level + 1) or @rnd:style = concat("d:orderedlist", $list-level + 1)] and
922 <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
923 namespace='http://docbook.org/ns/docbook'>
924 <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("d:itemizedlist", $list-level + 1) or @rnd:style = concat("d:orderedlist", $list-level + 1)][following-sibling::*[generate-id() = generate-id($stop.node)]]'
925 mode='rnd:listitem'/>
928 <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("d:itemizedlist", $list-level + 1) or @rnd:style = concat("d:orderedlist", $list-level + 1)]'>
930 <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
931 namespace='http://docbook.org/ns/docbook'>
932 <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("d:itemizedlist", $list-level + 1) or @rnd:style = concat("d:orderedlist", $list-level + 1)]'
933 mode='rnd:listitem'/>
942 <xsl:template match='dbk:para' mode='rnd:blockquote'>
944 <xsl:when test='@rnd:style ="blockquote-attribution"'/>
945 <xsl:when test='@rnd:style ="blockquote-title"'/>
948 <xsl:apply-templates/>
953 <xsl:template match='dbk:para' mode='rnd:blockquote-attribution'>
954 <xsl:if test='@rnd:style ="blockquote-attribution"'>
956 <xsl:apply-templates/>
963 <xsl:template match='dbk:para' mode='rnd:metadata'>
965 <xsl:when test='@rnd:style = "biblioentry-title" and
966 parent::dbk:bibliography|parent::dbk:bibliodiv'/>
967 <xsl:when test='@rnd:style = "biblioentry-title"'>
968 <xsl:call-template name='rnd:error'>
969 <xsl:with-param name='code'>bad-metadata</xsl:with-param>
970 <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" must not be metadata for parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
974 <xsl:when test='@rnd:style = "abstract-title" or
975 @rnd:style = "d:abstract"'>
976 <xsl:variable name='stop.node'
977 select='following-sibling::dbk:para[@rnd:style != "d:abstract"][1]'/>
979 <xsl:when test='$stop.node'>
981 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "d:abstract"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
982 mode='rnd:abstract'/>
984 <xsl:apply-templates select='$stop.node'
985 mode='rnd:metadata'/>
989 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "d:abstract"]' mode='rnd:abstract'/>
995 <xsl:when test='@rnd:style = "d:legalnotice"'>
996 <xsl:variable name='stop.node'
997 select='following-sibling::dbk:para[@rnd:style != "d:legalnotice"][1]'/>
1000 <xsl:when test='$stop.node'>
1002 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "d:legalnotice"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
1003 mode='rnd:legalnotice'/>
1005 <xsl:apply-templates select='$stop.node'
1006 mode='rnd:metadata'/>
1009 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "d:legalnotice"]'
1010 mode='rnd:legalnotice'/>
1015 <xsl:when test='@rnd:style = "d:keyword"'>
1016 <xsl:variable name='stop.node'
1017 select='following-sibling::*[not(self::dbk:para) or
1018 (self::dbk:para and @rnd:style != "d:keyword")][1]'/>
1021 <xsl:when test='$stop.node'>
1023 <xsl:call-template name='rnd:keyword'>
1024 <xsl:with-param name='nodes'
1025 select='.|following-sibling::dbk:para[@rnd:style = "d:keyword"][following-sibling::*[generate-id() = generate-id($stop.node)]]'/>
1026 </xsl:call-template>
1028 <xsl:apply-templates select='$stop.node'
1029 mode='rnd:metadata'/>
1032 <xsl:call-template name='rnd:keyword'>
1033 <xsl:with-param name='nodes'
1034 select='.|following-sibling::dbk:para[@rnd:style = "d:keyword"]'/>
1035 </xsl:call-template>
1040 <xsl:when test='@rnd:style = "d:author"'>
1043 <xsl:when test='dbk:emphasis[@rnd:style = "d:orgname"]'>
1045 <xsl:apply-templates
1046 select='dbk:emphasis[@rnd:style = "d:orgname"]'
1047 mode='rnd:orgname'/>
1049 <xsl:if test='*[not(@rnd:style = "d:orgname")]'>
1050 <xsl:call-template name='rnd:error'>
1051 <xsl:with-param name='code'>bad-author-orgname-combo</xsl:with-param>
1052 <xsl:with-param name='message'>character span "<xsl:value-of select='dbk:emphasis[@rnd:style != "d:orgname"][1]/@rnd:style'/>" not allowed in an author paragraph combined with orgname</xsl:with-param>
1053 </xsl:call-template>
1058 <!-- TODO: check style of author; mixed content or structured -->
1059 <xsl:apply-templates mode='rnd:personname'/>
1063 <xsl:apply-templates mode='rnd:author-personblurb'/>
1064 <xsl:apply-templates select='following-sibling::*[1]'
1067 <xsl:call-template name='rnd:resume-metadata'>
1068 <xsl:with-param name='node' select='following-sibling::*[1]'/>
1069 </xsl:call-template>
1071 <xsl:when test='@rnd:style = "d:personblurb" or
1072 @rnd:style = "d:address" or
1073 @rnd:style = "d:affiliation" or
1074 @rnd:style = "d:contrib" or
1075 @rnd:style = "d:email"'/>
1077 <xsl:when test='@rnd:style = "d:releaseinfo" or
1078 @rnd:style = "d:date" or
1079 @rnd:style = "d:pubdate" or
1080 @rnd:style = "d:pagenums" or
1081 @rnd:style = "d:issuenum" or
1082 @rnd:style = "d:volumenum" or
1083 @rnd:style = "d:edition" or
1084 @rnd:style = "d:editor" or
1085 @rnd:style = "d:othercredit" or
1086 @rnd:style = "d:biblioid" or
1087 @rnd:style = "d:bibliosource" or
1088 @rnd:style = "d:bibliomisc" or
1089 @rnd:style = "d:revhistory" or
1090 @rnd:style = "d:revision"'>
1091 <xsl:element name='{@rnd:style}'
1092 namespace='http://docbook.org/ns/docbook'>
1093 <xsl:apply-templates mode='rnd:metadata'/>
1095 <xsl:apply-templates select='following-sibling::*[1]'
1096 mode='rnd:metadata'/>
1098 <xsl:when test='contains(@rnd:style, "-titleabbrev")'>
1099 <xsl:variable name='parent'
1100 select='substring-before(@rnd:style, "-titleabbrev")'/>
1103 <xsl:when test='$parent = local-name(..)'>
1105 <xsl:apply-templates mode='rnd:metadata'/>
1108 <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
1109 preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
1111 <xsl:apply-templates mode='rnd:metadata'/>
1115 <xsl:call-template name='rnd:error'>
1116 <xsl:with-param name='code'>bad-titleabbrev</xsl:with-param>
1117 <xsl:with-param name='message'>titleabbrev style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1118 </xsl:call-template>
1122 <xsl:apply-templates select='following-sibling::*[1]'
1123 mode='rnd:metadata'/>
1125 <xsl:when test='contains(@rnd:style, "-title")'>
1126 <xsl:variable name='parent'
1127 select='substring-before(@rnd:style, "-title")'/>
1130 <xsl:when test='$parent = "d:table" or
1131 $parent = "d:figure"'>
1133 <xsl:apply-templates mode='rnd:metadata'/>
1136 <xsl:when test='$parent = local-name(..)'>
1138 <xsl:apply-templates mode='rnd:metadata'/>
1141 <xsl:when test='parent::dbk:book-component'>
1143 <xsl:apply-templates mode='rnd:metadata'/>
1146 <xsl:when test='parent::dbk:article and
1149 <xsl:apply-templates mode='rnd:metadata'/>
1153 <xsl:call-template name='rnd:error'>
1154 <xsl:with-param name='code'>bad-title</xsl:with-param>
1155 <xsl:with-param name='message'>title style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1156 </xsl:call-template>
1160 <xsl:apply-templates select='following-sibling::*[1]'
1161 mode='rnd:metadata'/>
1164 <!-- Exception to normal subtitle handling is biblioentry-subtitle -->
1165 <xsl:when test='@rnd:style = "biblioentry-subtitle"'>
1166 <!-- TODO: check that this is in a biblioentry -->
1168 <xsl:apply-templates mode='rnd:metadata'/>
1171 <xsl:apply-templates select='following-sibling::*[1]'
1172 mode='rnd:metadata'/>
1174 <xsl:when test='contains(@rnd:style, "-subtitle")'>
1175 <xsl:variable name='parent'
1176 select='substring-before(@rnd:style, "-subtitle")'/>
1179 <xsl:when test='$parent = local-name(..)'>
1181 <xsl:apply-templates mode='rnd:metadata'/>
1184 <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
1185 preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
1187 <xsl:apply-templates mode='rnd:metadata'/>
1191 <xsl:call-template name='rnd:error'>
1192 <xsl:with-param name='code'>bad-subtitle</xsl:with-param>
1193 <xsl:with-param name='message'>subtitle style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1194 </xsl:call-template>
1198 <xsl:apply-templates select='following-sibling::*[1]'
1199 mode='rnd:metadata'/>
1202 <xsl:when test='@rnd:style = "publisher-address" and
1203 preceding-sibling::*[1][not(self::dbk:para) or not(@rnd:style = "d:publisher")]'>
1204 <xsl:call-template name='rnd:error'>
1205 <xsl:with-param name='code'>bad-publisher-address</xsl:with-param>
1206 <xsl:with-param name='message'>publisher-address must follow publisher</xsl:with-param>
1207 </xsl:call-template>
1208 <xsl:apply-templates select='following-sibling::*[1]'
1209 mode='rnd:metadata'/>
1211 <xsl:when test='@rnd:style = "publisher-address"'>
1212 <xsl:apply-templates select='following-sibling::*[1]'
1213 mode='rnd:metadata'/>
1215 <xsl:when test='@rnd:style = "d:publisher"'>
1218 <xsl:apply-templates/>
1219 </dbk:publishername>
1220 <xsl:if test='following-sibling::*[1][@rnd:style = "publisher-address"]'>
1221 <xsl:apply-templates select='following-sibling::*[1]'
1222 mode='rnd:publisher'/>
1226 <xsl:apply-templates select='following-sibling::*[1]'
1227 mode='rnd:metadata'/>
1232 <xsl:template name='rnd:keyword'>
1233 <xsl:param name='nodes' select='/..'/>
1236 <xsl:when test='not($nodes)'/>
1238 <xsl:call-template name='rnd:keyword-phrases'>
1239 <xsl:with-param name='text' select='$nodes[1]'/>
1240 </xsl:call-template>
1241 <xsl:call-template name='rnd:keyword'>
1242 <xsl:with-param name='nodes' select='$nodes[position() != 1]'/>
1243 </xsl:call-template>
1247 <xsl:template name='rnd:keyword-phrases'>
1248 <xsl:param name='text'/>
1251 <xsl:when test='not($text)'/>
1252 <xsl:when test='contains($text, ",")'>
1254 <xsl:value-of select='normalize-space(substring-before($text, ","))'/>
1256 <xsl:call-template name='rnd:keyword-phrases'>
1257 <xsl:with-param name='text' select='substring-after($text, ",")'/>
1258 </xsl:call-template>
1262 <xsl:value-of select='normalize-space($text)'/>
1268 <xsl:template match='dbk:emphasis' mode='rnd:metadata'>
1270 <xsl:when test='not(@rnd:style)'>
1272 <xsl:apply-templates mode='rnd:metadata'/>
1275 <xsl:when test='@rnd:style = "Hyperlink" and
1277 <xsl:apply-templates mode='rnd:metadata'/>
1279 <xsl:when test='@rnd:style = "Hyperlink"'>
1280 <dbk:link xlink:href='{.}'>
1281 <xsl:apply-templates mode='rnd:metadata'/>
1285 <xsl:element name='{@rnd:style}'
1286 namespace='http://docbook.org/ns/docbook'>
1287 <xsl:apply-templates mode='rnd:metadata'/>
1292 <xsl:template match='dbk:link' mode='rnd:metadata'>
1294 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1295 <xsl:apply-templates mode='rnd:metadata'/>
1298 <xsl:template match='dbk:inlinemediaobject' mode='rnd:metadata'>
1299 <xsl:call-template name='rnd:copy'/>
1301 <xsl:template match='*' mode='rnd:metadata'/>
1303 <xsl:template name='rnd:resume-metadata'>
1304 <xsl:param name='node' select='/..'/>
1307 <xsl:when test='$node[self::dbk:para][&author-content;]'>
1308 <xsl:call-template name='rnd:resume-metadata'>
1309 <xsl:with-param name='node' select='$node/following-sibling::*[1]'/>
1310 </xsl:call-template>
1312 <xsl:when test='$node[self::dbk:para][&metadata-content;]'>
1313 <xsl:apply-templates select='$node' mode='rnd:metadata'/>
1318 <xsl:template match='dbk:para' mode='rnd:abstract'>
1320 <xsl:when test='@rnd:style = "abstract-title"'>
1322 <xsl:call-template name='rnd:attributes'/>
1323 <xsl:apply-templates/>
1328 <xsl:call-template name='rnd:attributes'/>
1329 <xsl:apply-templates/>
1335 <xsl:template match='dbk:para' mode='rnd:legalnotice'>
1337 <xsl:call-template name='rnd:attributes'/>
1338 <xsl:apply-templates/>
1342 <xsl:template match='dbk:footnote' mode='rnd:personname'/>
1343 <xsl:template match='dbk:emphasis' mode='rnd:personname'>
1344 <!-- Need to check preceding emphasis for same style,
1345 but blocks pretty-prints and all text nodes
1346 are preserved in paragraph content.
1348 <xsl:variable name='previous'
1349 select='preceding-sibling::node()[not(self::text()) or (self::text() and normalize-space() != "")]'/>
1351 <xsl:comment> this style is <xsl:value-of select='@rnd:style'/>, previous style is <xsl:value-of select='$previous[last()]/@rnd:style'/> # previous <xsl:value-of select='count($previous)'/></xsl:comment>
1354 <!-- inlines are coalesced -->
1355 <xsl:when test='@rnd:style = $previous[last()][self::dbk:emphasis]/@rnd:style'/>
1356 <xsl:when test='@rnd:style = "d:honorific" or
1357 @rnd:style = "d:firstname" or
1358 @rnd:style = "d:lineage" or
1359 @rnd:style = "d:othername" or
1360 @rnd:style = "d:surname"'>
1361 <xsl:element name='{@rnd:style}'
1362 namespace='http://docbook.org/ns/docbook'>
1363 <xsl:apply-templates/>
1364 <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
1365 mode='rnd:personname-emphasis'>
1366 <xsl:with-param name='style' select='@rnd:style'/>
1367 </xsl:apply-templates>
1371 <xsl:call-template name='rnd:error'>
1372 <xsl:with-param name='code'>bad-author-inline</xsl:with-param>
1373 <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in an author paragraph</xsl:with-param>
1374 </xsl:call-template>
1379 <xsl:template match='text()' mode='rnd:author-personblurb'/>
1380 <xsl:template match='dbk:emphasis' mode='rnd:author-personblurb'/>
1381 <xsl:template match='dbk:footnote' mode='rnd:author-personblurb'>
1385 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1386 <xsl:apply-templates/>
1392 <xsl:template match='dbk:para' mode='rnd:author'>
1394 <xsl:when test='@rnd:style = "d:personblurb" and
1395 preceding-sibling::*[1][self::dbk:para and @rnd:style != "d:personblurb"]'>
1397 <xsl:apply-templates select='.'
1398 mode='rnd:personblurb'/>
1401 <xsl:when test='@rnd:style = "d:personblurb"'>
1402 <xsl:apply-templates select='following-sibling::*[1]'
1406 <!-- Web and mail addresses may appear in a simplified form -->
1407 <xsl:when test='@rnd:style = "d:address"'>
1409 <xsl:when test='dbk:link and
1410 count(dbk:link) = count(*)'>
1411 <!-- simplified form -->
1413 <xsl:apply-templates select='dbk:link'
1414 mode='rnd:otheraddr'/>
1419 <xsl:apply-templates mode='rnd:author'/>
1421 <xsl:apply-templates select='following-sibling::*[1]'
1427 <xsl:when test='@rnd:style = "d:affiliation"'>
1430 <xsl:when test='not(*)'>
1432 <xsl:apply-templates mode='rnd:author'/>
1436 <xsl:apply-templates mode='rnd:author'/>
1440 <xsl:apply-templates select='following-sibling::*[1]'
1443 <xsl:when test='@rnd:style = "d:contrib" or
1444 @rnd:style = "d:email"'>
1445 <xsl:element name='{@rnd:style}'
1446 namespace='http://docbook.org/ns/docbook'>
1447 <xsl:apply-templates mode='rnd:author'/>
1449 <xsl:apply-templates select='following-sibling::*[1]'
1455 <xsl:template match='dbk:link' mode='rnd:otheraddr'>
1457 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1458 <xsl:apply-templates mode='rnd:otheraddr'/>
1462 <!-- TODO: not all of these inlines are allowed in all elements that are children of author.
1463 Need to further refine validation of inlines.
1465 <xsl:template match='dbk:emphasis' mode='rnd:author'>
1467 <xsl:when test='@rnd:style = "d:city" or
1468 @rnd:style = "d:country" or
1469 @rnd:style = "d:email" or
1470 @rnd:style = "d:fax" or
1471 @rnd:style = "d:jobtitle" or
1472 @rnd:style = "d:orgdiv" or
1473 @rnd:style = "d:orgname" or
1474 @rnd:style = "d:otheraddr" or
1475 @rnd:style = "d:phone" or
1476 @rnd:style = "d:pob" or
1477 @rnd:style = "d:postcode" or
1478 @rnd:style = "d:shortaffil" or
1479 @rnd:style = "d:state" or
1480 @rnd:style = "d:street"'>
1481 <xsl:element name='{@rnd:style}'
1482 namespace='http://docbook.org/ns/docbook'>
1483 <xsl:apply-templates/>
1487 <xsl:call-template name='rnd:error'>
1488 <xsl:with-param name='code'>metadata-bad-inline</xsl:with-param>
1489 <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in author metadata</xsl:with-param>
1490 </xsl:call-template>
1495 <xsl:template match='dbk:para' mode='rnd:personblurb'>
1496 <xsl:if test='@rnd:style = "d:personblurb"'>
1498 <xsl:apply-templates/>
1500 <xsl:apply-templates select='following-sibling::*[1]'
1501 mode='rnd:personblurb'/>
1505 <xsl:template match='dbk:para' mode='rnd:publisher'>
1506 <xsl:if test='@rnd:style = "publisher-address"'>
1508 <xsl:apply-templates/>
1513 <xsl:template match='dbk:para' mode='rnd:programlisting'>
1514 <xsl:text>
</xsl:text>
1515 <xsl:apply-templates/>
1518 <!-- Continuing paragraphs -->
1520 <xsl:template match='*' mode='rnd:continue'/>
1521 <xsl:template match='dbk:para' mode='rnd:continue'>
1522 <xsl:if test='@rnd:style = "para-continue"'>
1524 <xsl:call-template name='rnd:attributes'/>
1525 <xsl:apply-templates/>
1527 <xsl:apply-templates select='following-sibling::*[1]'
1528 mode='rnd:continue'/>
1531 <xsl:template match='dbk:informaltable' mode='rnd:continue'>
1532 <xsl:apply-templates select='.'>
1533 <xsl:with-param name='in-list' select='true()'/>
1534 </xsl:apply-templates>
1535 <xsl:apply-templates select='following-sibling::*[1]'
1536 mode='rnd:continue'/>
1541 <xsl:template match='dbk:informaltable'>
1542 <xsl:param name='in-list' select='false()'/>
1545 <xsl:when test='not($in-list) and
1546 preceding-sibling::dbk:para[1][starts-with(@rnd:style, "d:itemizedlist") or starts-with(@rnd:style, "d:orderedlist") or @rnd:style = "para-continue"]'/>
1547 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style ="table-title"]'>
1549 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1552 <xsl:apply-templates select='preceding-sibling::dbk:para[1]'
1553 mode='rnd:table-title'/>
1556 <xsl:call-template name='rnd:table-textobject'/>
1558 <xsl:apply-templates/>
1560 <xsl:call-template name='rnd:table-caption'/>
1565 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1567 <xsl:call-template name='rnd:table-textobject'/>
1569 <xsl:apply-templates/>
1571 <xsl:call-template name='rnd:table-caption'/>
1576 <xsl:template match='dbk:tgroup'>
1578 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1579 <xsl:if test='not(@cols)'>
1580 <xsl:attribute name='cols'>
1581 <xsl:call-template name='dbk:max-columns'>
1582 <xsl:with-param name='rows' select='*/dbk:row'/>
1583 </xsl:call-template>
1586 <xsl:apply-templates/>
1589 <xsl:template name='dbk:max-columns'>
1590 <xsl:param name='rows' select='/..'/>
1591 <xsl:param name='max' select='0'/>
1593 <!-- This is a tail-recursive algorithm.
1594 Could improve this with other algorithm(s),
1595 eg. divide-and-conquer.
1599 <xsl:when test='not($rows)'>
1600 <xsl:value-of select='$max'/>
1602 <xsl:when test='count($rows[1]/dbk:entry) > $max'>
1603 <xsl:call-template name='dbk:max-columns'>
1604 <xsl:with-param name='rows' select='$rows[position() != 1]'/>
1605 <xsl:with-param name='max' select='count($rows[1]/dbk:entry)'/>
1606 </xsl:call-template>
1609 <xsl:call-template name='dbk:max-columns'>
1610 <xsl:with-param name='rows' select='$rows[position() != 1]'/>
1611 <xsl:with-param name='max' select='$max'/>
1612 </xsl:call-template>
1616 <xsl:template match='dbk:tbody|dbk:thead|dbk:tfoot|dbk:row|dbk:colspec'>
1618 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1619 <xsl:apply-templates/>
1622 <xsl:template match='dbk:entry'>
1624 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1625 <xsl:apply-templates/>
1629 <xsl:template match='dbk:para' mode='rnd:table-title'>
1631 <xsl:apply-templates/>
1635 <!-- Find the caption associated with this table -->
1636 <xsl:template name='rnd:table-caption'>
1637 <xsl:variable name='candidate'
1638 select='following-sibling::dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"][1]'/>
1640 <xsl:if test='$candidate != "" and
1641 generate-id($candidate/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
1644 <xsl:apply-templates select='$candidate/node()'/>
1650 <!-- Find table associated text -->
1651 <xsl:template name='rnd:table-textobject'>
1652 <xsl:variable name='caption'
1653 select='following-sibling::dbk:para[@rnd:style = "d:caption" or @rnd:style = "Caption"][1]'/>
1655 <xsl:if test='generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
1656 <xsl:variable name='content'
1657 select='following-sibling::*[following-sibling::*[generate-id($caption) = generate-id()]]'/>
1658 <xsl:if test='$content'>
1660 <xsl:apply-templates select='$content' mode='rnd:textobject'/>
1665 <xsl:template match='dbk:para' mode='rnd:textobject'>
1666 <xsl:call-template name='rnd:para'>
1667 <xsl:with-param name='suppress' select='false()'/>
1668 </xsl:call-template>
1672 <xsl:template match='dbk:footnote'>
1674 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1675 <xsl:apply-templates/>
1681 <!-- rnd:attributes reconstitutes an element's attributes -->
1682 <xsl:template name='rnd:attributes'>
1683 <xsl:param name='node' select='.'/>
1685 <xsl:apply-templates select='$node/@*[namespace-uri() != "http://docbook.org/d:ns/d:docbook/d:roundtrip"]' mode='rnd:copy'/>
1688 <xsl:template match='*' name='rnd:copy' mode='rnd:copy'>
1690 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1691 <xsl:apply-templates mode='rnd:copy'/>
1694 <xsl:template match='@*' mode='rnd:copy'>
1698 <!-- These templates are invoked whenever an error condition is detected in the conversion of a document.
1700 <xsl:template name='rnd:error'>
1701 <xsl:param name='node' select='.'/>
1702 <xsl:param name='code'/>
1703 <xsl:param name='message'/>
1705 <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
1706 <xsl:message>ERROR "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
1709 <xsl:value-of select='$code'/>
1712 <xsl:value-of select='$message'/>
1716 <xsl:template name='rnd:warning'>
1717 <xsl:param name='node' select='.'/>
1718 <xsl:param name='code'/>
1719 <xsl:param name='message'/>
1721 <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
1722 <xsl:message>WARNING "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
1725 <xsl:value-of select='$code'/>
1728 <xsl:value-of select='$message'/>