lfs-mixed.xsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns="http://www.w3.org/1999/xhtml"
  4. version="1.0">
  5. <!-- REVISED -->
  6. <!-- This stylesheet contains misc templates for output formating.
  7. This file is for that templates that don't fit in other files
  8. and that not afect the chunk algorithm. -->
  9. <!-- Individual elements templates -->
  10. <!-- para:
  11. Added a choose to skip empty "Home page" in packages.xml -->
  12. <!-- The original template is in {docbook-xsl}/xhtml/block.xsl -->
  13. <xsl:template match="para">
  14. <xsl:choose>
  15. <xsl:when test="child::ulink[@url=' ']"/>
  16. <xsl:otherwise>
  17. <xsl:call-template name="paragraph">
  18. <xsl:with-param name="class">
  19. <xsl:if test="@role and $para.propagates.style != 0">
  20. <xsl:value-of select="@role"/>
  21. </xsl:if>
  22. </xsl:with-param>
  23. <xsl:with-param name="content">
  24. <xsl:if test="position() = 1 and parent::listitem">
  25. <xsl:call-template name="anchor">
  26. <xsl:with-param name="node" select="parent::listitem"/>
  27. </xsl:call-template>
  28. </xsl:if>
  29. <xsl:call-template name="anchor"/>
  30. <xsl:apply-templates/>
  31. </xsl:with-param>
  32. </xsl:call-template>
  33. </xsl:otherwise>
  34. </xsl:choose>
  35. </xsl:template>
  36. <!-- screen:
  37. Changed class attribute asignament to fit our look needs.
  38. Removed unused line numbering support. -->
  39. <!-- The original template is in {docbook-xsl}/xhtml/verbatim.xsl
  40. It match also programlisting and synopsis. The code for that tags
  41. is unchanged. -->
  42. <xsl:template match="screen">
  43. <xsl:choose>
  44. <xsl:when test="child::* = userinput">
  45. <pre class="userinput">
  46. <xsl:apply-templates/>
  47. </pre>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <pre class="{name(.)}">
  51. <xsl:apply-templates/>
  52. </pre>
  53. </xsl:otherwise>
  54. </xsl:choose>
  55. </xsl:template>
  56. <!-- userinput:
  57. Using a customized output when inside screen.
  58. In other cases, use the original template. -->
  59. <!-- The original template is in {docbook-xsl}/xhtml/inline.xsl -->
  60. <xsl:template match="userinput">
  61. <xsl:choose>
  62. <xsl:when test="ancestor::screen">
  63. <kbd class="command">
  64. <xsl:apply-templates/>
  65. </kbd>
  66. </xsl:when>
  67. <xsl:otherwise>
  68. <xsl:apply-imports/>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. </xsl:template>
  72. <!-- seg in segementedlist:
  73. Added a span around seg text to can match it with CSS code. -->
  74. <!-- The original template is in {docbook-xsl}/xhtml/lists.xsl -->
  75. <xsl:template match="seg">
  76. <xsl:variable name="segnum" select="count(preceding-sibling::seg)+1"/>
  77. <xsl:variable name="seglist" select="ancestor::segmentedlist"/>
  78. <xsl:variable name="segtitles" select="$seglist/segtitle"/>
  79. <!-- Note: segtitle is only going to be the right thing in a well formed
  80. SegmentedList. If there are too many Segs or too few SegTitles,
  81. you'll get something odd...maybe an error -->
  82. <div class="seg">
  83. <strong>
  84. <span class="segtitle">
  85. <xsl:apply-templates select="$segtitles[$segnum=position()]" mode="segtitle-in-seg"/>
  86. <xsl:text>: </xsl:text>
  87. </span>
  88. </strong>
  89. <span class="seg">
  90. <xsl:apply-templates/>
  91. </span>
  92. </div>
  93. </xsl:template>
  94. <!-- variablelist:
  95. If it have a role attribute, wrap the default output into a div with
  96. a class attribute matching that role attribute.
  97. Apply the original template in all cases. -->
  98. <!-- The original template is in {docbook-xsl}/xhtml/lists.xsl -->
  99. <xsl:template match="variablelist">
  100. <xsl:choose>
  101. <xsl:when test="@role">
  102. <div class="{@role}">
  103. <xsl:apply-imports/>
  104. </div>
  105. </xsl:when>
  106. <xsl:otherwise>
  107. <xsl:apply-imports/>
  108. </xsl:otherwise>
  109. </xsl:choose>
  110. </xsl:template>
  111. <!-- Named formating templates -->
  112. <!-- Body attributes:
  113. Add to the body XHTML output tag an id attribute with the book type
  114. and a class atribute with the book version. -->
  115. <!-- The original template is in {docbook-xsl}/xhtml/docbook.xsl -->
  116. <xsl:template name="body.attributes">
  117. <xsl:attribute name="id">
  118. <xsl:text>lfs</xsl:text>
  119. </xsl:attribute>
  120. <xsl:attribute name="class">
  121. <xsl:value-of select="substring-after(/book/bookinfo/subtitle, ' ')"/>
  122. </xsl:attribute>
  123. </xsl:template>
  124. <!-- inline.monoseq:
  125. The code xhtml tag have look issues in some browsers.
  126. We will use tt instead. -->
  127. <!-- The original template is in {docbook-xsl}/xhtml/inline.xsl -->
  128. <xsl:template name="inline.monoseq">
  129. <xsl:param name="content">
  130. <xsl:call-template name="anchor"/>
  131. <xsl:call-template name="simple.xlink">
  132. <xsl:with-param name="content">
  133. <xsl:apply-templates/>
  134. </xsl:with-param>
  135. </xsl:call-template>
  136. </xsl:param>
  137. <tt>
  138. <xsl:apply-templates select="." mode="class.attribute"/>
  139. <xsl:call-template name="dir"/>
  140. <xsl:call-template name="generate.html.title"/>
  141. <xsl:copy-of select="$content"/>
  142. <xsl:call-template name="apply-annotations"/>
  143. </tt>
  144. </xsl:template>
  145. <!-- inline.boldmonoseq:
  146. The code xhtml tag have look issues in some browsers.
  147. We will use tt instead. -->
  148. <!-- The original template is in {docbook-xsl}/xhtml/inline.xsl -->
  149. <xsl:template name="inline.boldmonoseq">
  150. <xsl:param name="content">
  151. <xsl:call-template name="anchor"/>
  152. <xsl:call-template name="simple.xlink">
  153. <xsl:with-param name="content">
  154. <xsl:apply-templates/>
  155. </xsl:with-param>
  156. </xsl:call-template>
  157. </xsl:param>
  158. <!-- don't put <strong> inside figure, example, or table titles
  159. or other titles that may already be represented with <strong>'s. -->
  160. <xsl:choose>
  161. <xsl:when test="local-name(..) = 'title' and (local-name(../..) = 'figure'
  162. or local-name(../..) = 'example' or local-name(../..) = 'table'
  163. or local-name(../..) = 'formalpara')">
  164. <tt>
  165. <xsl:apply-templates select="." mode="class.attribute"/>
  166. <xsl:call-template name="generate.html.title"/>
  167. <xsl:call-template name="dir"/>
  168. <xsl:copy-of select="$content"/>
  169. <xsl:call-template name="apply-annotations"/>
  170. </tt>
  171. </xsl:when>
  172. <xsl:otherwise>
  173. <strong>
  174. <xsl:apply-templates select="." mode="class.attribute"/>
  175. <tt>
  176. <xsl:call-template name="generate.html.title"/>
  177. <xsl:call-template name="dir"/>
  178. <xsl:copy-of select="$content"/>
  179. </tt>
  180. </strong>
  181. </xsl:otherwise>
  182. </xsl:choose>
  183. </xsl:template>
  184. <!-- inline.italicmonoseq:
  185. The code xhtml tag have look issues in some browsers.
  186. We will use tt instead. -->
  187. <!-- The original template is in {docbook-xsl}/xhtml/inline.xsl -->
  188. <xsl:template name="inline.italicmonoseq">
  189. <xsl:param name="content">
  190. <xsl:call-template name="anchor"/>
  191. <xsl:call-template name="simple.xlink">
  192. <xsl:with-param name="content">
  193. <xsl:apply-templates/>
  194. </xsl:with-param>
  195. </xsl:call-template>
  196. </xsl:param>
  197. <em>
  198. <xsl:apply-templates select="." mode="class.attribute"/>
  199. <tt>
  200. <xsl:call-template name="generate.html.title"/>
  201. <xsl:call-template name="dir"/>
  202. <xsl:copy-of select="$content"/>
  203. <xsl:call-template name="apply-annotations"/>
  204. </tt>
  205. </em>
  206. </xsl:template>
  207. <!-- Total packages size calculation -->
  208. <!-- returnvalue:
  209. If the tag is not empty, apply the original template.
  210. Otherwise apply the calculation template. -->
  211. <!-- The original template is in {docbook-xsl}/xhtml/inline.xsl -->
  212. <xsl:template match="returnvalue">
  213. <xsl:choose>
  214. <xsl:when test="count(*)&gt;0">
  215. <xsl:apply-imports/>
  216. </xsl:when>
  217. <xsl:otherwise>
  218. <xsl:call-template name="calculation">
  219. <xsl:with-param name="scope" select="../../variablelist"/>
  220. </xsl:call-template>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:template>
  224. <!-- Self-made calculation template. -->
  225. <xsl:template name="calculation">
  226. <xsl:param name="scope"/>
  227. <xsl:param name="total">0</xsl:param>
  228. <xsl:param name="position">1</xsl:param>
  229. <xsl:variable name="tokens" select="count($scope/varlistentry)"/>
  230. <xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
  231. <xsl:variable name="size" select="substring-before($token,' KB')"/>
  232. <xsl:variable name="rawsize">
  233. <xsl:choose>
  234. <xsl:when test="contains($size,',')">
  235. <xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
  236. </xsl:when>
  237. <xsl:otherwise>
  238. <xsl:value-of select="$size"/>
  239. </xsl:otherwise>
  240. </xsl:choose>
  241. </xsl:variable>
  242. <xsl:choose>
  243. <xsl:when test="$position &lt;= $tokens">
  244. <xsl:call-template name="calculation">
  245. <xsl:with-param name="scope" select="$scope"/>
  246. <xsl:with-param name="position" select="$position +1"/>
  247. <xsl:with-param name="total" select="$total + $rawsize"/>
  248. </xsl:call-template>
  249. </xsl:when>
  250. <xsl:otherwise>
  251. <xsl:choose>
  252. <xsl:when test="$total &lt; '1000'">
  253. <xsl:value-of select="$total"/>
  254. <xsl:text> KB</xsl:text>
  255. </xsl:when>
  256. <xsl:when test="$total &gt; '1000' and $total &lt; '5000'">
  257. <xsl:value-of select="substring($total,1,1)"/>
  258. <xsl:text>,</xsl:text>
  259. <xsl:value-of select="substring($total,2)"/>
  260. <xsl:text> KB</xsl:text>
  261. </xsl:when>
  262. <xsl:otherwise>
  263. <xsl:value-of select="round($total div 1024)"/>
  264. <xsl:text> MB</xsl:text>
  265. </xsl:otherwise>
  266. </xsl:choose>
  267. </xsl:otherwise>
  268. </xsl:choose>
  269. </xsl:template>
  270. </xsl:stylesheet>