docbook.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:exsl="http://exslt.org/common"
  4. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  5. xmlns:ng="http://docbook.org/docbook-ng"
  6. xmlns:db="http://docbook.org/ns/docbook"
  7. exclude-result-prefixes="db ng exsl"
  8. version='1.0'>
  9. <!-- It is important to use indent="no" here, otherwise verbatim -->
  10. <!-- environments get broken by indented tags...at least when the -->
  11. <!-- callout extension is used...at least with some processors -->
  12. <xsl:output method="xml" indent="no"/>
  13. <!-- ********************************************************************
  14. $Id$
  15. ********************************************************************
  16. This file is part of the XSL DocBook Stylesheet distribution.
  17. See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  18. and other information.
  19. ******************************************************************** -->
  20. <!-- ==================================================================== -->
  21. <xsl:include href="../VERSION"/>
  22. <xsl:include href="param.xsl"/>
  23. <xsl:include href="../lib/lib.xsl"/>
  24. <xsl:include href="../common/l10n.xsl"/>
  25. <xsl:include href="../common/common.xsl"/>
  26. <xsl:include href="../common/labels.xsl"/>
  27. <xsl:include href="../common/titles.xsl"/>
  28. <xsl:include href="../common/subtitles.xsl"/>
  29. <xsl:include href="../common/gentext.xsl"/>
  30. <xsl:include href="../common/olink.xsl"/>
  31. <xsl:include href="../common/targets.xsl"/>
  32. <xsl:include href="../common/pi.xsl"/>
  33. <xsl:include href="autotoc.xsl"/>
  34. <xsl:include href="autoidx.xsl"/>
  35. <xsl:include href="lists.xsl"/>
  36. <xsl:include href="callout.xsl"/>
  37. <xsl:include href="verbatim.xsl"/>
  38. <xsl:include href="graphics.xsl"/>
  39. <xsl:include href="xref.xsl"/>
  40. <xsl:include href="formal.xsl"/>
  41. <xsl:include href="table.xsl"/>
  42. <xsl:include href="htmltbl.xsl"/>
  43. <xsl:include href="sections.xsl"/>
  44. <xsl:include href="inline.xsl"/>
  45. <xsl:include href="footnote.xsl"/>
  46. <xsl:include href="fo.xsl"/>
  47. <xsl:include href="fo-rtf.xsl"/>
  48. <xsl:include href="info.xsl"/>
  49. <xsl:include href="keywords.xsl"/>
  50. <xsl:include href="division.xsl"/>
  51. <xsl:include href="index.xsl"/>
  52. <xsl:include href="toc.xsl"/>
  53. <xsl:include href="refentry.xsl"/>
  54. <xsl:include href="math.xsl"/>
  55. <xsl:include href="admon.xsl"/>
  56. <xsl:include href="component.xsl"/>
  57. <xsl:include href="biblio.xsl"/>
  58. <xsl:include href="biblio-iso690.xsl"/>
  59. <xsl:include href="glossary.xsl"/>
  60. <xsl:include href="block.xsl"/>
  61. <xsl:include href="task.xsl"/>
  62. <xsl:include href="qandaset.xsl"/>
  63. <xsl:include href="synop.xsl"/>
  64. <xsl:include href="titlepage.xsl"/>
  65. <xsl:include href="titlepage.templates.xsl"/>
  66. <xsl:include href="pagesetup.xsl"/>
  67. <xsl:include href="pi.xsl"/>
  68. <xsl:include href="spaces.xsl"/>
  69. <xsl:include href="ebnf.xsl"/>
  70. <xsl:include href="../html/chunker.xsl"/>
  71. <xsl:include href="annotations.xsl"/>
  72. <xsl:include href="../common/stripns.xsl"/>
  73. <xsl:include href="fop.xsl"/>
  74. <xsl:include href="fop1.xsl"/>
  75. <xsl:include href="passivetex.xsl"/>
  76. <xsl:include href="xep.xsl"/>
  77. <xsl:include href="axf.xsl"/>
  78. <xsl:include href="ptc.xsl"/>
  79. <xsl:param name="stylesheet.result.type" select="'fo'"/>
  80. <!-- ==================================================================== -->
  81. <xsl:key name="id" match="*" use="@id|@xml:id"/>
  82. <!-- ==================================================================== -->
  83. <xsl:template match="*">
  84. <xsl:message>
  85. <xsl:value-of select="name(.)"/>
  86. <xsl:text> encountered</xsl:text>
  87. <xsl:if test="parent::*">
  88. <xsl:text> in </xsl:text>
  89. <xsl:value-of select="name(parent::*)"/>
  90. </xsl:if>
  91. <xsl:text>, but no template matches.</xsl:text>
  92. </xsl:message>
  93. <fo:block color="red">
  94. <xsl:text>&lt;</xsl:text>
  95. <xsl:value-of select="name(.)"/>
  96. <xsl:text>&gt;</xsl:text>
  97. <xsl:apply-templates/>
  98. <xsl:text>&lt;/</xsl:text>
  99. <xsl:value-of select="name(.)"/>
  100. <xsl:text>&gt;</xsl:text>
  101. </fo:block>
  102. </xsl:template>
  103. <!-- Update this list if new root elements supported -->
  104. <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
  105. <xsl:template match="/">
  106. <xsl:choose>
  107. <!-- include extra test for Xalan quirk -->
  108. <xsl:when test="(function-available('exsl:node-set') or
  109. contains(system-property('xsl:vendor'),
  110. 'Apache Software Foundation'))
  111. and (*/self::ng:* or */self::db:*)">
  112. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  113. toss the namespace and continue. Someday we'll reverse this logic
  114. and add the namespace to documents that don't have one.
  115. But not before the whole stylesheet has been converted to use
  116. namespaces. i.e., don't hold your breath -->
  117. <xsl:message>Stripping namespace from DocBook 5 document.</xsl:message>
  118. <xsl:variable name="nons">
  119. <xsl:apply-templates mode="stripNS"/>
  120. </xsl:variable>
  121. <xsl:apply-templates select="exsl:node-set($nons)"/>
  122. </xsl:when>
  123. <!-- Can't process unless namespace removed -->
  124. <xsl:when test="*/self::ng:* or */self::db:*">
  125. <xsl:message terminate="yes">
  126. <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
  127. <xsl:text> cannot proceed.</xsl:text>
  128. </xsl:message>
  129. </xsl:when>
  130. <xsl:otherwise>
  131. <xsl:choose>
  132. <xsl:when test="$rootid != ''">
  133. <xsl:variable name="root.element" select="key('id', $rootid)"/>
  134. <xsl:choose>
  135. <xsl:when test="count($root.element) = 0">
  136. <xsl:message terminate="yes">
  137. <xsl:text>ID '</xsl:text>
  138. <xsl:value-of select="$rootid"/>
  139. <xsl:text>' not found in document.</xsl:text>
  140. </xsl:message>
  141. </xsl:when>
  142. <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
  143. <xsl:message terminate="yes">
  144. <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
  145. <xsl:value-of select="$rootid"/>
  146. <xsl:text>) for FO output </xsl:text>
  147. <xsl:text>must be one of the following elements:</xsl:text>
  148. <xsl:value-of select="$root.elements"/>
  149. </xsl:message>
  150. </xsl:when>
  151. <!-- Otherwise proceed -->
  152. <xsl:otherwise>
  153. <xsl:if test="$collect.xref.targets = 'yes' or
  154. $collect.xref.targets = 'only'">
  155. <xsl:apply-templates select="$root.element"
  156. mode="collect.targets"/>
  157. </xsl:if>
  158. <xsl:if test="$collect.xref.targets != 'only'">
  159. <xsl:apply-templates select="$root.element"
  160. mode="process.root"/>
  161. </xsl:if>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </xsl:when>
  165. <!-- Otherwise process the document root element -->
  166. <xsl:otherwise>
  167. <xsl:variable name="document.element" select="*[1]"/>
  168. <xsl:choose>
  169. <xsl:when test="not(contains($root.elements,
  170. concat(' ', local-name($document.element), ' ')))">
  171. <xsl:message terminate="yes">
  172. <xsl:text>ERROR: Document root element for FO output </xsl:text>
  173. <xsl:text>must be one of the following elements:</xsl:text>
  174. <xsl:value-of select="$root.elements"/>
  175. </xsl:message>
  176. </xsl:when>
  177. <!-- Otherwise proceed -->
  178. <xsl:otherwise>
  179. <xsl:if test="$collect.xref.targets = 'yes' or
  180. $collect.xref.targets = 'only'">
  181. <xsl:apply-templates select="/"
  182. mode="collect.targets"/>
  183. </xsl:if>
  184. <xsl:if test="$collect.xref.targets != 'only'">
  185. <xsl:apply-templates select="/"
  186. mode="process.root"/>
  187. </xsl:if>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:otherwise>
  193. </xsl:choose>
  194. </xsl:template>
  195. <xsl:template match="*" mode="process.root">
  196. <xsl:variable name="document.element" select="self::*"/>
  197. <xsl:call-template name="root.messages"/>
  198. <xsl:variable name="title">
  199. <xsl:choose>
  200. <xsl:when test="$document.element/title[1]">
  201. <xsl:value-of select="$document.element/title[1]"/>
  202. </xsl:when>
  203. <xsl:otherwise>[could not find document title]</xsl:otherwise>
  204. </xsl:choose>
  205. </xsl:variable>
  206. <!-- Include all id values in XEP output -->
  207. <xsl:if test="$xep.extensions != 0">
  208. <xsl:processing-instruction
  209. name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
  210. </xsl:if>
  211. <fo:root xsl:use-attribute-sets="root.properties">
  212. <xsl:attribute name="language">
  213. <xsl:call-template name="l10n.language">
  214. <xsl:with-param name="target" select="/*[1]"/>
  215. </xsl:call-template>
  216. </xsl:attribute>
  217. <xsl:if test="$xep.extensions != 0">
  218. <xsl:call-template name="xep-pis"/>
  219. <xsl:call-template name="xep-document-information"/>
  220. </xsl:if>
  221. <xsl:if test="$axf.extensions != 0">
  222. <xsl:call-template name="axf-document-information"/>
  223. </xsl:if>
  224. <xsl:call-template name="setup.pagemasters"/>
  225. <xsl:if test="$fop.extensions != 0">
  226. <xsl:apply-templates select="$document.element" mode="fop.outline"/>
  227. </xsl:if>
  228. <xsl:if test="$fop1.extensions != 0">
  229. <xsl:variable name="bookmarks">
  230. <xsl:apply-templates select="$document.element"
  231. mode="fop1.outline"/>
  232. </xsl:variable>
  233. <xsl:if test="string($bookmarks) != ''">
  234. <fo:bookmark-tree>
  235. <xsl:copy-of select="$bookmarks"/>
  236. </fo:bookmark-tree>
  237. </xsl:if>
  238. </xsl:if>
  239. <xsl:if test="$xep.extensions != 0">
  240. <xsl:variable name="bookmarks">
  241. <xsl:apply-templates select="$document.element" mode="xep.outline"/>
  242. </xsl:variable>
  243. <xsl:if test="string($bookmarks) != ''">
  244. <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
  245. <xsl:copy-of select="$bookmarks"/>
  246. </rx:outline>
  247. </xsl:if>
  248. </xsl:if>
  249. <xsl:if test="$arbortext.extensions != 0 and $ati.xsl11.bookmarks != 0">
  250. <xsl:variable name="bookmarks">
  251. <xsl:apply-templates select="$document.element"
  252. mode="ati.xsl11.bookmarks"/>
  253. </xsl:variable>
  254. <xsl:if test="string($bookmarks) != ''">
  255. <fo:bookmark-tree>
  256. <xsl:copy-of select="$bookmarks"/>
  257. </fo:bookmark-tree>
  258. </xsl:if>
  259. </xsl:if>
  260. <xsl:apply-templates select="$document.element"/>
  261. </fo:root>
  262. </xsl:template>
  263. <xsl:template name="root.messages">
  264. <!-- redefine this any way you'd like to output messages -->
  265. <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
  266. <xsl:message>
  267. <xsl:text>Making </xsl:text>
  268. <xsl:value-of select="$page.orientation"/>
  269. <xsl:text> pages on </xsl:text>
  270. <xsl:value-of select="$paper.type"/>
  271. <xsl:text> paper (</xsl:text>
  272. <xsl:value-of select="$page.width"/>
  273. <xsl:text>x</xsl:text>
  274. <xsl:value-of select="$page.height"/>
  275. <xsl:text>)</xsl:text>
  276. </xsl:message>
  277. </xsl:template>
  278. <!-- ==================================================================== -->
  279. </xsl:stylesheet>