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 version="1.0"
14 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15 xmlns:dbk='http://docbook.org/ns/docbook'
16 xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
17 xmlns:xlink='http://www.w3.org/1999/xlink'>
19 <!-- $Id: blocks2dbk.xsl 8137 2008-10-09 03:37:56Z balls $ -->
20 <!-- Stylesheet to convert word processing docs to DocBook -->
21 <!-- This stylesheet processes the output of sections2blocks.xsl -->
23 <xsl:output indent="yes" method="xml"
24 cdata-section-elements='dbk:programlisting dbk:literallayout'/>
26 <!-- ================================================== -->
28 <!-- ================================================== -->
30 <xsl:param name='docbook5'>0</xsl:param>
31 <xsl:param name="nest.sections">1</xsl:param>
33 <xsl:strip-space elements='*'/>
34 <xsl:preserve-space elements='dbk:para dbk:emphasis'/>
36 <xsl:template match="&components; |
39 <xsl:when test='self::dbk:article and
40 count(dbk:book) = 1 and
41 count(dbk:info|dbk:book) <= 2'>
42 <xsl:apply-templates select='dbk:book'/>
44 <xsl:when test='self::dbk:article and
45 *[1][self::dbk:para] and
46 *[1]/@rnd:style != "article-title" and
47 contains(*[1]/@rnd:style, "-title")'>
48 <xsl:variable name='element-name'
49 select='substring-before(*[1]/@rnd:style, "-title")'/>
50 <xsl:element name='{$element-name}'
51 namespace='http://docbook.org/ns/docbook'>
53 <xsl:apply-templates select='*[1]'
56 <xsl:apply-templates/>
61 <xsl:call-template name='rnd:attributes'/>
63 <xsl:variable name='metadata'>
64 <xsl:apply-templates select='*[1]'
67 <xsl:if test='$metadata'>
69 <xsl:copy-of select='$metadata'/>
73 <xsl:apply-templates/>
79 <xsl:template match='dbk:book-component'>
80 <xsl:variable name='element-name'
81 select='substring-before(*[1]/@rnd:style, "-title")'/>
83 <xsl:element name='{$element-name}'
84 namespace='http://docbook.org/ns/docbook'>
86 <xsl:apply-templates select='*[1]'
89 <xsl:apply-templates/>
93 <xsl:template match="dbk:para" name='rnd:para'>
94 <!-- Some elements are normally suppressed,
95 since they are processed in a different context.
96 If this parameter is false then the element will be processed normally.
98 <xsl:param name='suppress' select='true()'/>
100 <!-- This paragraph may be in a sidebar -->
101 <xsl:variable name='sidebar'
102 select='preceding-sibling::*[self::dbk:para and @rnd:style = "sidebar-title"][1]'/>
104 <!-- This paragraph may be in the textobject of a table or figure -->
105 <xsl:variable name='table'
106 select='preceding-sibling::dbk:informaltable[1]'/>
107 <xsl:variable name='figure'
108 select='preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]'/>
109 <xsl:variable name='caption'
110 select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'/>
113 <!-- continue style paragraphs are handled in context -->
114 <xsl:when test='$suppress and
115 @rnd:style = "para-continue"'/>
117 <!-- Certain elements gather the following paragraph -->
118 <xsl:when test='$suppress and
119 preceding-sibling::*[1][self::dbk:para and
120 @rnd:style = "example-title"]'/>
122 <xsl:when test='$suppress and
124 not(preceding-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
125 preceding-sibling::*[preceding-sibling::*[generate-id() = generate-id($sidebar)]]])'/>
127 <!-- Separate processing is performed for table/figure titles and captions -->
128 <xsl:when test='$suppress and
129 @rnd:style = "table-title" and
130 following-sibling::*[1][self::dbk:informaltable|self::dbk:para[@rnd:style = "informalfigure-imagedata"]|self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]]'/>
131 <xsl:when test='$suppress and
132 @rnd:style = "figure-title" and
133 following-sibling::*[1][self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")]'/>
134 <xsl:when test='$suppress and
135 (@rnd:style = "caption" or @rnd:style = "Caption") and
136 (preceding-sibling::*[self::dbk:informaltable] or
137 preceding-sibling::*[self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")])'/>
139 <xsl:when test='$suppress and
142 generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id($table)'/>
143 <xsl:when test='$suppress and
146 generate-id($caption/preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]) = generate-id($figure)'/>
148 <xsl:when test='@rnd:style = "imagedata-metadata" or
149 @rnd:style = "table-metadata"'/>
151 <!-- Ignore empty paragraphs -->
152 <xsl:when test='(not(@rnd:style) or
154 normalize-space(.) = "" and
157 <!-- Image inline or block? -->
158 <xsl:when test='(not(@rnd:style) or
160 normalize-space(.) = "" and
162 dbk:inlinemediaobject'>
163 <xsl:apply-templates/>
165 <xsl:when test='not(@rnd:style) or
167 @rnd:style = "para-continue"'>
169 <xsl:call-template name='rnd:attributes'/>
170 <xsl:apply-templates/>
174 <xsl:when test='@rnd:style = "xinclude"'
175 xmlns:xi='http://www.w3.org/2001/XInclude'>
177 <xsl:attribute name='href'>
178 <xsl:apply-templates mode='rnd:xinclude'/>
183 <xsl:when test='$suppress and
184 preceding-sibling::*[1]/self::dbk:para[&admonition-title;]'/>
185 <xsl:when test='&admonition-title;'>
186 <xsl:element name='{substring-before(@rnd:style, "-title")}'
187 namespace='http://docbook.org/ns/docbook'>
188 <xsl:call-template name='rnd:attributes'/>
190 <xsl:apply-templates/>
192 <xsl:apply-templates select='following-sibling::*[1]'>
193 <xsl:with-param name='suppress' select='false()'/>
194 </xsl:apply-templates>
195 <xsl:apply-templates select='following-sibling::*[2]'
196 mode='rnd:continue'/>
200 <xsl:when test='starts-with(@rnd:style, "itemizedlist") or
201 starts-with(@rnd:style, "orderedlist")'>
203 <xsl:variable name='stop.node'
204 select='following-sibling::dbk:para[not(@rnd:style) or
205 (not(starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist")) and @rnd:style != "para-continue")][1]'/>
208 <xsl:when test='translate(substring-after(@rnd:style, "list"), "0123456789", "") != "" or
209 substring-after(@rnd:style, "list") = ""'>
210 <xsl:call-template name='rnd:error'>
211 <xsl:with-param name='code' select='"list-bad-level"'/>
212 <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" is not a valid list style</xsl:with-param>
216 <!-- TODO: the previous para-continue may not be associated with a list -->
218 <!-- NB. Look back at the previous paragraph. There may be intervening tables or images. -->
219 <xsl:when test='preceding-sibling::dbk:para[1][starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist") or @rnd:style = "para-continue"]'/>
220 <xsl:when test='substring-after(@rnd:style, "list") != 1'>
221 <xsl:call-template name='rnd:error'>
222 <xsl:with-param name='code'>list-wrong-level</xsl:with-param>
223 <xsl:with-param name='message'>list started at the wrong level</xsl:with-param>
226 <xsl:when test='$stop.node'>
227 <xsl:element name='{substring-before(@rnd:style, "1")}'
228 namespace='http://docbook.org/ns/docbook'>
229 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style][following-sibling::*[generate-id() = generate-id($stop.node)]]'
230 mode='rnd:listitem'/>
234 <xsl:element name='{substring-before(@rnd:style, "1")}'
235 namespace='http://docbook.org/ns/docbook'>
236 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = current()/@rnd:style]'
237 mode='rnd:listitem'/>
243 <xsl:when test='@rnd:style = "programlisting" and
244 preceding-sibling::*[1][self::dbk:para and @rnd:style = "programlisting"]'/>
245 <xsl:when test='@rnd:style = "literallayout" and
246 preceding-sibling::*[1][self::dbk:para and @rnd:style = "literallayout"]'/>
247 <xsl:when test='@rnd:style = "programlisting" or
248 @rnd:style = "literallayout"'>
250 <xsl:variable name='stop.node'
251 select='following-sibling::dbk:para[@rnd:style != current()/@rnd:style][1]'/>
253 <xsl:element name='{@rnd:style}'
254 namespace='http://docbook.org/ns/docbook'>
255 <xsl:apply-templates/>
258 <xsl:when test='$stop.node'>
259 <xsl:apply-templates select='following-sibling::dbk:para[following-sibling::*[generate-id() = generate-id($stop.node)]]'
260 mode='rnd:programlisting'/>
263 <xsl:apply-templates select='following-sibling::dbk:para'
264 mode='rnd:programlisting'/>
270 <xsl:when test='@rnd:style = "example-title"'>
271 <xsl:element name='{substring-before(@rnd:style, "-title")}'
272 namespace='http://docbook.org/ns/docbook'>
273 <xsl:call-template name='rnd:attributes'/>
275 <xsl:apply-templates/>
278 <xsl:apply-templates select='following-sibling::*[1]'>
279 <xsl:with-param name='suppress' select='false()'/>
280 </xsl:apply-templates>
284 <xsl:when test='@rnd:style = "sidebar-title"'>
285 <!-- TODO: next sidebar should stop this sidebar -->
286 <xsl:variable name='stop.node'
287 select='following-sibling::dbk:para[(not(@rnd:style) or @rnd:style = "") and
288 normalize-space(.) = ""][1]'/>
291 <xsl:call-template name='rnd:attributes'/>
294 <xsl:apply-templates/>
299 <xsl:when test='$stop.node'>
300 <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
304 <xsl:apply-templates select='following-sibling::*'
311 <xsl:when test='&admonition;'>
312 <xsl:element name='{@rnd:style}'
313 namespace='http://docbook.org/ns/docbook'>
314 <xsl:call-template name='rnd:attributes'/>
316 <xsl:apply-templates/>
318 <xsl:apply-templates select='following-sibling::*[1]'
319 mode='rnd:continue'/>
323 <!-- TODO: make sure this is in a bibliography.
324 If not, create a bibliolist.
326 <xsl:when test='@rnd:style = "bibliomixed"'>
328 <xsl:call-template name='rnd:attributes'/>
329 <xsl:apply-templates/>
332 <xsl:when test='@rnd:style = "biblioentry-title"'>
334 <xsl:call-template name='rnd:attributes'/>
336 <xsl:apply-templates/>
338 <xsl:if test='following-sibling::*[1][&metadata-content;]'>
339 <xsl:apply-templates select='following-sibling::*[1]'
340 mode='rnd:metadata'/>
345 <xsl:when test='@rnd:style = "blockquote-attribution" and
346 preceding-sibling::*[1][self::dbk:para][@rnd:style = "blockquote-title" or @rnd:style = "blockquote"]'/>
347 <xsl:when test='@rnd:style = "blockquote-attribution"'>
348 <xsl:call-template name='rnd:error'>
349 <xsl:with-param name='code'>improper-blockquote-attribution</xsl:with-param>
350 <xsl:with-param name='message'>blockquote attribution must follow a blockquote title</xsl:with-param>
353 <xsl:when test='@rnd:style = "blockquote" or
354 @rnd:style = "blockquote-title"'>
356 <xsl:when test='@rnd:style = "blockquote" and
357 preceding-sibling::*[1][self::dbk:para][starts-with(@rnd:style, "blockquote")]'/>
360 <xsl:variable name='stop.node'
361 select='following-sibling::*[not(@rnd:style = "blockquote" or
362 @rnd:style = "blockquote-attribution")][1]'/>
365 <xsl:call-template name='rnd:attributes'/>
366 <xsl:if test='@rnd:style = "blockquote-title"'>
369 <xsl:apply-templates/>
374 <xsl:when test='$stop.node'>
375 <xsl:apply-templates select='following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]][@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
376 <xsl:apply-templates select='self::*[@rnd:style = "blockquote"] |
377 following-sibling::*[following-sibling::*[generate-id() = generate-id($stop.node)]]'
378 mode='rnd:blockquote'/>
381 <xsl:apply-templates select='following-sibling::*[@rnd:style = "blockquote-attribution"]' mode='rnd:blockquote-attribution'/>
382 <xsl:apply-templates select='self::*[@rnd:style = "blockquote"] |
383 following-sibling::*'
384 mode='rnd:blockquote'/>
392 <xsl:when test='@rnd:style = "bridgehead"'>
393 <xsl:element name='{@rnd:style}'
394 namespace='http://docbook.org/ns/docbook'>
395 <xsl:call-template name='rnd:attributes'/>
396 <xsl:apply-templates/>
400 <xsl:when test='@rnd:style = "formalpara-title"'>
403 <xsl:call-template name='rnd:attributes'/>
404 <xsl:apply-templates/>
407 <xsl:when test='following-sibling::*[1][self::dbk:para][@rnd:style = "formalpara"]'>
409 <xsl:call-template name='rnd:attributes'>
410 <xsl:with-param name='node'
411 select='following-sibling::*[1]'/>
413 <xsl:apply-templates select='following-sibling::*[1]/node()'/>
419 <xsl:when test='@rnd:style = "formalpara" and
420 preceding-sibling::*[1][self::dbk:para][@rnd:style = "formalpara-title"]'/>
421 <xsl:when test='@rnd:style = "formalpara"'>
422 <xsl:call-template name='rnd:error'>
423 <xsl:with-param name='code'>formalpara-notitle</xsl:with-param>
424 <xsl:with-param name='message'>formalpara used without a title</xsl:with-param>
428 <xsl:when test='@rnd:style = "informalfigure-imagedata"'>
429 <xsl:variable name='caption.next'
430 select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
432 <xsl:variable name='metadata'
433 select='preceding-sibling::*[1][self::dbk:para][@rnd:style = "imagedata-metadata"]'/>
436 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
437 ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "figure-title"])'>
439 <xsl:call-template name='rnd:attributes'/>
443 <xsl:when test='$metadata'>
445 select='preceding-sibling::*[2]/node()'/>
449 select='preceding-sibling::*[1]/node()'/>
457 <xsl:attribute name='fileref'>
459 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
460 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
463 <xsl:value-of select='.'/>
467 <xsl:call-template name='rnd:imagedata-attributes'>
468 <xsl:with-param name='metadata' select='$metadata'/>
473 <xsl:call-template name='rnd:figure-text-caption'>
474 <xsl:with-param name='caption' select='$caption.next'/>
478 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "table-title"] or
479 ($metadata and preceding-sibling::*[2][self::dbk:para][@rnd:style = "table-title"])'>
481 <xsl:call-template name='rnd:attributes'/>
485 <xsl:when test='$metadata'>
487 select='preceding-sibling::*[2]/node()'/>
491 select='preceding-sibling::*[1]/node()'/>
500 <xsl:attribute name='fileref'>
502 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
503 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
506 <xsl:value-of select='.'/>
510 <xsl:call-template name='rnd:imagedata-attributes'>
511 <xsl:with-param name='metadata' select='$metadata'/>
516 <xsl:call-template name='rnd:figure-text-caption'>
517 <xsl:with-param name='caption' select='$caption.next'/>
523 <xsl:call-template name='rnd:attributes'/>
527 <xsl:attribute name='fileref'>
529 <xsl:when test='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref != ""'>
530 <xsl:value-of select='dbk:inlinemediaobject/dbk:imageobject/dbk:imagedata/@fileref'/>
533 <xsl:value-of select='.'/>
537 <xsl:call-template name='rnd:imagedata-attributes'>
538 <xsl:with-param name='metadata' select='$metadata'/>
543 <xsl:call-template name='rnd:figure-text-caption'>
544 <xsl:with-param name='caption' select='$caption.next'/>
546 </dbk:informalfigure>
551 <xsl:when test='(@rnd:style = "caption" or @rnd:style = "Caption") and
552 preceding-sibling::*[(self::dbk:para and contains(@rnd:style, "imagedata")) or self::dbk:informaltable]'/>
553 <xsl:when test='@rnd:style = "caption" or @rnd:style = "Caption"'>
554 <xsl:call-template name='rnd:error'>
555 <xsl:with-param name='code'>bad-caption</xsl:with-param>
556 <xsl:with-param name='message'>caption does not follow table or figure</xsl:with-param>
560 <xsl:when test='(contains(@rnd:style, "-title") or
561 contains(@rnd:style, "-titleabbrev") or
562 contains(@rnd:style, "-subtitle")) and
563 not(starts-with(@rnd:style, "blockquote") or starts-with(@rnd:style, "formal"))'>
564 <!-- TODO: check that no non-metadata elements occur before this paragraph -->
567 <!-- Metadata elements are handled in rnd:metadata mode -->
568 <!-- TODO: check that no non-metadata elements occur before this paragraph -->
569 <xsl:when test='&metadata-content;'/>
572 <xsl:call-template name='rnd:error'>
573 <xsl:with-param name='code'>unknown-style</xsl:with-param>
574 <xsl:with-param name='message'>unknown paragraph style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
580 <!-- Determine if the caption belongs to the current figure.
581 If so, then process the textobject content and the caption.
583 <xsl:template name='rnd:figure-text-caption'>
584 <xsl:param name='caption' select='/..'/>
586 <xsl:variable name='textobjs'
587 select='following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]]'/>
590 <xsl:when test='not($caption)'/> <!-- nothing to do -->
591 <xsl:when test='$textobjs[self::dbk:informaltable |
592 self::dbk:inlinemediaobject |
593 self::dbk:para[@rnd:style = "informalfigure-imagedata" or
594 @rnd:style = "mediaobject-imagedata"]]'/> <!-- caption belongs to something else -->
596 <xsl:apply-templates select='$textobjs' mode='rnd:textobject'/>
598 <xsl:apply-templates select='$caption' mode='rnd:caption'/>
603 <xsl:template match='dbk:para' mode='rnd:caption'>
605 <xsl:call-template name='rnd:attributes'/>
606 <xsl:apply-templates/>
610 <xsl:template name='rnd:imagedata-attributes'>
611 <xsl:param name='metadata' select='""'/>
614 <xsl:when test='not($metadata)'/>
615 <xsl:when test='contains($metadata, " ")'>
616 <xsl:call-template name='rnd:imagedata-attributes'>
617 <xsl:with-param name='metadata'
618 select='substring-before($metadata, " ")'/>
620 <xsl:call-template name='rnd:imagedata-attributes'>
621 <xsl:with-param name='metadata'
622 select='substring-after($metadata, " ")'/>
625 <xsl:when test='not(contains($metadata, "="))'>
626 <xsl:call-template name='rnd:warning'>
627 <xsl:with-param name='code' select='"imagedata-missing-value"'/>
628 <xsl:with-param name='message'>
629 <xsl:text>imagedata-metadata missing value for attribute "</xsl:text>
630 <xsl:value-of select='$metadata'/>
631 <xsl:text>"</xsl:text>
636 <xsl:variable name='name'
637 select='translate(normalize-space(substring-before($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")'/>
638 <xsl:variable name='value'
639 select='translate(normalize-space(substring-after($metadata, "=")), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")'/>
642 <xsl:when test='$name = "scalefit"'>
643 <xsl:attribute name='scalefit'>
645 <xsl:when test='$value = "1" or
647 $value = "true"'>1</xsl:when>
648 <xsl:otherwise>0</xsl:otherwise>
652 <xsl:when test='$name = "align" or
653 $name = "contentdepth" or
654 $name = "contentwidth" or
659 <!-- TODO: check enumerate values-->
660 <xsl:attribute name='{$name}'>
661 <xsl:value-of select='$value'/>
665 <xsl:call-template name='rnd:error'>
666 <xsl:with-param name='code' select='"imagedata-unknown-attribute"'/>
667 <xsl:with-param name='message'>
668 <xsl:text>imagedata-metadata unknown attribute "</xsl:text>
669 <xsl:value-of select='$name'/>
670 <xsl:text>"</xsl:text>
679 <xsl:template match='dbk:emphasis'>
681 <xsl:when test='not(@rnd:style) and @role = "italic"'>
683 <xsl:apply-templates mode='rnd:copy'/>
686 <xsl:when test='not(@rnd:style) or @role'>
688 <xsl:call-template name='rnd:attributes'/>
689 <xsl:apply-templates mode='rnd:copy'/>
693 <xsl:when test='@rnd:style = preceding-sibling::node()[1][self::dbk:emphasis]/@rnd:style'/>
695 <xsl:when test='@rnd:style = "emphasis"'>
697 <xsl:call-template name='rnd:attributes'/>
698 <xsl:apply-templates mode='rnd:copy'/>
699 <xsl:apply-templates select='following-sibling::node()[1]'
700 mode='rnd:emphasis'/>
703 <xsl:when test='@rnd:style = "emphasis-bold" or
704 @rnd:style = "emphasis-strong"'>
706 <xsl:attribute name='role'>bold</xsl:attribute>
707 <xsl:call-template name='rnd:attributes'/>
708 <xsl:apply-templates mode='rnd:copy'/>
709 <xsl:apply-templates select='following-sibling::node()[1]'
710 mode='rnd:emphasis'/>
713 <xsl:when test='@rnd:style = "emphasis-underline"'>
715 <xsl:attribute name='role'>underline</xsl:attribute>
716 <xsl:call-template name='rnd:attributes'/>
717 <xsl:apply-templates mode='rnd:copy'/>
718 <xsl:apply-templates select='following-sibling::node()[1]'
719 mode='rnd:emphasis'/>
723 <xsl:when test='@rnd:style = "citetitle" or
724 @rnd:style = "literal" or
725 @rnd:style = "sgmltag"'>
726 <xsl:element name='{@rnd:style}'
727 namespace='http://docbook.org/ns/docbook'>
728 <xsl:call-template name='rnd:attributes'/>
729 <xsl:apply-templates/>
730 <xsl:apply-templates select='following-sibling::node()[1]'
731 mode='rnd:emphasis'/>
735 <xsl:when test='@rnd:style = "Hyperlink" and
737 <!-- This occurs in a hyperlink; parent should be dbk:link -->
738 <xsl:apply-templates/>
740 <xsl:when test='@rnd:style = "Hyperlink"'>
741 <!-- dbk:link is missing -->
742 <dbk:link xlink:href='{.}'>
743 <xsl:apply-templates/>
747 <!-- In rare circumstances, Word inserts an empty element that appears to be something like a space in the editor -->
748 <xsl:when test='(@rnd:style = "EndnoteReference" or
749 @rnd:style = "FootnoteReference") and
751 <xsl:text> </xsl:text>
755 <xsl:call-template name='rnd:error'>
756 <xsl:with-param name='code'>unknown-style</xsl:with-param>
757 <xsl:with-param name='message'>unknown character span style "<xsl:value-of select='@rnd:style'/>" encountered</xsl:with-param>
763 <!-- Coalesce emphasis elements into a single element -->
764 <xsl:template match='dbk:emphasis' mode='rnd:emphasis'>
766 <xsl:when test='@rnd:style = preceding-sibling::node()[self::dbk:emphasis]/@rnd:style'>
767 <xsl:apply-templates/>
768 <xsl:apply-templates select='following-sibling::node()[1]'
769 mode='rnd:emphasis'/>
773 <xsl:template match='*|text()' mode='rnd:emphasis'/>
775 <xsl:template match='dbk:emphasis' mode='rnd:personname-emphasis'>
776 <xsl:param name='style'/>
779 <xsl:when test='@rnd:style = $style'>
780 <xsl:apply-templates/>
781 <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
782 mode='rnd:personname-emphasis'>
783 <xsl:with-param name='style' select='$style'/>
784 </xsl:apply-templates>
788 <xsl:template match='*|text()' mode='rnd:emphasis'/>
790 <xsl:template match='dbk:subscript|dbk:superscript'>
792 <xsl:apply-templates select='@*' mode='rnd:copy'/>
793 <xsl:apply-templates/>
799 <xsl:template match='dbk:inlinemediaobject'>
801 <xsl:when test='not(preceding-sibling::*|following-sibling::*) and
802 normalize-space(..) = ""'>
804 <xsl:variable name='next.captioned'
805 select='ancestor::dbk:para/following-sibling::*[self::dbk:informaltable or self::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space() = ""]][1]'/>
807 <xsl:variable name='caption'
808 select='ancestor::dbk:para/following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'/>
810 <xsl:variable name='metadata'>
811 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[1]'
812 mode='rnd:metadata'/>
816 <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"] or
819 <xsl:if test='ancestor::dbk:para/preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"]'>
821 <xsl:apply-templates select='ancestor::dbk:para/preceding-sibling::*[1]/node()'/>
824 <xsl:copy-of select='$metadata'/>
829 <xsl:apply-templates mode='rnd:copy'/>
833 <xsl:when test='not($caption)'/>
834 <xsl:when test='not($next.captioned)'>
835 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
837 <xsl:apply-templates select='$caption'
840 <!-- Does caption belong to this image or next.captioned?
841 - Only if it belongs to this image do we process it here.
843 <xsl:when test='$next.captioned[preceding-sibling::*[generate-id() = generate-id($caption)]]'>
844 <xsl:apply-templates select='ancestor::dbk:para/following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]][not(&metadata-content;)]'
846 <xsl:apply-templates select='$caption'
849 <!-- otherwise caption does not belong to this figure -->
854 <xsl:call-template name='rnd:copy'/>
859 <xsl:template match='dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'
863 <xsl:apply-templates/>
867 <xsl:template match='*' mode='rnd:caption'/>
869 <xsl:template match='*' mode='rnd:figure'>
870 <xsl:call-template name='rnd:para'>
871 <xsl:with-param name='suppress' select='false()'/>
877 <xsl:template match='*' mode='rnd:sidebar'>
878 <xsl:call-template name='rnd:para'>
879 <xsl:with-param name='suppress' select='false()'/>
885 <xsl:template match='dbk:para' mode='rnd:listitem'>
888 <xsl:call-template name='rnd:attributes'/>
889 <xsl:apply-templates/>
891 <xsl:apply-templates select='following-sibling::*[1]'
892 mode='rnd:continue'/>
894 <!-- Handle nested lists -->
895 <xsl:variable name='list-type'
896 select='concat(substring-before(@rnd:style, "list"), "list")'/>
897 <xsl:variable name='list-level'
898 select='substring-after(@rnd:style, $list-type)'/>
900 <!-- Assuming only five levels of list nesting.
901 - This is probably better done in a previous stage using grouping.
903 <xsl:variable name='stop.node'
904 select='following-sibling::dbk:para[@rnd:style != concat("itemizedlist", $list-level + 1) and
905 @rnd:style != concat("orderedlist", $list-level + 1) and
906 @rnd:style != concat("itemizedlist", $list-level + 2) and
907 @rnd:style != concat("orderedlist", $list-level + 2) and
908 @rnd:style != concat("itemizedlist", $list-level + 3) and
909 @rnd:style != concat("orderedlist", $list-level + 3) and
910 @rnd:style != "para-continue"][1]'/>
912 <xsl:variable name='nested'
913 select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)][1]'/>
916 <!-- Is there a nested list at all? -->
917 <xsl:when test='following-sibling::*[self::dbk:para and @rnd:style != "para-continue"][1][@rnd:style != concat("itemizedlist", $list-level + 1) and @rnd:style != concat("orderedlist", $list-level + 1)]'/>
919 <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)] and
921 <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
922 namespace='http://docbook.org/ns/docbook'>
923 <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)][following-sibling::*[generate-id() = generate-id($stop.node)]]'
924 mode='rnd:listitem'/>
927 <xsl:when test='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)]'>
929 <xsl:element name='{concat(substring-before($nested/@rnd:style, "list"), "list")}'
930 namespace='http://docbook.org/ns/docbook'>
931 <xsl:apply-templates select='following-sibling::dbk:para[@rnd:style = concat("itemizedlist", $list-level + 1) or @rnd:style = concat("orderedlist", $list-level + 1)]'
932 mode='rnd:listitem'/>
941 <xsl:template match='dbk:para' mode='rnd:blockquote'>
943 <xsl:when test='@rnd:style ="blockquote-attribution"'/>
944 <xsl:when test='@rnd:style ="blockquote-title"'/>
947 <xsl:apply-templates/>
952 <xsl:template match='dbk:para' mode='rnd:blockquote-attribution'>
953 <xsl:if test='@rnd:style ="blockquote-attribution"'>
955 <xsl:apply-templates/>
962 <xsl:template match='dbk:para' mode='rnd:metadata'>
964 <xsl:when test='@rnd:style = "biblioentry-title" and
965 parent::dbk:bibliography|parent::dbk:bibliodiv'/>
966 <xsl:when test='@rnd:style = "biblioentry-title"'>
967 <xsl:call-template name='rnd:error'>
968 <xsl:with-param name='code'>bad-metadata</xsl:with-param>
969 <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>
973 <xsl:when test='@rnd:style = "abstract-title" or
974 @rnd:style = "abstract"'>
975 <xsl:variable name='stop.node'
976 select='following-sibling::dbk:para[@rnd:style != "abstract"][1]'/>
978 <xsl:when test='$stop.node'>
980 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "abstract"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
981 mode='rnd:abstract'/>
983 <xsl:apply-templates select='$stop.node'
984 mode='rnd:metadata'/>
988 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "abstract"]' mode='rnd:abstract'/>
994 <xsl:when test='@rnd:style = "legalnotice"'>
995 <xsl:variable name='stop.node'
996 select='following-sibling::dbk:para[@rnd:style != "legalnotice"][1]'/>
999 <xsl:when test='$stop.node'>
1001 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "legalnotice"][following-sibling::*[generate-id() = generate-id($stop.node)]]'
1002 mode='rnd:legalnotice'/>
1004 <xsl:apply-templates select='$stop.node'
1005 mode='rnd:metadata'/>
1008 <xsl:apply-templates select='.|following-sibling::dbk:para[@rnd:style = "legalnotice"]'
1009 mode='rnd:legalnotice'/>
1014 <xsl:when test='@rnd:style = "keyword"'>
1015 <xsl:variable name='stop.node'
1016 select='following-sibling::*[not(self::dbk:para) or
1017 (self::dbk:para and @rnd:style != "keyword")][1]'/>
1020 <xsl:when test='$stop.node'>
1022 <xsl:call-template name='rnd:keyword'>
1023 <xsl:with-param name='nodes'
1024 select='.|following-sibling::dbk:para[@rnd:style = "keyword"][following-sibling::*[generate-id() = generate-id($stop.node)]]'/>
1025 </xsl:call-template>
1027 <xsl:apply-templates select='$stop.node'
1028 mode='rnd:metadata'/>
1031 <xsl:call-template name='rnd:keyword'>
1032 <xsl:with-param name='nodes'
1033 select='.|following-sibling::dbk:para[@rnd:style = "keyword"]'/>
1034 </xsl:call-template>
1039 <xsl:when test='@rnd:style = "author"'>
1042 <xsl:when test='dbk:emphasis[@rnd:style = "orgname"]'>
1044 <xsl:apply-templates
1045 select='dbk:emphasis[@rnd:style = "orgname"]'
1046 mode='rnd:orgname'/>
1048 <xsl:if test='*[not(@rnd:style = "orgname")]'>
1049 <xsl:call-template name='rnd:error'>
1050 <xsl:with-param name='code'>bad-author-orgname-combo</xsl:with-param>
1051 <xsl:with-param name='message'>character span "<xsl:value-of select='dbk:emphasis[@rnd:style != "orgname"][1]/@rnd:style'/>" not allowed in an author paragraph combined with orgname</xsl:with-param>
1052 </xsl:call-template>
1057 <!-- TODO: check style of author; mixed content or structured -->
1058 <xsl:apply-templates mode='rnd:personname'/>
1062 <xsl:apply-templates mode='rnd:author-personblurb'/>
1063 <xsl:apply-templates select='following-sibling::*[1]'
1066 <xsl:call-template name='rnd:resume-metadata'>
1067 <xsl:with-param name='node' select='following-sibling::*[1]'/>
1068 </xsl:call-template>
1070 <xsl:when test='@rnd:style = "personblurb" or
1071 @rnd:style = "address" or
1072 @rnd:style = "affiliation" or
1073 @rnd:style = "contrib" or
1074 @rnd:style = "email"'/>
1076 <xsl:when test='@rnd:style = "releaseinfo" or
1077 @rnd:style = "date" or
1078 @rnd:style = "pubdate" or
1079 @rnd:style = "pagenums" or
1080 @rnd:style = "issuenum" or
1081 @rnd:style = "volumenum" or
1082 @rnd:style = "edition" or
1083 @rnd:style = "editor" or
1084 @rnd:style = "othercredit" or
1085 @rnd:style = "biblioid" or
1086 @rnd:style = "bibliosource" or
1087 @rnd:style = "bibliomisc" or
1088 @rnd:style = "revhistory" or
1089 @rnd:style = "revision"'>
1090 <xsl:element name='{@rnd:style}'
1091 namespace='http://docbook.org/ns/docbook'>
1092 <xsl:apply-templates mode='rnd:metadata'/>
1094 <xsl:apply-templates select='following-sibling::*[1]'
1095 mode='rnd:metadata'/>
1097 <xsl:when test='contains(@rnd:style, "-titleabbrev")'>
1098 <xsl:variable name='parent'
1099 select='substring-before(@rnd:style, "-titleabbrev")'/>
1102 <xsl:when test='$parent = local-name(..)'>
1104 <xsl:apply-templates mode='rnd:metadata'/>
1107 <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
1108 preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
1110 <xsl:apply-templates mode='rnd:metadata'/>
1114 <xsl:call-template name='rnd:error'>
1115 <xsl:with-param name='code'>bad-titleabbrev</xsl:with-param>
1116 <xsl:with-param name='message'>titleabbrev style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1117 </xsl:call-template>
1121 <xsl:apply-templates select='following-sibling::*[1]'
1122 mode='rnd:metadata'/>
1124 <xsl:when test='contains(@rnd:style, "-title")'>
1125 <xsl:variable name='parent'
1126 select='substring-before(@rnd:style, "-title")'/>
1129 <xsl:when test='$parent = "table" or
1130 $parent = "figure"'>
1132 <xsl:apply-templates mode='rnd:metadata'/>
1135 <xsl:when test='$parent = local-name(..)'>
1137 <xsl:apply-templates mode='rnd:metadata'/>
1140 <xsl:when test='parent::dbk:book-component'>
1142 <xsl:apply-templates mode='rnd:metadata'/>
1145 <xsl:when test='parent::dbk:article and
1148 <xsl:apply-templates mode='rnd:metadata'/>
1152 <xsl:call-template name='rnd:error'>
1153 <xsl:with-param name='code'>bad-title</xsl:with-param>
1154 <xsl:with-param name='message'>title style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1155 </xsl:call-template>
1159 <xsl:apply-templates select='following-sibling::*[1]'
1160 mode='rnd:metadata'/>
1163 <!-- Exception to normal subtitle handling is biblioentry-subtitle -->
1164 <xsl:when test='@rnd:style = "biblioentry-subtitle"'>
1165 <!-- TODO: check that this is in a biblioentry -->
1167 <xsl:apply-templates mode='rnd:metadata'/>
1170 <xsl:apply-templates select='following-sibling::*[1]'
1171 mode='rnd:metadata'/>
1173 <xsl:when test='contains(@rnd:style, "-subtitle")'>
1174 <xsl:variable name='parent'
1175 select='substring-before(@rnd:style, "-subtitle")'/>
1178 <xsl:when test='$parent = local-name(..)'>
1180 <xsl:apply-templates mode='rnd:metadata'/>
1183 <xsl:when test='(parent::dbk:article or parent::dbk:book-component) and
1184 preceding-sibling::dbk:para[@rnd:style = concat($parent, "-title")]'>
1186 <xsl:apply-templates mode='rnd:metadata'/>
1190 <xsl:call-template name='rnd:error'>
1191 <xsl:with-param name='code'>bad-subtitle</xsl:with-param>
1192 <xsl:with-param name='message'>subtitle style "<xsl:value-of select='@rnd:style'/>" mismatches parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
1193 </xsl:call-template>
1197 <xsl:apply-templates select='following-sibling::*[1]'
1198 mode='rnd:metadata'/>
1201 <xsl:when test='@rnd:style = "publisher-address" and
1202 preceding-sibling::*[1][not(self::dbk:para) or not(@rnd:style = "publisher")]'>
1203 <xsl:call-template name='rnd:error'>
1204 <xsl:with-param name='code'>bad-publisher-address</xsl:with-param>
1205 <xsl:with-param name='message'>publisher-address must follow publisher</xsl:with-param>
1206 </xsl:call-template>
1207 <xsl:apply-templates select='following-sibling::*[1]'
1208 mode='rnd:metadata'/>
1210 <xsl:when test='@rnd:style = "publisher-address"'>
1211 <xsl:apply-templates select='following-sibling::*[1]'
1212 mode='rnd:metadata'/>
1214 <xsl:when test='@rnd:style = "publisher"'>
1217 <xsl:apply-templates/>
1218 </dbk:publishername>
1219 <xsl:if test='following-sibling::*[1][@rnd:style = "publisher-address"]'>
1220 <xsl:apply-templates select='following-sibling::*[1]'
1221 mode='rnd:publisher'/>
1225 <xsl:apply-templates select='following-sibling::*[1]'
1226 mode='rnd:metadata'/>
1231 <xsl:template name='rnd:keyword'>
1232 <xsl:param name='nodes' select='/..'/>
1235 <xsl:when test='not($nodes)'/>
1237 <xsl:call-template name='rnd:keyword-phrases'>
1238 <xsl:with-param name='text' select='$nodes[1]'/>
1239 </xsl:call-template>
1240 <xsl:call-template name='rnd:keyword'>
1241 <xsl:with-param name='nodes' select='$nodes[position() != 1]'/>
1242 </xsl:call-template>
1246 <xsl:template name='rnd:keyword-phrases'>
1247 <xsl:param name='text'/>
1250 <xsl:when test='not($text)'/>
1251 <xsl:when test='contains($text, ",")'>
1253 <xsl:value-of select='normalize-space(substring-before($text, ","))'/>
1255 <xsl:call-template name='rnd:keyword-phrases'>
1256 <xsl:with-param name='text' select='substring-after($text, ",")'/>
1257 </xsl:call-template>
1261 <xsl:value-of select='normalize-space($text)'/>
1267 <xsl:template match='dbk:emphasis' mode='rnd:metadata'>
1269 <xsl:when test='not(@rnd:style)'>
1271 <xsl:apply-templates mode='rnd:metadata'/>
1274 <xsl:when test='@rnd:style = "Hyperlink" and
1276 <xsl:apply-templates mode='rnd:metadata'/>
1278 <xsl:when test='@rnd:style = "Hyperlink"'>
1279 <dbk:link xlink:href='{.}'>
1280 <xsl:apply-templates mode='rnd:metadata'/>
1284 <xsl:element name='{@rnd:style}'
1285 namespace='http://docbook.org/ns/docbook'>
1286 <xsl:apply-templates mode='rnd:metadata'/>
1291 <xsl:template match='dbk:link' mode='rnd:metadata'>
1293 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1294 <xsl:apply-templates mode='rnd:metadata'/>
1297 <xsl:template match='dbk:inlinemediaobject' mode='rnd:metadata'>
1298 <xsl:call-template name='rnd:copy'/>
1300 <xsl:template match='*' mode='rnd:metadata'/>
1302 <xsl:template name='rnd:resume-metadata'>
1303 <xsl:param name='node' select='/..'/>
1306 <xsl:when test='$node[self::dbk:para][&author-content;]'>
1307 <xsl:call-template name='rnd:resume-metadata'>
1308 <xsl:with-param name='node' select='$node/following-sibling::*[1]'/>
1309 </xsl:call-template>
1311 <xsl:when test='$node[self::dbk:para][&metadata-content;]'>
1312 <xsl:apply-templates select='$node' mode='rnd:metadata'/>
1317 <xsl:template match='dbk:para' mode='rnd:abstract'>
1319 <xsl:when test='@rnd:style = "abstract-title"'>
1321 <xsl:call-template name='rnd:attributes'/>
1322 <xsl:apply-templates/>
1327 <xsl:call-template name='rnd:attributes'/>
1328 <xsl:apply-templates/>
1334 <xsl:template match='dbk:para' mode='rnd:legalnotice'>
1336 <xsl:call-template name='rnd:attributes'/>
1337 <xsl:apply-templates/>
1341 <xsl:template match='dbk:footnote' mode='rnd:personname'/>
1342 <xsl:template match='dbk:emphasis' mode='rnd:personname'>
1343 <!-- Need to check preceding emphasis for same style,
1344 but blocks pretty-prints and all text nodes
1345 are preserved in paragraph content.
1347 <xsl:variable name='previous'
1348 select='preceding-sibling::node()[not(self::text()) or (self::text() and normalize-space() != "")]'/>
1350 <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>
1353 <!-- inlines are coalesced -->
1354 <xsl:when test='@rnd:style = $previous[last()][self::dbk:emphasis]/@rnd:style'/>
1355 <xsl:when test='@rnd:style = "honorific" or
1356 @rnd:style = "firstname" or
1357 @rnd:style = "lineage" or
1358 @rnd:style = "othername" or
1359 @rnd:style = "surname"'>
1360 <xsl:element name='{@rnd:style}'
1361 namespace='http://docbook.org/ns/docbook'>
1362 <xsl:apply-templates/>
1363 <xsl:apply-templates select='following-sibling::dbk:emphasis[1]'
1364 mode='rnd:personname-emphasis'>
1365 <xsl:with-param name='style' select='@rnd:style'/>
1366 </xsl:apply-templates>
1370 <xsl:call-template name='rnd:error'>
1371 <xsl:with-param name='code'>bad-author-inline</xsl:with-param>
1372 <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in an author paragraph</xsl:with-param>
1373 </xsl:call-template>
1378 <xsl:template match='text()' mode='rnd:author-personblurb'/>
1379 <xsl:template match='dbk:emphasis' mode='rnd:author-personblurb'/>
1380 <xsl:template match='dbk:footnote' mode='rnd:author-personblurb'>
1384 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1385 <xsl:apply-templates/>
1391 <xsl:template match='dbk:para' mode='rnd:author'>
1393 <xsl:when test='@rnd:style = "personblurb" and
1394 preceding-sibling::*[1][self::dbk:para and @rnd:style != "personblurb"]'>
1396 <xsl:apply-templates select='.'
1397 mode='rnd:personblurb'/>
1400 <xsl:when test='@rnd:style = "personblurb"'>
1401 <xsl:apply-templates select='following-sibling::*[1]'
1405 <!-- Web and mail addresses may appear in a simplified form -->
1406 <xsl:when test='@rnd:style = "address"'>
1408 <xsl:when test='dbk:link and
1409 count(dbk:link) = count(*)'>
1410 <!-- simplified form -->
1412 <xsl:apply-templates select='dbk:link'
1413 mode='rnd:otheraddr'/>
1418 <xsl:apply-templates mode='rnd:author'/>
1420 <xsl:apply-templates select='following-sibling::*[1]'
1426 <xsl:when test='@rnd:style = "affiliation"'>
1429 <xsl:when test='not(*)'>
1431 <xsl:apply-templates mode='rnd:author'/>
1435 <xsl:apply-templates mode='rnd:author'/>
1439 <xsl:apply-templates select='following-sibling::*[1]'
1442 <xsl:when test='@rnd:style = "contrib" or
1443 @rnd:style = "email"'>
1444 <xsl:element name='{@rnd:style}'
1445 namespace='http://docbook.org/ns/docbook'>
1446 <xsl:apply-templates mode='rnd:author'/>
1448 <xsl:apply-templates select='following-sibling::*[1]'
1454 <xsl:template match='dbk:link' mode='rnd:otheraddr'>
1456 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1457 <xsl:apply-templates mode='rnd:otheraddr'/>
1461 <!-- TODO: not all of these inlines are allowed in all elements that are children of author.
1462 Need to further refine validation of inlines.
1464 <xsl:template match='dbk:emphasis' mode='rnd:author'>
1466 <xsl:when test='@rnd:style = "city" or
1467 @rnd:style = "country" or
1468 @rnd:style = "email" or
1469 @rnd:style = "fax" or
1470 @rnd:style = "jobtitle" or
1471 @rnd:style = "orgdiv" or
1472 @rnd:style = "orgname" or
1473 @rnd:style = "otheraddr" or
1474 @rnd:style = "phone" or
1475 @rnd:style = "pob" or
1476 @rnd:style = "postcode" or
1477 @rnd:style = "shortaffil" or
1478 @rnd:style = "state" or
1479 @rnd:style = "street"'>
1480 <xsl:element name='{@rnd:style}'
1481 namespace='http://docbook.org/ns/docbook'>
1482 <xsl:apply-templates/>
1486 <xsl:call-template name='rnd:error'>
1487 <xsl:with-param name='code'>metadata-bad-inline</xsl:with-param>
1488 <xsl:with-param name='message'>character span "<xsl:value-of select='@rnd:style'/>" not allowed in author metadata</xsl:with-param>
1489 </xsl:call-template>
1494 <xsl:template match='dbk:para' mode='rnd:personblurb'>
1495 <xsl:if test='@rnd:style = "personblurb"'>
1497 <xsl:apply-templates/>
1499 <xsl:apply-templates select='following-sibling::*[1]'
1500 mode='rnd:personblurb'/>
1504 <xsl:template match='dbk:para' mode='rnd:publisher'>
1505 <xsl:if test='@rnd:style = "publisher-address"'>
1507 <xsl:apply-templates/>
1512 <xsl:template match='dbk:para' mode='rnd:programlisting'>
1513 <xsl:text>
</xsl:text>
1514 <xsl:apply-templates/>
1517 <!-- Continuing paragraphs -->
1519 <xsl:template match='*' mode='rnd:continue'/>
1520 <xsl:template match='dbk:para' mode='rnd:continue'>
1521 <xsl:if test='@rnd:style = "para-continue"'>
1523 <xsl:call-template name='rnd:attributes'/>
1524 <xsl:apply-templates/>
1526 <xsl:apply-templates select='following-sibling::*[1]'
1527 mode='rnd:continue'/>
1530 <xsl:template match='dbk:informaltable' mode='rnd:continue'>
1531 <xsl:apply-templates select='.'>
1532 <xsl:with-param name='in-list' select='true()'/>
1533 </xsl:apply-templates>
1534 <xsl:apply-templates select='following-sibling::*[1]'
1535 mode='rnd:continue'/>
1540 <xsl:template match='dbk:informaltable'>
1541 <xsl:param name='in-list' select='false()'/>
1544 <xsl:when test='not($in-list) and
1545 preceding-sibling::dbk:para[1][starts-with(@rnd:style, "itemizedlist") or starts-with(@rnd:style, "orderedlist") or @rnd:style = "para-continue"]'/>
1546 <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style ="table-title"]'>
1548 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1551 <xsl:apply-templates select='preceding-sibling::dbk:para[1]'
1552 mode='rnd:table-title'/>
1555 <xsl:call-template name='rnd:table-textobject'/>
1557 <xsl:apply-templates/>
1559 <xsl:call-template name='rnd:table-caption'/>
1564 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1566 <xsl:call-template name='rnd:table-textobject'/>
1568 <xsl:apply-templates/>
1570 <xsl:call-template name='rnd:table-caption'/>
1575 <xsl:template match='dbk:tgroup'>
1577 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1578 <xsl:if test='not(@cols)'>
1579 <xsl:attribute name='cols'>
1580 <xsl:call-template name='dbk:max-columns'>
1581 <xsl:with-param name='rows' select='*/dbk:row'/>
1582 </xsl:call-template>
1585 <xsl:apply-templates/>
1588 <xsl:template name='dbk:max-columns'>
1589 <xsl:param name='rows' select='/..'/>
1590 <xsl:param name='max' select='0'/>
1592 <!-- This is a tail-recursive algorithm.
1593 Could improve this with other algorithm(s),
1594 eg. divide-and-conquer.
1598 <xsl:when test='not($rows)'>
1599 <xsl:value-of select='$max'/>
1601 <xsl:when test='count($rows[1]/dbk:entry) > $max'>
1602 <xsl:call-template name='dbk:max-columns'>
1603 <xsl:with-param name='rows' select='$rows[position() != 1]'/>
1604 <xsl:with-param name='max' select='count($rows[1]/dbk:entry)'/>
1605 </xsl:call-template>
1608 <xsl:call-template name='dbk:max-columns'>
1609 <xsl:with-param name='rows' select='$rows[position() != 1]'/>
1610 <xsl:with-param name='max' select='$max'/>
1611 </xsl:call-template>
1615 <xsl:template match='dbk:tbody|dbk:thead|dbk:tfoot|dbk:row|dbk:colspec'>
1617 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1618 <xsl:apply-templates/>
1621 <xsl:template match='dbk:entry'>
1623 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1624 <xsl:apply-templates/>
1628 <xsl:template match='dbk:para' mode='rnd:table-title'>
1630 <xsl:apply-templates/>
1634 <!-- Find the caption associated with this table -->
1635 <xsl:template name='rnd:table-caption'>
1636 <xsl:variable name='candidate'
1637 select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
1639 <xsl:if test='$candidate != "" and
1640 generate-id($candidate/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
1643 <xsl:apply-templates select='$candidate/node()'/>
1649 <!-- Find table associated text -->
1650 <xsl:template name='rnd:table-textobject'>
1651 <xsl:variable name='caption'
1652 select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
1654 <xsl:if test='generate-id($caption/preceding-sibling::dbk:informaltable[1]) = generate-id(.)'>
1655 <xsl:variable name='content'
1656 select='following-sibling::*[following-sibling::*[generate-id($caption) = generate-id()]]'/>
1657 <xsl:if test='$content'>
1659 <xsl:apply-templates select='$content' mode='rnd:textobject'/>
1664 <xsl:template match='dbk:para' mode='rnd:textobject'>
1665 <xsl:call-template name='rnd:para'>
1666 <xsl:with-param name='suppress' select='false()'/>
1667 </xsl:call-template>
1671 <xsl:template match='dbk:footnote'>
1673 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1674 <xsl:apply-templates/>
1680 <!-- rnd:attributes reconstitutes an element's attributes -->
1681 <xsl:template name='rnd:attributes'>
1682 <xsl:param name='node' select='.'/>
1684 <xsl:apply-templates select='$node/@*[namespace-uri() != "http://docbook.org/ns/docbook/roundtrip"]' mode='rnd:copy'/>
1687 <xsl:template match='*' name='rnd:copy' mode='rnd:copy'>
1689 <xsl:apply-templates select='@*' mode='rnd:copy'/>
1690 <xsl:apply-templates mode='rnd:copy'/>
1693 <xsl:template match='@*' mode='rnd:copy'>
1697 <!-- These templates are invoked whenever an error condition is detected in the conversion of a document.
1699 <xsl:template name='rnd:error'>
1700 <xsl:param name='node' select='.'/>
1701 <xsl:param name='code'/>
1702 <xsl:param name='message'/>
1704 <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
1705 <xsl:message>ERROR "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
1708 <xsl:value-of select='$code'/>
1711 <xsl:value-of select='$message'/>
1715 <xsl:template name='rnd:warning'>
1716 <xsl:param name='node' select='.'/>
1717 <xsl:param name='code'/>
1718 <xsl:param name='message'/>
1720 <xsl:comment><xsl:value-of select='$message'/></xsl:comment>
1721 <xsl:message>WARNING "<xsl:value-of select='$code'/>": <xsl:value-of select='$message'/></xsl:message>
1724 <xsl:value-of select='$code'/>
1727 <xsl:value-of select='$message'/>