lfs-mixed.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version="1.0">
  5. <!-- This is a hack and isn't correct semantically. Theoretically, the beginpage
  6. tags should be placed in the XML source only to render the PDF output and
  7. should be removed after it. But there is no a better way and we need this.-->
  8. <xsl:template match="beginpage">
  9. <fo:block break-after="page"/>
  10. </xsl:template>
  11. <!-- Allow forced line breaks inside paragraphs emulating literallayout
  12. and to remove vertical space in pachages and patches pages. -->
  13. <xsl:template match="para">
  14. <xsl:choose>
  15. <xsl:when test="child::ulink[@url=' ']"/>
  16. <xsl:when test="./@remap='verbatim'">
  17. <fo:block wrap-option="no-wrap"
  18. white-space-collapse="false"
  19. white-space-treatment="preserve"
  20. text-align="start"
  21. linefeed-treatment="preserve">
  22. <xsl:call-template name="anchor"/>
  23. <xsl:apply-templates/>
  24. </fo:block>
  25. </xsl:when>
  26. <xsl:when test="ancestor::variablelist/@role = 'materials'">
  27. <fo:block>
  28. <xsl:attribute name="space-before.optimum">0.1em</xsl:attribute>
  29. <xsl:attribute name="space-before.minimum">0em</xsl:attribute>
  30. <xsl:attribute name="space-before.maximum">0.2em</xsl:attribute>
  31. <xsl:call-template name="anchor"/>
  32. <xsl:apply-templates/>
  33. </fo:block>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:apply-imports/>
  37. </xsl:otherwise>
  38. </xsl:choose>
  39. </xsl:template>
  40. <!-- Show URLs in italic font -->
  41. <xsl:template match="ulink" name="ulink">
  42. <fo:inline font-style="italic">
  43. <fo:basic-link xsl:use-attribute-sets="xref.properties">
  44. <xsl:attribute name="external-destination">
  45. <xsl:call-template name="fo-external-image">
  46. <xsl:with-param name="filename" select="@url"/>
  47. </xsl:call-template>
  48. </xsl:attribute>
  49. <xsl:choose>
  50. <xsl:when test="count(child::node())=0">
  51. <xsl:call-template name="hyphenate-url">
  52. <xsl:with-param name="url" select="@url"/>
  53. </xsl:call-template>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:apply-templates/>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. </fo:basic-link>
  60. </fo:inline>
  61. <xsl:if test="count(child::node()) != 0
  62. and string(.) != @url
  63. and $ulink.show != 0">
  64. <!-- yes, show the URI -->
  65. <xsl:choose>
  66. <xsl:when test="$ulink.footnotes != 0 and not(ancestor::footnote)">
  67. <xsl:text>&#xA0;</xsl:text>
  68. <fo:footnote>
  69. <xsl:call-template name="ulink.footnote.number"/>
  70. <fo:footnote-body font-family="{$body.fontset}"
  71. font-size="{$footnote.font.size}">
  72. <fo:block>
  73. <xsl:call-template name="ulink.footnote.number"/>
  74. <xsl:text> </xsl:text>
  75. <fo:inline>
  76. <xsl:value-of select="@url"/>
  77. </fo:inline>
  78. </fo:block>
  79. </fo:footnote-body>
  80. </fo:footnote>
  81. </xsl:when>
  82. <xsl:otherwise>
  83. <fo:inline hyphenate="false">
  84. <xsl:text> [</xsl:text>
  85. <xsl:call-template name="hyphenate-url">
  86. <xsl:with-param name="url" select="@url"/>
  87. </xsl:call-template>
  88. <xsl:text>]</xsl:text>
  89. </fo:inline>
  90. </xsl:otherwise>
  91. </xsl:choose>
  92. </xsl:if>
  93. </xsl:template>
  94. <!-- Split URLs (obsolete, keeped as reference) -->
  95. <!--<xsl:template name="hyphenate-url">
  96. <xsl:param name="url" select="''"/>
  97. <xsl:choose>
  98. <xsl:when test="ancestor::varlistentry">
  99. <xsl:choose>
  100. <xsl:when test="string-length($url) > 90">
  101. <xsl:value-of select="substring($url, 1, 50)"/>
  102. <xsl:param name="rest" select="substring($url, 51)"/>
  103. <xsl:value-of select="substring-before($rest, '/')"/>
  104. <xsl:text> /</xsl:text>
  105. <xsl:value-of select="substring-after($rest, '/')"/>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:value-of select="$url"/>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:value-of select="$url"/>-->
  114. <!-- <xsl:value-of select="substring-before($url, '//')"/>
  115. <xsl:text>// </xsl:text>
  116. <xsl:call-template name="split-url">
  117. <xsl:with-param name="url2" select="substring-after($url, '//')"/>
  118. </xsl:call-template>-->
  119. <!-- </xsl:otherwise>
  120. </xsl:choose>
  121. </xsl:template>-->
  122. <!--<xsl:template name="split-url">
  123. <xsl:choose>
  124. <xsl:when test="contains($url2, '/')">
  125. <xsl:param name="url2" select="''"/>
  126. <xsl:value-of select="substring-before($url2, '/')"/>
  127. <xsl:text> /</xsl:text>
  128. <xsl:call-template name="split-url">
  129. <xsl:with-param name="url2" select="substring-after($url2, '/')"/>
  130. </xsl:call-template>
  131. </xsl:when>
  132. <xsl:otherwise>
  133. <xsl:value-of select="$url2"/>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. </xsl:template>-->
  137. <!-- Shade screen -->
  138. <xsl:param name="shade.verbatim" select="1"/>
  139. <!-- How is rendered by default a variablelist -->
  140. <xsl:param name="variablelist.as.blocks" select="1"/>
  141. <xsl:param name="variablelist.max.termlength">32</xsl:param>
  142. <!-- Adding space before segmentedlist -->
  143. <xsl:template match="segmentedlist">
  144. <!--<xsl:variable name="presentation">
  145. <xsl:call-template name="pi-attribute">
  146. <xsl:with-param name="pis"
  147. select="processing-instruction('dbfo')"/>
  148. <xsl:with-param name="attribute" select="'list-presentation'"/>
  149. </xsl:call-template>
  150. </xsl:variable>
  151. <xsl:choose>
  152. <xsl:when test="$presentation = 'table'">
  153. <xsl:apply-templates select="." mode="seglist-table"/>
  154. </xsl:when>
  155. <xsl:when test="$presentation = 'list'">
  156. <fo:block space-before.minimum="0.4em" space-before.optimum="0.6em"
  157. space-before.maximum="0.8em">
  158. <xsl:apply-templates/>
  159. </fo:block>
  160. </xsl:when>
  161. <xsl:when test="$segmentedlist.as.table != 0">
  162. <xsl:apply-templates select="." mode="seglist-table"/>
  163. </xsl:when>
  164. <xsl:otherwise>-->
  165. <fo:block space-before.minimum="0.4em" space-before.optimum="0.6em"
  166. space-before.maximum="0.8em">
  167. <xsl:apply-templates/>
  168. </fo:block>
  169. <!--</xsl:otherwise>
  170. </xsl:choose>-->
  171. </xsl:template>
  172. <!-- Presentation of literal tag -->
  173. <xsl:template match="literal">
  174. <fo:inline font-weight="normal">
  175. <xsl:call-template name="inline.monoseq"/>
  176. </fo:inline>
  177. </xsl:template>
  178. <!-- Left alingnament for itemizedlist -->
  179. <xsl:template match="itemizedlist">
  180. <xsl:variable name="id">
  181. <xsl:call-template name="object.id"/>
  182. </xsl:variable>
  183. <xsl:variable name="label-width">
  184. <xsl:call-template name="dbfo-attribute">
  185. <xsl:with-param name="pis"
  186. select="processing-instruction('dbfo')"/>
  187. <xsl:with-param name="attribute" select="'label-width'"/>
  188. </xsl:call-template>
  189. </xsl:variable>
  190. <xsl:if test="title">
  191. <xsl:apply-templates select="title" mode="list.title.mode"/>
  192. </xsl:if>
  193. <!-- Preserve order of PIs and comments -->
  194. <xsl:apply-templates
  195. select="*[not(self::listitem
  196. or self::title
  197. or self::titleabbrev)]
  198. |comment()[not(preceding-sibling::listitem)]
  199. |processing-instruction()[not(preceding-sibling::listitem)]"/>
  200. <fo:list-block id="{$id}" xsl:use-attribute-sets="list.block.spacing"
  201. provisional-label-separation="0.2em" text-align="left">
  202. <xsl:attribute name="provisional-distance-between-starts">
  203. <xsl:choose>
  204. <xsl:when test="$label-width != ''">
  205. <xsl:value-of select="$label-width"/>
  206. </xsl:when>
  207. <xsl:otherwise>1.5em</xsl:otherwise>
  208. </xsl:choose>
  209. </xsl:attribute>
  210. <xsl:apply-templates
  211. select="listitem
  212. |comment()[preceding-sibling::listitem]
  213. |processing-instruction()[preceding-sibling::listitem]"/>
  214. </fo:list-block>
  215. </xsl:template>
  216. <!-- Addibg a bullet, and left alignament, for packages and paches list. -->
  217. <xsl:template match="varlistentry" mode="vl.as.blocks">
  218. <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
  219. <xsl:choose>
  220. <xsl:when test="ancestor::variablelist/@role = 'materials'">
  221. <fo:block id="{$id}" xsl:use-attribute-sets="list.item.spacing"
  222. keep-together.within-column="always"
  223. keep-with-next.within-column="always" text-align="left">
  224. <xsl:text>&#x2022; </xsl:text>
  225. <xsl:apply-templates select="term"/>
  226. </fo:block>
  227. <fo:block margin-left="1.4pc" text-align="left">
  228. <xsl:apply-templates select="listitem"/>
  229. </fo:block>
  230. </xsl:when>
  231. <xsl:otherwise>
  232. <fo:block id="{$id}" xsl:use-attribute-sets="list.item.spacing"
  233. keep-together.within-column="always"
  234. keep-with-next.within-column="always">
  235. <xsl:apply-templates select="term"/>
  236. </fo:block>
  237. <fo:block margin-left="0.25in">
  238. <xsl:apply-templates select="listitem"/>
  239. </fo:block>
  240. </xsl:otherwise>
  241. </xsl:choose>
  242. </xsl:template>
  243. <!-- Total packages size calculation -->
  244. <xsl:template match="returnvalue">
  245. <xsl:call-template name="calculation">
  246. <xsl:with-param name="scope" select="../../variablelist"/>
  247. </xsl:call-template>
  248. </xsl:template>
  249. <xsl:template name="calculation">
  250. <xsl:param name="scope"/>
  251. <xsl:param name="total">0</xsl:param>
  252. <xsl:param name="position">1</xsl:param>
  253. <xsl:variable name="tokens" select="count($scope/varlistentry)"/>
  254. <xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
  255. <xsl:variable name="size" select="substring-before($token,' KB')"/>
  256. <xsl:variable name="rawsize">
  257. <xsl:choose>
  258. <xsl:when test="contains($size,',')">
  259. <xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
  260. </xsl:when>
  261. <xsl:otherwise>
  262. <xsl:value-of select="$size"/>
  263. </xsl:otherwise>
  264. </xsl:choose>
  265. </xsl:variable>
  266. <xsl:choose>
  267. <xsl:when test="$position &lt;= $tokens">
  268. <xsl:call-template name="calculation">
  269. <xsl:with-param name="scope" select="$scope"/>
  270. <xsl:with-param name="position" select="$position +1"/>
  271. <xsl:with-param name="total" select="$total + $rawsize"/>
  272. </xsl:call-template>
  273. </xsl:when>
  274. <xsl:otherwise>
  275. <xsl:choose>
  276. <xsl:when test="$total &lt; '1000'">
  277. <xsl:value-of select="$total"/>
  278. <xsl:text> KB</xsl:text>
  279. </xsl:when>
  280. <xsl:when test="$total &gt; '1000' and $total &lt; '5000'">
  281. <xsl:value-of select="substring($total,1,1)"/>
  282. <xsl:text>,</xsl:text>
  283. <xsl:value-of select="substring($total,2)"/>
  284. <xsl:text> KB</xsl:text>
  285. </xsl:when>
  286. <xsl:otherwise>
  287. <xsl:value-of select="round($total div 1024)"/>
  288. <xsl:text> MB</xsl:text>
  289. </xsl:otherwise>
  290. </xsl:choose>
  291. </xsl:otherwise>
  292. </xsl:choose>
  293. </xsl:template>
  294. </xsl:stylesheet>