docbook.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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://docbook.sf.net/release/xsl/current/ for
  18. copyright 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/utility.xsl"/>
  27. <xsl:include href="../common/labels.xsl"/>
  28. <xsl:include href="../common/titles.xsl"/>
  29. <xsl:include href="../common/subtitles.xsl"/>
  30. <xsl:include href="../common/gentext.xsl"/>
  31. <xsl:include href="../common/olink.xsl"/>
  32. <xsl:include href="../common/targets.xsl"/>
  33. <xsl:include href="../common/pi.xsl"/>
  34. <xsl:include href="autotoc.xsl"/>
  35. <xsl:include href="autoidx.xsl"/>
  36. <xsl:include href="lists.xsl"/>
  37. <xsl:include href="callout.xsl"/>
  38. <xsl:include href="verbatim.xsl"/>
  39. <xsl:include href="graphics.xsl"/>
  40. <xsl:include href="xref.xsl"/>
  41. <xsl:include href="formal.xsl"/>
  42. <xsl:include href="table.xsl"/>
  43. <xsl:include href="htmltbl.xsl"/>
  44. <xsl:include href="sections.xsl"/>
  45. <xsl:include href="inline.xsl"/>
  46. <xsl:include href="footnote.xsl"/>
  47. <xsl:include href="fo.xsl"/>
  48. <xsl:include href="fo-rtf.xsl"/>
  49. <xsl:include href="info.xsl"/>
  50. <xsl:include href="keywords.xsl"/>
  51. <xsl:include href="division.xsl"/>
  52. <xsl:include href="index.xsl"/>
  53. <xsl:include href="toc.xsl"/>
  54. <xsl:include href="refentry.xsl"/>
  55. <xsl:include href="math.xsl"/>
  56. <xsl:include href="admon.xsl"/>
  57. <xsl:include href="component.xsl"/>
  58. <xsl:include href="biblio.xsl"/>
  59. <xsl:include href="biblio-iso690.xsl"/>
  60. <xsl:include href="glossary.xsl"/>
  61. <xsl:include href="block.xsl"/>
  62. <xsl:include href="task.xsl"/>
  63. <xsl:include href="qandaset.xsl"/>
  64. <xsl:include href="synop.xsl"/>
  65. <xsl:include href="titlepage.xsl"/>
  66. <xsl:include href="titlepage.templates.xsl"/>
  67. <xsl:include href="pagesetup.xsl"/>
  68. <xsl:include href="pi.xsl"/>
  69. <xsl:include href="spaces.xsl"/>
  70. <xsl:include href="ebnf.xsl"/>
  71. <xsl:include href="../html/chunker.xsl"/>
  72. <xsl:include href="annotations.xsl"/>
  73. <xsl:include href="../common/stripns.xsl"/>
  74. <xsl:include href="fop.xsl"/>
  75. <xsl:include href="fop1.xsl"/>
  76. <xsl:include href="passivetex.xsl"/>
  77. <xsl:include href="xep.xsl"/>
  78. <xsl:include href="axf.xsl"/>
  79. <xsl:include href="ptc.xsl"/>
  80. <xsl:param name="stylesheet.result.type" select="'fo'"/>
  81. <!-- ==================================================================== -->
  82. <xsl:key name="id" match="*" use="@id|@xml:id"/>
  83. <!-- ==================================================================== -->
  84. <xsl:template match="*">
  85. <xsl:message>
  86. <xsl:value-of select="name(.)"/>
  87. <xsl:text> encountered</xsl:text>
  88. <xsl:if test="parent::*">
  89. <xsl:text> in </xsl:text>
  90. <xsl:value-of select="name(parent::*)"/>
  91. </xsl:if>
  92. <xsl:text>, but no template matches.</xsl:text>
  93. </xsl:message>
  94. <fo:block color="red">
  95. <xsl:text>&lt;</xsl:text>
  96. <xsl:value-of select="name(.)"/>
  97. <xsl:text>&gt;</xsl:text>
  98. <xsl:apply-templates/>
  99. <xsl:text>&lt;/</xsl:text>
  100. <xsl:value-of select="name(.)"/>
  101. <xsl:text>&gt;</xsl:text>
  102. </fo:block>
  103. </xsl:template>
  104. <!-- Update this list if new root elements supported -->
  105. <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
  106. <xsl:template match="/">
  107. <!-- * Get a title for current doc so that we let the user -->
  108. <!-- * know what document we are processing at this point. -->
  109. <xsl:variable name="doc.title">
  110. <xsl:call-template name="get.doc.title"/>
  111. </xsl:variable>
  112. <xsl:choose>
  113. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  114. toss the namespace and continue. Use the docbook5 namespaced
  115. stylesheets for DocBook5 if you don't want to use this feature.-->
  116. <!-- include extra test for Xalan quirk -->
  117. <xsl:when test="(function-available('exsl:node-set') or
  118. contains(system-property('xsl:vendor'),
  119. 'Apache Software Foundation'))
  120. and (*/self::ng:* or */self::db:*)">
  121. <xsl:call-template name="log.message">
  122. <xsl:with-param name="level">Note</xsl:with-param>
  123. <xsl:with-param name="source" select="$doc.title"/>
  124. <xsl:with-param name="context-desc">
  125. <xsl:text>namesp. cut</xsl:text>
  126. </xsl:with-param>
  127. <xsl:with-param name="message">
  128. <xsl:text>stripped namespace before processing</xsl:text>
  129. </xsl:with-param>
  130. </xsl:call-template>
  131. <xsl:variable name="nons">
  132. <xsl:apply-templates mode="stripNS"/>
  133. </xsl:variable>
  134. <xsl:call-template name="log.message">
  135. <xsl:with-param name="level">Note</xsl:with-param>
  136. <xsl:with-param name="source" select="$doc.title"/>
  137. <xsl:with-param name="context-desc">
  138. <xsl:text>namesp. cut</xsl:text>
  139. </xsl:with-param>
  140. <xsl:with-param name="message">
  141. <xsl:text>processing stripped document</xsl:text>
  142. </xsl:with-param>
  143. </xsl:call-template>
  144. <xsl:apply-templates select="exsl:node-set($nons)"/>
  145. </xsl:when>
  146. <!-- Can't process unless namespace removed -->
  147. <xsl:when test="*/self::ng:* or */self::db:*">
  148. <xsl:message terminate="yes">
  149. <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
  150. <xsl:text> cannot proceed.</xsl:text>
  151. </xsl:message>
  152. </xsl:when>
  153. <xsl:otherwise>
  154. <xsl:choose>
  155. <xsl:when test="$rootid != ''">
  156. <xsl:variable name="root.element" select="key('id', $rootid)"/>
  157. <xsl:choose>
  158. <xsl:when test="count($root.element) = 0">
  159. <xsl:message terminate="yes">
  160. <xsl:text>ID '</xsl:text>
  161. <xsl:value-of select="$rootid"/>
  162. <xsl:text>' not found in document.</xsl:text>
  163. </xsl:message>
  164. </xsl:when>
  165. <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
  166. <xsl:message terminate="yes">
  167. <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
  168. <xsl:value-of select="$rootid"/>
  169. <xsl:text>) for FO output </xsl:text>
  170. <xsl:text>must be one of the following elements:</xsl:text>
  171. <xsl:value-of select="$root.elements"/>
  172. </xsl:message>
  173. </xsl:when>
  174. <!-- Otherwise proceed -->
  175. <xsl:otherwise>
  176. <xsl:if test="$collect.xref.targets = 'yes' or
  177. $collect.xref.targets = 'only'">
  178. <xsl:apply-templates select="$root.element"
  179. mode="collect.targets"/>
  180. </xsl:if>
  181. <xsl:if test="$collect.xref.targets != 'only'">
  182. <xsl:apply-templates select="$root.element"
  183. mode="process.root"/>
  184. </xsl:if>
  185. </xsl:otherwise>
  186. </xsl:choose>
  187. </xsl:when>
  188. <!-- Otherwise process the document root element -->
  189. <xsl:otherwise>
  190. <xsl:variable name="document.element" select="*[1]"/>
  191. <xsl:choose>
  192. <xsl:when test="not(contains($root.elements,
  193. concat(' ', local-name($document.element), ' ')))">
  194. <xsl:message terminate="yes">
  195. <xsl:text>ERROR: Document root element for FO output </xsl:text>
  196. <xsl:text>must be one of the following elements:</xsl:text>
  197. <xsl:value-of select="$root.elements"/>
  198. </xsl:message>
  199. </xsl:when>
  200. <!-- Otherwise proceed -->
  201. <xsl:otherwise>
  202. <xsl:if test="$collect.xref.targets = 'yes' or
  203. $collect.xref.targets = 'only'">
  204. <xsl:apply-templates select="/"
  205. mode="collect.targets"/>
  206. </xsl:if>
  207. <xsl:if test="$collect.xref.targets != 'only'">
  208. <xsl:apply-templates select="/"
  209. mode="process.root"/>
  210. </xsl:if>
  211. </xsl:otherwise>
  212. </xsl:choose>
  213. </xsl:otherwise>
  214. </xsl:choose>
  215. </xsl:otherwise>
  216. </xsl:choose>
  217. </xsl:template>
  218. <xsl:template match="*" mode="process.root">
  219. <xsl:variable name="document.element" select="self::*"/>
  220. <xsl:call-template name="root.messages"/>
  221. <xsl:variable name="title">
  222. <xsl:choose>
  223. <xsl:when test="$document.element/title[1]">
  224. <xsl:value-of select="$document.element/title[1]"/>
  225. </xsl:when>
  226. <xsl:otherwise>[could not find document title]</xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:variable>
  229. <!-- Include all id values in XEP output -->
  230. <xsl:if test="$xep.extensions != 0">
  231. <xsl:processing-instruction
  232. name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
  233. </xsl:if>
  234. <fo:root xsl:use-attribute-sets="root.properties">
  235. <xsl:attribute name="language">
  236. <xsl:call-template name="l10n.language">
  237. <xsl:with-param name="target" select="/*[1]"/>
  238. </xsl:call-template>
  239. </xsl:attribute>
  240. <xsl:if test="$xep.extensions != 0">
  241. <xsl:call-template name="xep-pis"/>
  242. <xsl:call-template name="xep-document-information"/>
  243. </xsl:if>
  244. <xsl:if test="$axf.extensions != 0">
  245. <xsl:call-template name="axf-document-information"/>
  246. </xsl:if>
  247. <xsl:call-template name="setup.pagemasters"/>
  248. <xsl:if test="$fop.extensions != 0">
  249. <xsl:apply-templates select="$document.element" mode="fop.outline"/>
  250. </xsl:if>
  251. <xsl:if test="$fop1.extensions != 0">
  252. <xsl:variable name="bookmarks">
  253. <xsl:apply-templates select="$document.element"
  254. mode="fop1.outline"/>
  255. </xsl:variable>
  256. <xsl:if test="string($bookmarks) != ''">
  257. <fo:bookmark-tree>
  258. <xsl:copy-of select="$bookmarks"/>
  259. </fo:bookmark-tree>
  260. </xsl:if>
  261. </xsl:if>
  262. <xsl:if test="$xep.extensions != 0">
  263. <xsl:variable name="bookmarks">
  264. <xsl:apply-templates select="$document.element" mode="xep.outline"/>
  265. </xsl:variable>
  266. <xsl:if test="string($bookmarks) != ''">
  267. <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
  268. <xsl:copy-of select="$bookmarks"/>
  269. </rx:outline>
  270. </xsl:if>
  271. </xsl:if>
  272. <xsl:if test="$arbortext.extensions != 0 and $ati.xsl11.bookmarks != 0">
  273. <xsl:variable name="bookmarks">
  274. <xsl:apply-templates select="$document.element"
  275. mode="ati.xsl11.bookmarks"/>
  276. </xsl:variable>
  277. <xsl:if test="string($bookmarks) != ''">
  278. <fo:bookmark-tree>
  279. <xsl:copy-of select="$bookmarks"/>
  280. </fo:bookmark-tree>
  281. </xsl:if>
  282. </xsl:if>
  283. <xsl:apply-templates select="$document.element"/>
  284. </fo:root>
  285. </xsl:template>
  286. <xsl:template name="root.messages">
  287. <!-- redefine this any way you'd like to output messages -->
  288. <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
  289. <xsl:message>
  290. <xsl:text>Making </xsl:text>
  291. <xsl:value-of select="$page.orientation"/>
  292. <xsl:text> pages on </xsl:text>
  293. <xsl:value-of select="$paper.type"/>
  294. <xsl:text> paper (</xsl:text>
  295. <xsl:value-of select="$page.width"/>
  296. <xsl:text>x</xsl:text>
  297. <xsl:value-of select="$page.height"/>
  298. <xsl:text>)</xsl:text>
  299. </xsl:message>
  300. </xsl:template>
  301. <!-- ==================================================================== -->
  302. </xsl:stylesheet>