docbook.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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: docbook.xsl 9647 2012-10-26 17:42:03Z bobstayton $
  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.xsl"/>
  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="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:text>Element </xsl:text>
  86. <xsl:value-of select="local-name(.)"/>
  87. <xsl:text> in namespace '</xsl:text>
  88. <xsl:value-of select="namespace-uri(.)"/>
  89. <xsl:text>' encountered</xsl:text>
  90. <xsl:if test="parent::*">
  91. <xsl:text> in </xsl:text>
  92. <xsl:value-of select="name(parent::*)"/>
  93. </xsl:if>
  94. <xsl:text>, but no template matches.</xsl:text>
  95. </xsl:message>
  96. <fo:block color="red">
  97. <xsl:text>&lt;</xsl:text>
  98. <xsl:value-of select="name(.)"/>
  99. <xsl:text>&gt;</xsl:text>
  100. <xsl:apply-templates/>
  101. <xsl:text>&lt;/</xsl:text>
  102. <xsl:value-of select="name(.)"/>
  103. <xsl:text>&gt;</xsl:text>
  104. </fo:block>
  105. </xsl:template>
  106. <!-- Update this list if new root elements supported -->
  107. <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
  108. <xsl:template match="/">
  109. <!-- * Get a title for current doc so that we let the user -->
  110. <!-- * know what document we are processing at this point. -->
  111. <xsl:variable name="doc.title">
  112. <xsl:call-template name="get.doc.title"/>
  113. </xsl:variable>
  114. <xsl:choose>
  115. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  116. toss the namespace and continue. Use the docbook5 namespaced
  117. stylesheets for DocBook5 if you don't want to use this feature.-->
  118. <xsl:when test="$exsl.node.set.available != 0
  119. and (*/self::ng:* or */self::db:*)">
  120. <xsl:call-template name="log.message">
  121. <xsl:with-param name="level">Note</xsl:with-param>
  122. <xsl:with-param name="source" select="$doc.title"/>
  123. <xsl:with-param name="context-desc">
  124. <xsl:text>namesp. cut</xsl:text>
  125. </xsl:with-param>
  126. <xsl:with-param name="message">
  127. <xsl:text>stripped namespace before processing</xsl:text>
  128. </xsl:with-param>
  129. </xsl:call-template>
  130. <xsl:variable name="nons">
  131. <xsl:apply-templates mode="stripNS"/>
  132. </xsl:variable>
  133. <xsl:call-template name="log.message">
  134. <xsl:with-param name="level">Note</xsl:with-param>
  135. <xsl:with-param name="source" select="$doc.title"/>
  136. <xsl:with-param name="context-desc">
  137. <xsl:text>namesp. cut</xsl:text>
  138. </xsl:with-param>
  139. <xsl:with-param name="message">
  140. <xsl:text>processing stripped document</xsl:text>
  141. </xsl:with-param>
  142. </xsl:call-template>
  143. <xsl:apply-templates select="exsl:node-set($nons)"/>
  144. </xsl:when>
  145. <!-- Can't process unless namespace removed -->
  146. <xsl:when test="*/self::ng:* or */self::db:*">
  147. <xsl:message terminate="yes">
  148. <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
  149. <xsl:text> cannot proceed.</xsl:text>
  150. </xsl:message>
  151. </xsl:when>
  152. <xsl:otherwise>
  153. <xsl:choose>
  154. <xsl:when test="$rootid != ''">
  155. <xsl:variable name="root.element" select="key('id', $rootid)"/>
  156. <xsl:choose>
  157. <xsl:when test="count($root.element) = 0">
  158. <xsl:message terminate="yes">
  159. <xsl:text>ID '</xsl:text>
  160. <xsl:value-of select="$rootid"/>
  161. <xsl:text>' not found in document.</xsl:text>
  162. </xsl:message>
  163. </xsl:when>
  164. <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
  165. <xsl:message terminate="yes">
  166. <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
  167. <xsl:value-of select="$rootid"/>
  168. <xsl:text>) for FO output </xsl:text>
  169. <xsl:text>must be one of the following elements:</xsl:text>
  170. <xsl:value-of select="$root.elements"/>
  171. </xsl:message>
  172. </xsl:when>
  173. <!-- Otherwise proceed -->
  174. <xsl:otherwise>
  175. <xsl:if test="$collect.xref.targets = 'yes' or
  176. $collect.xref.targets = 'only'">
  177. <xsl:apply-templates select="$root.element"
  178. mode="collect.targets"/>
  179. </xsl:if>
  180. <xsl:if test="$collect.xref.targets != 'only'">
  181. <xsl:apply-templates select="$root.element"
  182. mode="process.root"/>
  183. </xsl:if>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </xsl:when>
  187. <!-- Otherwise process the document root element -->
  188. <xsl:otherwise>
  189. <xsl:variable name="document.element" select="*[1]"/>
  190. <xsl:choose>
  191. <xsl:when test="not(contains($root.elements,
  192. concat(' ', local-name($document.element), ' ')))">
  193. <xsl:message terminate="yes">
  194. <xsl:text>ERROR: Document root element for FO output </xsl:text>
  195. <xsl:text>must be one of the following elements:</xsl:text>
  196. <xsl:value-of select="$root.elements"/>
  197. </xsl:message>
  198. </xsl:when>
  199. <!-- Otherwise proceed -->
  200. <xsl:otherwise>
  201. <xsl:if test="$collect.xref.targets = 'yes' or
  202. $collect.xref.targets = 'only'">
  203. <xsl:apply-templates select="/"
  204. mode="collect.targets"/>
  205. </xsl:if>
  206. <xsl:if test="$collect.xref.targets != 'only'">
  207. <xsl:apply-templates select="/"
  208. mode="process.root"/>
  209. </xsl:if>
  210. </xsl:otherwise>
  211. </xsl:choose>
  212. </xsl:otherwise>
  213. </xsl:choose>
  214. </xsl:otherwise>
  215. </xsl:choose>
  216. </xsl:template>
  217. <xsl:template match="*" mode="process.root">
  218. <xsl:variable name="document.element" select="self::*"/>
  219. <xsl:call-template name="root.messages"/>
  220. <xsl:variable name="title">
  221. <xsl:choose>
  222. <xsl:when test="$document.element/title[1]">
  223. <xsl:value-of select="$document.element/title[1]"/>
  224. </xsl:when>
  225. <xsl:otherwise>[could not find document title]</xsl:otherwise>
  226. </xsl:choose>
  227. </xsl:variable>
  228. <!-- Include all id values in XEP output -->
  229. <xsl:if test="$xep.extensions != 0">
  230. <xsl:processing-instruction
  231. name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
  232. </xsl:if>
  233. <fo:root xsl:use-attribute-sets="root.properties">
  234. <xsl:attribute name="language">
  235. <xsl:call-template name="l10n.language">
  236. <xsl:with-param name="target" select="/*[1]"/>
  237. </xsl:call-template>
  238. </xsl:attribute>
  239. <xsl:if test="$xep.extensions != 0">
  240. <xsl:call-template name="xep-pis"/>
  241. <xsl:call-template name="xep-document-information"/>
  242. </xsl:if>
  243. <xsl:if test="$axf.extensions != 0">
  244. <xsl:call-template name="axf-document-information"/>
  245. </xsl:if>
  246. <xsl:call-template name="setup.pagemasters"/>
  247. <xsl:if test="$fop.extensions != 0">
  248. <xsl:apply-templates select="$document.element" mode="fop.outline"/>
  249. </xsl:if>
  250. <xsl:if test="$fop1.extensions != 0">
  251. <xsl:call-template name="fop1-document-information"/>
  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:apply-templates select="$document.element"
  262. mode="fop1.foxdest"/>
  263. </xsl:if>
  264. <xsl:if test="$xep.extensions != 0">
  265. <xsl:variable name="bookmarks">
  266. <xsl:apply-templates select="$document.element" mode="xep.outline"/>
  267. </xsl:variable>
  268. <xsl:if test="string($bookmarks) != ''">
  269. <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
  270. <xsl:copy-of select="$bookmarks"/>
  271. </rx:outline>
  272. </xsl:if>
  273. </xsl:if>
  274. <xsl:if test="$arbortext.extensions != 0 and $ati.xsl11.bookmarks != 0">
  275. <xsl:variable name="bookmarks">
  276. <xsl:apply-templates select="$document.element"
  277. mode="ati.xsl11.bookmarks"/>
  278. </xsl:variable>
  279. <xsl:if test="string($bookmarks) != ''">
  280. <fo:bookmark-tree>
  281. <xsl:copy-of select="$bookmarks"/>
  282. </fo:bookmark-tree>
  283. </xsl:if>
  284. </xsl:if>
  285. <xsl:apply-templates select="$document.element"/>
  286. </fo:root>
  287. </xsl:template>
  288. <xsl:template name="root.messages">
  289. <!-- redefine this any way you'd like to output messages -->
  290. <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
  291. <xsl:message>
  292. <xsl:text>Making </xsl:text>
  293. <xsl:value-of select="$page.orientation"/>
  294. <xsl:text> pages on </xsl:text>
  295. <xsl:value-of select="$paper.type"/>
  296. <xsl:text> paper (</xsl:text>
  297. <xsl:value-of select="$page.width"/>
  298. <xsl:text>x</xsl:text>
  299. <xsl:value-of select="$page.height"/>
  300. <xsl:text>)</xsl:text>
  301. </xsl:message>
  302. </xsl:template>
  303. <!-- ==================================================================== -->
  304. </xsl:stylesheet>