lfs-mixed.xsl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. <!-- para -->
  6. <xsl:template match="para">
  7. <xsl:choose>
  8. <xsl:when test="child::ulink[@url=' ']"/>
  9. <xsl:otherwise>
  10. <xsl:call-template name="paragraph">
  11. <xsl:with-param name="class">
  12. <xsl:if test="@role and $para.propagates.style != 0">
  13. <xsl:value-of select="@role"/>
  14. </xsl:if>
  15. </xsl:with-param>
  16. <xsl:with-param name="content">
  17. <xsl:if test="position() = 1 and parent::listitem">
  18. <xsl:call-template name="anchor">
  19. <xsl:with-param name="node" select="parent::listitem"/>
  20. </xsl:call-template>
  21. </xsl:if>
  22. <xsl:call-template name="anchor"/>
  23. <xsl:apply-templates/>
  24. </xsl:with-param>
  25. </xsl:call-template>
  26. </xsl:otherwise>
  27. </xsl:choose>
  28. </xsl:template>
  29. <!-- screen -->
  30. <xsl:template match="screen">
  31. <xsl:choose>
  32. <xsl:when test="child::* = userinput">
  33. <pre class="userinput">
  34. <xsl:apply-templates/>
  35. </pre>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. <pre class="{name(.)}">
  39. <xsl:apply-templates/>
  40. </pre>
  41. </xsl:otherwise>
  42. </xsl:choose>
  43. </xsl:template>
  44. <xsl:template match="userinput">
  45. <xsl:choose>
  46. <xsl:when test="ancestor::screen">
  47. <kbd class="command">
  48. <xsl:apply-templates/>
  49. </kbd>
  50. </xsl:when>
  51. <xsl:otherwise>
  52. <xsl:apply-imports/>
  53. </xsl:otherwise>
  54. </xsl:choose>
  55. </xsl:template>
  56. <!-- segementedlist -->
  57. <xsl:template match="seg">
  58. <xsl:variable name="segnum" select="count(preceding-sibling::seg)+1"/>
  59. <xsl:variable name="seglist" select="ancestor::segmentedlist"/>
  60. <xsl:variable name="segtitles" select="$seglist/segtitle"/>
  61. <!-- Note: segtitle is only going to be the right thing in a well formed
  62. SegmentedList. If there are too many Segs or too few SegTitles,
  63. you'll get something odd...maybe an error -->
  64. <div class="seg">
  65. <strong>
  66. <span class="segtitle">
  67. <xsl:apply-templates select="$segtitles[$segnum=position()]" mode="segtitle-in-seg"/>
  68. <xsl:text>: </xsl:text>
  69. </span>
  70. </strong>
  71. <span class="seg">
  72. <xsl:apply-templates/>
  73. </span>
  74. </div>
  75. </xsl:template>
  76. <!-- variablelist -->
  77. <xsl:template match="variablelist">
  78. <xsl:choose>
  79. <xsl:when test="@role">
  80. <div class="{@role}">
  81. <xsl:apply-imports/>
  82. </div>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <xsl:apply-imports/>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. </xsl:template>
  89. <!-- Body attributes -->
  90. <xsl:template name="body.attributes">
  91. <xsl:attribute name="id">
  92. <xsl:text>lfs</xsl:text>
  93. </xsl:attribute>
  94. <xsl:attribute name="class">
  95. <xsl:value-of select="substring-after(/book/bookinfo/subtitle, ' ')"/>
  96. </xsl:attribute>
  97. </xsl:template>
  98. <!-- External URLs in italic font -->
  99. <xsl:template match="ulink" name="ulink">
  100. <a>
  101. <xsl:if test="@id">
  102. <xsl:attribute name="id">
  103. <xsl:value-of select="@id"/>
  104. </xsl:attribute>
  105. </xsl:if>
  106. <xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>
  107. <i>
  108. <xsl:choose>
  109. <xsl:when test="count(child::node())=0">
  110. <xsl:value-of select="@url"/>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:apply-templates/>
  114. </xsl:otherwise>
  115. </xsl:choose>
  116. </i>
  117. </a>
  118. </xsl:template>
  119. <!-- The <code> xhtml tag have look issues in some browsers, like Konqueror and.
  120. isn't semantically correct (a filename isn't a code fragment) We will use <tt> for now. -->
  121. <xsl:template name="inline.monoseq">
  122. <xsl:param name="content">
  123. <xsl:call-template name="anchor"/>
  124. <xsl:call-template name="simple.xlink">
  125. <xsl:with-param name="content">
  126. <xsl:apply-templates/>
  127. </xsl:with-param>
  128. </xsl:call-template>
  129. </xsl:param>
  130. <tt class="{local-name(.)}">
  131. <xsl:if test="@dir">
  132. <xsl:attribute name="dir">
  133. <xsl:value-of select="@dir"/>
  134. </xsl:attribute>
  135. </xsl:if>
  136. <xsl:copy-of select="$content"/>
  137. </tt>
  138. </xsl:template>
  139. <xsl:template name="inline.boldmonoseq">
  140. <xsl:param name="content">
  141. <xsl:call-template name="anchor"/>
  142. <xsl:call-template name="simple.xlink">
  143. <xsl:with-param name="content">
  144. <xsl:apply-templates/>
  145. </xsl:with-param>
  146. </xsl:call-template>
  147. </xsl:param>
  148. <!-- don't put <strong> inside figure, example, or table titles -->
  149. <!-- or other titles that may already be represented with <strong>'s. -->
  150. <xsl:choose>
  151. <xsl:when test="local-name(..) = 'title' and (local-name(../..) = 'figure'
  152. or local-name(../..) = 'example' or local-name(../..) = 'table' or local-name(../..) = 'formalpara')">
  153. <tt class="{local-name(.)}">
  154. <xsl:if test="@dir">
  155. <xsl:attribute name="dir">
  156. <xsl:value-of select="@dir"/>
  157. </xsl:attribute>
  158. </xsl:if>
  159. <xsl:copy-of select="$content"/>
  160. </tt>
  161. </xsl:when>
  162. <xsl:otherwise>
  163. <strong class="{local-name(.)}">
  164. <tt>
  165. <xsl:if test="@dir">
  166. <xsl:attribute name="dir">
  167. <xsl:value-of select="@dir"/>
  168. </xsl:attribute>
  169. </xsl:if>
  170. <xsl:copy-of select="$content"/>
  171. </tt>
  172. </strong>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:template>
  176. <xsl:template name="inline.italicmonoseq">
  177. <xsl:param name="content">
  178. <xsl:call-template name="anchor"/>
  179. <xsl:call-template name="simple.xlink">
  180. <xsl:with-param name="content">
  181. <xsl:apply-templates/>
  182. </xsl:with-param>
  183. </xsl:call-template>
  184. </xsl:param>
  185. <em class="{local-name(.)}">
  186. <tt>
  187. <xsl:if test="@dir">
  188. <xsl:attribute name="dir">
  189. <xsl:value-of select="@dir"/>
  190. </xsl:attribute>
  191. </xsl:if>
  192. <xsl:copy-of select="$content"/>
  193. </tt>
  194. </em>
  195. </xsl:template>
  196. <!-- Total packages size calculation -->
  197. <xsl:template match="returnvalue">
  198. <xsl:call-template name="calculation">
  199. <xsl:with-param name="scope" select="../../variablelist"/>
  200. </xsl:call-template>
  201. </xsl:template>
  202. <xsl:template name="calculation">
  203. <xsl:param name="scope"/>
  204. <xsl:param name="total">0</xsl:param>
  205. <xsl:param name="position">1</xsl:param>
  206. <xsl:variable name="tokens" select="count($scope/varlistentry)"/>
  207. <xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
  208. <xsl:variable name="size" select="substring-before($token,' KB')"/>
  209. <xsl:variable name="rawsize">
  210. <xsl:choose>
  211. <xsl:when test="contains($size,',')">
  212. <xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
  213. </xsl:when>
  214. <xsl:otherwise>
  215. <xsl:value-of select="$size"/>
  216. </xsl:otherwise>
  217. </xsl:choose>
  218. </xsl:variable>
  219. <xsl:choose>
  220. <xsl:when test="$position &lt;= $tokens">
  221. <xsl:call-template name="calculation">
  222. <xsl:with-param name="scope" select="$scope"/>
  223. <xsl:with-param name="position" select="$position +1"/>
  224. <xsl:with-param name="total" select="$total + $rawsize"/>
  225. </xsl:call-template>
  226. </xsl:when>
  227. <xsl:otherwise>
  228. <xsl:choose>
  229. <xsl:when test="$total &lt; '1000'">
  230. <xsl:value-of select="$total"/>
  231. <xsl:text> KB</xsl:text>
  232. </xsl:when>
  233. <xsl:when test="$total &gt; '1000' and $total &lt; '5000'">
  234. <xsl:value-of select="substring($total,1,1)"/>
  235. <xsl:text>,</xsl:text>
  236. <xsl:value-of select="substring($total,2)"/>
  237. <xsl:text> KB</xsl:text>
  238. </xsl:when>
  239. <xsl:otherwise>
  240. <xsl:value-of select="round($total div 1024)"/>
  241. <xsl:text> MB</xsl:text>
  242. </xsl:otherwise>
  243. </xsl:choose>
  244. </xsl:otherwise>
  245. </xsl:choose>
  246. </xsl:template>
  247. </xsl:stylesheet>