bz-fo.xsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?xml version="1.0" encoding="UTF-8"?> <!-- -*- sgml -*- -->
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
  4. <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
  5. <xsl:import href="bz-common.xsl"/>
  6. <!-- set indent = yes while debugging, then change to NO -->
  7. <xsl:output method="xml" indent="yes"/>
  8. <!-- ensure only passivetex extensions are on -->
  9. <xsl:param name="stylesheet.result.type" select="'fo'"/>
  10. <!-- fo extensions: PDF bookmarks and index terms -->
  11. <xsl:param name="use.extensions" select="'1'"/>
  12. <xsl:param name="xep.extensions" select="0"/>
  13. <xsl:param name="fop.extensions" select="0"/>
  14. <xsl:param name="saxon.extensions" select="0"/>
  15. <xsl:param name="passivetex.extensions" select="1"/>
  16. <xsl:param name="tablecolumns.extension" select="'1'"/>
  17. <!-- ensure we are using single sided -->
  18. <xsl:param name="double.sided" select="'0'"/>
  19. <!-- insert cross references to page numbers -->
  20. <xsl:param name="insert.xref.page.number" select="1"/>
  21. <!-- <?custom-pagebreak?> inserts a page break at this point -->
  22. <xsl:template match="processing-instruction('custom-pagebreak')">
  23. <fo:block break-before='page'/>
  24. </xsl:template>
  25. <!-- show links in color -->
  26. <xsl:attribute-set name="xref.properties">
  27. <xsl:attribute name="color">blue</xsl:attribute>
  28. </xsl:attribute-set>
  29. <!-- make pre listings indented a bit + a bg colour -->
  30. <xsl:template match="programlisting | screen">
  31. <fo:block start-indent="0.25in" wrap-option="no-wrap"
  32. white-space-collapse="false" text-align="start"
  33. font-family="monospace" background-color="#f2f2f9"
  34. linefeed-treatment="preserve"
  35. xsl:use-attribute-sets="normal.para.spacing">
  36. <xsl:apply-templates/>
  37. </fo:block>
  38. </xsl:template>
  39. <!-- make verbatim output prettier -->
  40. <xsl:template match="literallayout">
  41. <fo:block start-indent="0.25in" wrap-option="no-wrap"
  42. white-space-collapse="false" text-align="start"
  43. font-family="monospace" background-color="#edf7f4"
  44. linefeed-treatment="preserve"
  45. space-before="0em" space-after="0em">
  46. <xsl:apply-templates/>
  47. </fo:block>
  48. </xsl:template>
  49. <!-- workaround bug in passivetex fo output for itemizedlist -->
  50. <xsl:template match="itemizedlist/listitem">
  51. <xsl:variable name="id">
  52. <xsl:call-template name="object.id"/></xsl:variable>
  53. <xsl:variable name="itemsymbol">
  54. <xsl:call-template name="list.itemsymbol">
  55. <xsl:with-param name="node" select="parent::itemizedlist"/>
  56. </xsl:call-template>
  57. </xsl:variable>
  58. <xsl:variable name="item.contents">
  59. <fo:list-item-label end-indent="label-end()">
  60. <fo:block>
  61. <xsl:choose>
  62. <xsl:when test="$itemsymbol='disc'">&#x2022;</xsl:when>
  63. <xsl:when test="$itemsymbol='bullet'">&#x2022;</xsl:when>
  64. <xsl:otherwise>&#x2022;</xsl:otherwise>
  65. </xsl:choose>
  66. </fo:block>
  67. </fo:list-item-label>
  68. <fo:list-item-body start-indent="body-start()">
  69. <xsl:apply-templates/> <!-- removed extra block wrapper -->
  70. </fo:list-item-body>
  71. </xsl:variable>
  72. <xsl:choose>
  73. <xsl:when test="parent::*/@spacing = 'compact'">
  74. <fo:list-item id="{$id}"
  75. xsl:use-attribute-sets="compact.list.item.spacing">
  76. <xsl:copy-of select="$item.contents"/>
  77. </fo:list-item>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
  81. <xsl:copy-of select="$item.contents"/>
  82. </fo:list-item>
  83. </xsl:otherwise>
  84. </xsl:choose>
  85. </xsl:template>
  86. <!-- workaround bug in passivetex fo output for orderedlist -->
  87. <xsl:template match="orderedlist/listitem">
  88. <xsl:variable name="id">
  89. <xsl:call-template name="object.id"/></xsl:variable>
  90. <xsl:variable name="item.contents">
  91. <fo:list-item-label end-indent="label-end()">
  92. <fo:block>
  93. <xsl:apply-templates select="." mode="item-number"/>
  94. </fo:block>
  95. </fo:list-item-label>
  96. <fo:list-item-body start-indent="body-start()">
  97. <xsl:apply-templates/> <!-- removed extra block wrapper -->
  98. </fo:list-item-body>
  99. </xsl:variable>
  100. <xsl:choose>
  101. <xsl:when test="parent::*/@spacing = 'compact'">
  102. <fo:list-item id="{$id}"
  103. xsl:use-attribute-sets="compact.list.item.spacing">
  104. <xsl:copy-of select="$item.contents"/>
  105. </fo:list-item>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
  109. <xsl:copy-of select="$item.contents"/>
  110. </fo:list-item>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:template>
  114. <!-- workaround bug in passivetex fo output for variablelist -->
  115. <xsl:param name="variablelist.as.blocks" select="1"/>
  116. <xsl:template match="varlistentry" mode="vl.as.blocks">
  117. <xsl:variable name="id">
  118. <xsl:call-template name="object.id"/></xsl:variable>
  119. <fo:block id="{$id}" xsl:use-attribute-sets="list.item.spacing"
  120. keep-together.within-column="always"
  121. keep-with-next.within-column="always">
  122. <xsl:apply-templates select="term"/>
  123. </fo:block>
  124. <fo:block start-indent="0.5in" end-indent="0in"
  125. space-after.minimum="0.2em"
  126. space-after.optimum="0.4em"
  127. space-after.maximum="0.6em">
  128. <fo:block>
  129. <xsl:apply-templates select="listitem"/>
  130. </fo:block>
  131. </fo:block>
  132. </xsl:template>
  133. <!-- workaround bug in footers: force right-align w/two 80|30 cols -->
  134. <xsl:template name="footer.table">
  135. <xsl:param name="pageclass" select="''"/>
  136. <xsl:param name="sequence" select="''"/>
  137. <xsl:param name="gentext-key" select="''"/>
  138. <xsl:choose>
  139. <xsl:when test="$pageclass = 'index'">
  140. <xsl:attribute name="margin-left">0pt</xsl:attribute>
  141. </xsl:when>
  142. </xsl:choose>
  143. <xsl:variable name="candidate">
  144. <fo:table table-layout="fixed" width="100%">
  145. <fo:table-column column-number="1" column-width="80%"/>
  146. <fo:table-column column-number="2" column-width="20%"/>
  147. <fo:table-body>
  148. <fo:table-row height="14pt">
  149. <fo:table-cell text-align="left" display-align="after">
  150. <xsl:attribute name="relative-align">baseline</xsl:attribute>
  151. <fo:block>
  152. <fo:block> </fo:block><!-- empty cell -->
  153. </fo:block>
  154. </fo:table-cell>
  155. <fo:table-cell text-align="center" display-align="after">
  156. <xsl:attribute name="relative-align">baseline</xsl:attribute>
  157. <fo:block>
  158. <xsl:call-template name="footer.content">
  159. <xsl:with-param name="pageclass" select="$pageclass"/>
  160. <xsl:with-param name="sequence" select="$sequence"/>
  161. <xsl:with-param name="position" select="'center'"/>
  162. <xsl:with-param name="gentext-key" select="$gentext-key"/>
  163. </xsl:call-template>
  164. </fo:block>
  165. </fo:table-cell>
  166. </fo:table-row>
  167. </fo:table-body>
  168. </fo:table>
  169. </xsl:variable>
  170. <!-- Really output a footer? -->
  171. <xsl:choose>
  172. <xsl:when test="$pageclass='titlepage' and $gentext-key='book'
  173. and $sequence='first'">
  174. <!-- no, book titlepages have no footers at all -->
  175. </xsl:when>
  176. <xsl:when test="$sequence = 'blank' and $footers.on.blank.pages = 0">
  177. <!-- no output -->
  178. </xsl:when>
  179. <xsl:otherwise>
  180. <xsl:copy-of select="$candidate"/>
  181. </xsl:otherwise>
  182. </xsl:choose>
  183. </xsl:template>
  184. <!-- fix bug in headers: force right-align w/two 40|60 cols -->
  185. <xsl:template name="header.table">
  186. <xsl:param name="pageclass" select="''"/>
  187. <xsl:param name="sequence" select="''"/>
  188. <xsl:param name="gentext-key" select="''"/>
  189. <xsl:choose>
  190. <xsl:when test="$pageclass = 'index'">
  191. <xsl:attribute name="margin-left">0pt</xsl:attribute>
  192. </xsl:when>
  193. </xsl:choose>
  194. <xsl:variable name="candidate">
  195. <fo:table table-layout="fixed" width="100%">
  196. <xsl:call-template name="head.sep.rule">
  197. <xsl:with-param name="pageclass" select="$pageclass"/>
  198. <xsl:with-param name="sequence" select="$sequence"/>
  199. <xsl:with-param name="gentext-key" select="$gentext-key"/>
  200. </xsl:call-template>
  201. <fo:table-column column-number="1" column-width="40%"/>
  202. <fo:table-column column-number="2" column-width="60%"/>
  203. <fo:table-body>
  204. <fo:table-row height="14pt">
  205. <fo:table-cell text-align="left" display-align="before">
  206. <xsl:attribute name="relative-align">baseline</xsl:attribute>
  207. <fo:block>
  208. <fo:block> </fo:block><!-- empty cell -->
  209. </fo:block>
  210. </fo:table-cell>
  211. <fo:table-cell text-align="center" display-align="before">
  212. <xsl:attribute name="relative-align">baseline</xsl:attribute>
  213. <fo:block>
  214. <xsl:call-template name="header.content">
  215. <xsl:with-param name="pageclass" select="$pageclass"/>
  216. <xsl:with-param name="sequence" select="$sequence"/>
  217. <xsl:with-param name="position" select="'center'"/>
  218. <xsl:with-param name="gentext-key" select="$gentext-key"/>
  219. </xsl:call-template>
  220. </fo:block>
  221. </fo:table-cell>
  222. </fo:table-row>
  223. </fo:table-body>
  224. </fo:table>
  225. </xsl:variable>
  226. <!-- Really output a header? -->
  227. <xsl:choose>
  228. <xsl:when test="$pageclass = 'titlepage' and $gentext-key = 'book'
  229. and $sequence='first'">
  230. <!-- no, book titlepages have no headers at all -->
  231. </xsl:when>
  232. <xsl:when test="$sequence = 'blank' and $headers.on.blank.pages = 0">
  233. <!-- no output -->
  234. </xsl:when>
  235. <xsl:otherwise>
  236. <xsl:copy-of select="$candidate"/>
  237. </xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:template>
  240. <!-- Bug-fix for Suse 10 PassiveTex version -->
  241. <!-- Precompute attribute values 'cos PassiveTex is too stupid: -->
  242. <xsl:attribute-set name="component.title.properties">
  243. <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
  244. <xsl:attribute name="space-before.optimum">
  245. <xsl:value-of select="concat($body.font.master, 'pt')"/>
  246. </xsl:attribute>
  247. <xsl:attribute name="space-before.minimum">
  248. <xsl:value-of select="$body.font.master * 0.8"/>
  249. <xsl:text>pt</xsl:text>
  250. </xsl:attribute>
  251. <xsl:attribute name="space-before.maximum">
  252. <xsl:value-of select="$body.font.master * 1.2"/>
  253. <xsl:text>pt</xsl:text>
  254. </xsl:attribute>
  255. <xsl:attribute name="hyphenate">false</xsl:attribute>
  256. </xsl:attribute-set>
  257. </xsl:stylesheet>