docbook.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  108. toss the namespace and continue. Use the docbook5 namespaced
  109. stylesheets for DocBook5 if you don't want to use this feature.-->
  110. <!-- include extra test for Xalan quirk -->
  111. <xsl:when test="(function-available('exsl:node-set') or
  112. contains(system-property('xsl:vendor'),
  113. 'Apache Software Foundation'))
  114. and (*/self::ng:* or */self::db:*)">
  115. <xsl:message>Stripping namespace from DocBook 5 document.</xsl:message>
  116. <xsl:variable name="nons">
  117. <xsl:apply-templates mode="stripNS"/>
  118. </xsl:variable>
  119. <xsl:apply-templates select="exsl:node-set($nons)"/>
  120. </xsl:when>
  121. <!-- Can't process unless namespace removed -->
  122. <xsl:when test="*/self::ng:* or */self::db:*">
  123. <xsl:message terminate="yes">
  124. <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
  125. <xsl:text> cannot proceed.</xsl:text>
  126. </xsl:message>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xsl:choose>
  130. <xsl:when test="$rootid != ''">
  131. <xsl:variable name="root.element" select="key('id', $rootid)"/>
  132. <xsl:choose>
  133. <xsl:when test="count($root.element) = 0">
  134. <xsl:message terminate="yes">
  135. <xsl:text>ID '</xsl:text>
  136. <xsl:value-of select="$rootid"/>
  137. <xsl:text>' not found in document.</xsl:text>
  138. </xsl:message>
  139. </xsl:when>
  140. <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
  141. <xsl:message terminate="yes">
  142. <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
  143. <xsl:value-of select="$rootid"/>
  144. <xsl:text>) for FO output </xsl:text>
  145. <xsl:text>must be one of the following elements:</xsl:text>
  146. <xsl:value-of select="$root.elements"/>
  147. </xsl:message>
  148. </xsl:when>
  149. <!-- Otherwise proceed -->
  150. <xsl:otherwise>
  151. <xsl:if test="$collect.xref.targets = 'yes' or
  152. $collect.xref.targets = 'only'">
  153. <xsl:apply-templates select="$root.element"
  154. mode="collect.targets"/>
  155. </xsl:if>
  156. <xsl:if test="$collect.xref.targets != 'only'">
  157. <xsl:apply-templates select="$root.element"
  158. mode="process.root"/>
  159. </xsl:if>
  160. </xsl:otherwise>
  161. </xsl:choose>
  162. </xsl:when>
  163. <!-- Otherwise process the document root element -->
  164. <xsl:otherwise>
  165. <xsl:variable name="document.element" select="*[1]"/>
  166. <xsl:choose>
  167. <xsl:when test="not(contains($root.elements,
  168. concat(' ', local-name($document.element), ' ')))">
  169. <xsl:message terminate="yes">
  170. <xsl:text>ERROR: Document root element for FO output </xsl:text>
  171. <xsl:text>must be one of the following elements:</xsl:text>
  172. <xsl:value-of select="$root.elements"/>
  173. </xsl:message>
  174. </xsl:when>
  175. <!-- Otherwise proceed -->
  176. <xsl:otherwise>
  177. <xsl:if test="$collect.xref.targets = 'yes' or
  178. $collect.xref.targets = 'only'">
  179. <xsl:apply-templates select="/"
  180. mode="collect.targets"/>
  181. </xsl:if>
  182. <xsl:if test="$collect.xref.targets != 'only'">
  183. <xsl:apply-templates select="/"
  184. mode="process.root"/>
  185. </xsl:if>
  186. </xsl:otherwise>
  187. </xsl:choose>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:template>
  193. <xsl:template match="*" mode="process.root">
  194. <xsl:variable name="document.element" select="self::*"/>
  195. <xsl:call-template name="root.messages"/>
  196. <xsl:variable name="title">
  197. <xsl:choose>
  198. <xsl:when test="$document.element/title[1]">
  199. <xsl:value-of select="$document.element/title[1]"/>
  200. </xsl:when>
  201. <xsl:otherwise>[could not find document title]</xsl:otherwise>
  202. </xsl:choose>
  203. </xsl:variable>
  204. <!-- Include all id values in XEP output -->
  205. <xsl:if test="$xep.extensions != 0">
  206. <xsl:processing-instruction
  207. name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
  208. </xsl:if>
  209. <fo:root xsl:use-attribute-sets="root.properties">
  210. <xsl:attribute name="language">
  211. <xsl:call-template name="l10n.language">
  212. <xsl:with-param name="target" select="/*[1]"/>
  213. </xsl:call-template>
  214. </xsl:attribute>
  215. <xsl:if test="$xep.extensions != 0">
  216. <xsl:call-template name="xep-pis"/>
  217. <xsl:call-template name="xep-document-information"/>
  218. </xsl:if>
  219. <xsl:if test="$axf.extensions != 0">
  220. <xsl:call-template name="axf-document-information"/>
  221. </xsl:if>
  222. <xsl:call-template name="setup.pagemasters"/>
  223. <xsl:if test="$fop.extensions != 0">
  224. <xsl:apply-templates select="$document.element" mode="fop.outline"/>
  225. </xsl:if>
  226. <xsl:if test="$fop1.extensions != 0">
  227. <xsl:variable name="bookmarks">
  228. <xsl:apply-templates select="$document.element"
  229. mode="fop1.outline"/>
  230. </xsl:variable>
  231. <xsl:if test="string($bookmarks) != ''">
  232. <fo:bookmark-tree>
  233. <xsl:copy-of select="$bookmarks"/>
  234. </fo:bookmark-tree>
  235. </xsl:if>
  236. </xsl:if>
  237. <xsl:if test="$xep.extensions != 0">
  238. <xsl:variable name="bookmarks">
  239. <xsl:apply-templates select="$document.element" mode="xep.outline"/>
  240. </xsl:variable>
  241. <xsl:if test="string($bookmarks) != ''">
  242. <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
  243. <xsl:copy-of select="$bookmarks"/>
  244. </rx:outline>
  245. </xsl:if>
  246. </xsl:if>
  247. <xsl:if test="$arbortext.extensions != 0 and $ati.xsl11.bookmarks != 0">
  248. <xsl:variable name="bookmarks">
  249. <xsl:apply-templates select="$document.element"
  250. mode="ati.xsl11.bookmarks"/>
  251. </xsl:variable>
  252. <xsl:if test="string($bookmarks) != ''">
  253. <fo:bookmark-tree>
  254. <xsl:copy-of select="$bookmarks"/>
  255. </fo:bookmark-tree>
  256. </xsl:if>
  257. </xsl:if>
  258. <xsl:apply-templates select="$document.element"/>
  259. </fo:root>
  260. </xsl:template>
  261. <xsl:template name="root.messages">
  262. <!-- redefine this any way you'd like to output messages -->
  263. <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
  264. <xsl:message>
  265. <xsl:text>Making </xsl:text>
  266. <xsl:value-of select="$page.orientation"/>
  267. <xsl:text> pages on </xsl:text>
  268. <xsl:value-of select="$paper.type"/>
  269. <xsl:text> paper (</xsl:text>
  270. <xsl:value-of select="$page.width"/>
  271. <xsl:text>x</xsl:text>
  272. <xsl:value-of select="$page.height"/>
  273. <xsl:text>)</xsl:text>
  274. </xsl:message>
  275. </xsl:template>
  276. <!-- ==================================================================== -->
  277. </xsl:stylesheet>