common.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <!--
  3. $LastChangedBy$
  4. $Date$
  5. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns="http://www.w3.org/1999/xhtml"
  8. version="1.0">
  9. <!-- This stylesheet contains common params and templates for all outputs. -->
  10. <!-- This file contains our localization strings (for internationalization) -->
  11. <xsl:param name="local.l10n.xml" select="document('lfs-l10n.xml')"/>
  12. <!-- INDEX -->
  13. <!-- Should the Index be generated? 1 = yes, 0 = no -->
  14. <xsl:param name="generate.index" select="1"></xsl:param>
  15. <!-- The indexing method used. Only 'basic' is supported by xsltproc -->
  16. <xsl:param name="index.method" select="'basic'"></xsl:param>
  17. <!-- The Index title:
  18. We create this param to can have gentext support in both
  19. the Index page title and links that point to the Index page.
  20. It also allow us to change the title, if wanted.
  21. Note: To change the title involves creating the appropiate
  22. entries in lfs-l10n.xml -->
  23. <xsl:param name="index-title">Index</xsl:param>
  24. <!-- Index title generation. -->
  25. <!-- The original template is in {docbook-xsl}/common/titles.xsl -->
  26. <xsl:template match="index" mode="title.markup">
  27. <xsl:param name="allow-anchors" select="0"/>
  28. <xsl:call-template name="gentext">
  29. <xsl:with-param name="key" select="$index-title"/>
  30. </xsl:call-template>
  31. </xsl:template>
  32. <!-- indexterm:
  33. Dropping unneeded anchors and fo:wraper elemments. -->
  34. <!-- The original templates are in {docbook-xsl}/{xhtml,fo}/index.xsl -->
  35. <xsl:template match="indexterm"/>
  36. <!-- -->
  37. <!-- LABELS -->
  38. <!-- Are sections enumerated? 1 = yes, 0 = no -->
  39. <xsl:param name="section.autolabel" select="1"/>
  40. <!-- Do section labels include the component label? 1 = yes, 0 = no -->
  41. <xsl:param name="section.label.includes.component.label" select="1"/>
  42. <!-- sect1 label.markup:
  43. Use lowercase roman numbers for sect1 in preface. -->
  44. <!-- The original template is in {docbook-xsl}/common/labels.xsl -->
  45. <xsl:template match="sect1" mode="label.markup">
  46. <!-- if the parent is a component, maybe label that too -->
  47. <xsl:variable name="parent.is.component">
  48. <xsl:call-template name="is.component">
  49. <xsl:with-param name="node" select=".."/>
  50. </xsl:call-template>
  51. </xsl:variable>
  52. <xsl:variable name="component.label">
  53. <xsl:if test="$section.label.includes.component.label != 0
  54. and $parent.is.component != 0">
  55. <xsl:variable name="parent.label">
  56. <xsl:apply-templates select=".." mode="label.markup"/>
  57. </xsl:variable>
  58. <xsl:if test="$parent.label != ''">
  59. <xsl:apply-templates select=".." mode="label.markup"/>
  60. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  61. </xsl:if>
  62. </xsl:if>
  63. </xsl:variable>
  64. <xsl:choose>
  65. <xsl:when test="@label">
  66. <xsl:value-of select="@label"/>
  67. </xsl:when>
  68. <xsl:when test="$section.autolabel != 0">
  69. <xsl:copy-of select="$component.label"/>
  70. <xsl:choose>
  71. <xsl:when test="ancestor::preface">
  72. <xsl:number format="i" count="sect1"/>
  73. </xsl:when>
  74. <xsl:otherwise>
  75. <xsl:number format="1" count="sect1"/>
  76. </xsl:otherwise>
  77. </xsl:choose>
  78. </xsl:when>
  79. </xsl:choose>
  80. </xsl:template>
  81. <!-- sect2 label.markup:
  82. Skip numeration for sect2 with empty title. -->
  83. <!-- The original template is in {docbook-xsl}/common/labels.xsl
  84. It match also sect3, sect4, and sect5, that are unchanged. -->
  85. <xsl:template match="sect2" mode="label.markup">
  86. <!-- label the parent -->
  87. <xsl:variable name="parent.section.label">
  88. <xsl:call-template name="label.this.section">
  89. <xsl:with-param name="section" select=".."/>
  90. </xsl:call-template>
  91. </xsl:variable>
  92. <xsl:if test="$parent.section.label != '0'">
  93. <xsl:apply-templates select=".." mode="label.markup"/>
  94. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  95. </xsl:if>
  96. <xsl:choose>
  97. <xsl:when test="@label">
  98. <xsl:value-of select="@label"/>
  99. </xsl:when>
  100. <xsl:when test="$section.autolabel != 0">
  101. <xsl:choose>
  102. <!-- If the first sect2 isn't numbered, renumber the remainig sections -->
  103. <xsl:when test="string-length(../sect2[1]/title) = 0">
  104. <xsl:variable name="totalsect2">
  105. <xsl:number count="sect2"/>
  106. </xsl:variable>
  107. <xsl:number value="$totalsect2 - 1"/>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <xsl:number count="sect2"/>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:when>
  114. </xsl:choose>
  115. </xsl:template>
  116. <!-- object.title.template:
  117. Skip numeration for sectX > sect1 in preface. -->
  118. <!-- The original template is in {docbook-xsl}/common/gentext.xsl. -->
  119. <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect|bridgehead"
  120. mode="object.title.template">
  121. <xsl:variable name="is.numbered">
  122. <xsl:call-template name="label.this.section"/>
  123. </xsl:variable>
  124. <xsl:choose>
  125. <xsl:when test="$is.numbered != 0 and not(ancestor::preface/sect1)">
  126. <xsl:call-template name="gentext.template">
  127. <xsl:with-param name="context" select="'title-numbered'"/>
  128. <xsl:with-param name="name">
  129. <xsl:call-template name="xpath.location"/>
  130. </xsl:with-param>
  131. </xsl:call-template>
  132. </xsl:when>
  133. <xsl:otherwise>
  134. <xsl:call-template name="gentext.template">
  135. <xsl:with-param name="context" select="'title-unnumbered'"/>
  136. <xsl:with-param name="name">
  137. <xsl:call-template name="xpath.location"/>
  138. </xsl:with-param>
  139. </xsl:call-template>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. </xsl:template>
  143. <!-- -->
  144. <!-- XREF (see {xhtml,pdf}/xref.xsl) -->
  145. <!-- mode object.xref.markup:
  146. Propagate role to named template substitute-markup -->
  147. <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
  148. <xsl:template match="*" mode="object.xref.markup">
  149. <xsl:param name="purpose"/>
  150. <xsl:param name="xrefstyle"/>
  151. <xsl:param name="referrer"/>
  152. <xsl:param name="verbose" select="1"/>
  153. <xsl:param name="role"/>
  154. <xsl:variable name="template">
  155. <xsl:choose>
  156. <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
  157. <xsl:call-template name="make.gentext.template">
  158. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  159. <xsl:with-param name="purpose" select="$purpose"/>
  160. <xsl:with-param name="referrer" select="$referrer"/>
  161. </xsl:call-template>
  162. </xsl:when>
  163. <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
  164. <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <xsl:apply-templates select="." mode="object.xref.template">
  168. <xsl:with-param name="purpose" select="$purpose"/>
  169. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  170. <xsl:with-param name="referrer" select="$referrer"/>
  171. </xsl:apply-templates>
  172. </xsl:otherwise>
  173. </xsl:choose>
  174. </xsl:variable>
  175. <xsl:if test="$template = '' and $verbose != 0">
  176. <xsl:message>
  177. <xsl:text>object.xref.markup: empty xref template</xsl:text>
  178. <xsl:text> for linkend="</xsl:text>
  179. <xsl:value-of select="@id|@xml:id"/>
  180. <xsl:text>" and @xrefstyle="</xsl:text>
  181. <xsl:value-of select="$xrefstyle"/>
  182. <xsl:text>"</xsl:text>
  183. </xsl:message>
  184. </xsl:if>
  185. <xsl:call-template name="substitute-markup">
  186. <xsl:with-param name="purpose" select="$purpose"/>
  187. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  188. <xsl:with-param name="referrer" select="$referrer"/>
  189. <xsl:with-param name="template" select="$template"/>
  190. <xsl:with-param name="verbose" select="$verbose"/>
  191. <xsl:with-param name="role" select="$role"/>
  192. </xsl:call-template>
  193. </xsl:template>
  194. <!-- substitute-markup:
  195. Propagate role to mode insert.title.markup -->
  196. <!-- The original template is in {docbook-xsl}/common/gentext.xsl -->
  197. <xsl:template name="substitute-markup">
  198. <xsl:param name="template" select="''"/>
  199. <xsl:param name="allow-anchors" select="'0'"/>
  200. <xsl:param name="title" select="''"/>
  201. <xsl:param name="subtitle" select="''"/>
  202. <xsl:param name="docname" select="''"/>
  203. <xsl:param name="label" select="''"/>
  204. <xsl:param name="pagenumber" select="''"/>
  205. <xsl:param name="purpose"/>
  206. <xsl:param name="xrefstyle"/>
  207. <xsl:param name="referrer"/>
  208. <xsl:param name="verbose"/>
  209. <xsl:param name="role"/>
  210. <xsl:choose>
  211. <xsl:when test="contains($template, '%')">
  212. <xsl:value-of select="substring-before($template, '%')"/>
  213. <xsl:variable name="candidate"
  214. select="substring(substring-after($template, '%'), 1, 1)"/>
  215. <xsl:choose>
  216. <xsl:when test="$candidate = 't'">
  217. <xsl:apply-templates select="." mode="insert.title.markup">
  218. <xsl:with-param name="purpose" select="$purpose"/>
  219. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  220. <xsl:with-param name="role" select="$role"/>
  221. <xsl:with-param name="title">
  222. <xsl:choose>
  223. <xsl:when test="$title != ''">
  224. <xsl:copy-of select="$title"/>
  225. </xsl:when>
  226. <xsl:otherwise>
  227. <xsl:apply-templates select="." mode="title.markup">
  228. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  229. <xsl:with-param name="verbose" select="$verbose"/>
  230. </xsl:apply-templates>
  231. </xsl:otherwise>
  232. </xsl:choose>
  233. </xsl:with-param>
  234. </xsl:apply-templates>
  235. </xsl:when>
  236. <xsl:when test="$candidate = 's'">
  237. <xsl:apply-templates select="." mode="insert.subtitle.markup">
  238. <xsl:with-param name="purpose" select="$purpose"/>
  239. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  240. <xsl:with-param name="subtitle">
  241. <xsl:choose>
  242. <xsl:when test="$subtitle != ''">
  243. <xsl:copy-of select="$subtitle"/>
  244. </xsl:when>
  245. <xsl:otherwise>
  246. <xsl:apply-templates select="." mode="subtitle.markup">
  247. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  248. </xsl:apply-templates>
  249. </xsl:otherwise>
  250. </xsl:choose>
  251. </xsl:with-param>
  252. </xsl:apply-templates>
  253. </xsl:when>
  254. <xsl:when test="$candidate = 'n'">
  255. <xsl:apply-templates select="." mode="insert.label.markup">
  256. <xsl:with-param name="purpose" select="$purpose"/>
  257. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  258. <xsl:with-param name="label">
  259. <xsl:choose>
  260. <xsl:when test="$label != ''">
  261. <xsl:copy-of select="$label"/>
  262. </xsl:when>
  263. <xsl:otherwise>
  264. <xsl:apply-templates select="." mode="label.markup"/>
  265. </xsl:otherwise>
  266. </xsl:choose>
  267. </xsl:with-param>
  268. </xsl:apply-templates>
  269. </xsl:when>
  270. <xsl:when test="$candidate = 'p'">
  271. <xsl:apply-templates select="." mode="insert.pagenumber.markup">
  272. <xsl:with-param name="purpose" select="$purpose"/>
  273. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  274. <xsl:with-param name="pagenumber">
  275. <xsl:choose>
  276. <xsl:when test="$pagenumber != ''">
  277. <xsl:copy-of select="$pagenumber"/>
  278. </xsl:when>
  279. <xsl:otherwise>
  280. <xsl:apply-templates select="." mode="pagenumber.markup"/>
  281. </xsl:otherwise>
  282. </xsl:choose>
  283. </xsl:with-param>
  284. </xsl:apply-templates>
  285. </xsl:when>
  286. <xsl:when test="$candidate = 'o'">
  287. <!-- olink target document title -->
  288. <xsl:apply-templates select="." mode="insert.olink.docname.markup">
  289. <xsl:with-param name="purpose" select="$purpose"/>
  290. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  291. <xsl:with-param name="docname">
  292. <xsl:choose>
  293. <xsl:when test="$docname != ''">
  294. <xsl:copy-of select="$docname"/>
  295. </xsl:when>
  296. <xsl:otherwise>
  297. <xsl:apply-templates select="." mode="olink.docname.markup"/>
  298. </xsl:otherwise>
  299. </xsl:choose>
  300. </xsl:with-param>
  301. </xsl:apply-templates>
  302. </xsl:when>
  303. <xsl:when test="$candidate = 'd'">
  304. <xsl:apply-templates select="." mode="insert.direction.markup">
  305. <xsl:with-param name="purpose" select="$purpose"/>
  306. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  307. <xsl:with-param name="direction">
  308. <xsl:choose>
  309. <xsl:when test="$referrer">
  310. <xsl:variable name="referent-is-below">
  311. <xsl:for-each select="preceding::xref">
  312. <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
  313. </xsl:for-each>
  314. </xsl:variable>
  315. <xsl:choose>
  316. <xsl:when test="$referent-is-below = ''">
  317. <xsl:call-template name="gentext">
  318. <xsl:with-param name="key" select="'above'"/>
  319. </xsl:call-template>
  320. </xsl:when>
  321. <xsl:otherwise>
  322. <xsl:call-template name="gentext">
  323. <xsl:with-param name="key" select="'below'"/>
  324. </xsl:call-template>
  325. </xsl:otherwise>
  326. </xsl:choose>
  327. </xsl:when>
  328. <xsl:otherwise>
  329. <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
  330. </xsl:otherwise>
  331. </xsl:choose>
  332. </xsl:with-param>
  333. </xsl:apply-templates>
  334. </xsl:when>
  335. <xsl:when test="$candidate = '%' ">
  336. <xsl:text>%</xsl:text>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. <!-- recurse with the rest of the template string -->
  343. <xsl:variable name="rest"
  344. select="substring($template,
  345. string-length(substring-before($template, '%'))+3)"/>
  346. <xsl:call-template name="substitute-markup">
  347. <xsl:with-param name="template" select="$rest"/>
  348. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  349. <xsl:with-param name="title" select="$title"/>
  350. <xsl:with-param name="subtitle" select="$subtitle"/>
  351. <xsl:with-param name="docname" select="$docname"/>
  352. <xsl:with-param name="label" select="$label"/>
  353. <xsl:with-param name="pagenumber" select="$pagenumber"/>
  354. <xsl:with-param name="purpose" select="$purpose"/>
  355. <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
  356. <xsl:with-param name="referrer" select="$referrer"/>
  357. <xsl:with-param name="verbose" select="$verbose"/>
  358. <xsl:with-param name="role" select="$role"/>
  359. </xsl:call-template>
  360. </xsl:when>
  361. <xsl:otherwise>
  362. <xsl:value-of select="$template"/>
  363. </xsl:otherwise>
  364. </xsl:choose>
  365. </xsl:template>
  366. <!-- -->
  367. <!-- Total packages size calculation -->
  368. <!-- returnvalue:
  369. If the tag is not empty, apply the original template.
  370. Otherwise apply the calculation template. -->
  371. <xsl:template match="returnvalue">
  372. <xsl:choose>
  373. <xsl:when test="count(*)&gt;0">
  374. <xsl:apply-imports/>
  375. </xsl:when>
  376. <xsl:otherwise>
  377. <xsl:call-template name="calculation">
  378. <xsl:with-param name="scope" select="../../variablelist"/>
  379. </xsl:call-template>
  380. </xsl:otherwise>
  381. </xsl:choose>
  382. </xsl:template>
  383. <!-- Self-made calculation template. -->
  384. <xsl:template name="calculation">
  385. <xsl:param name="scope"/>
  386. <xsl:param name="total">0</xsl:param>
  387. <xsl:param name="position">1</xsl:param>
  388. <xsl:variable name="tokens" select="count($scope/varlistentry)"/>
  389. <xsl:variable name="token" select="$scope/varlistentry[$position]/term/token"/>
  390. <xsl:variable name="size" select="substring-before($token,' KB')"/>
  391. <xsl:variable name="rawsize">
  392. <xsl:choose>
  393. <xsl:when test="contains($size,',')">
  394. <xsl:value-of select="concat(substring-before($size,','),substring-after($size,','))"/>
  395. </xsl:when>
  396. <xsl:otherwise>
  397. <xsl:value-of select="$size"/>
  398. </xsl:otherwise>
  399. </xsl:choose>
  400. </xsl:variable>
  401. <xsl:choose>
  402. <xsl:when test="$position &lt;= $tokens">
  403. <xsl:call-template name="calculation">
  404. <xsl:with-param name="scope" select="$scope"/>
  405. <xsl:with-param name="position" select="$position +1"/>
  406. <xsl:with-param name="total" select="$total + $rawsize"/>
  407. </xsl:call-template>
  408. </xsl:when>
  409. <xsl:otherwise>
  410. <xsl:choose>
  411. <xsl:when test="$total &lt; '1000'">
  412. <xsl:value-of select="$total"/>
  413. <xsl:text> KB</xsl:text>
  414. </xsl:when>
  415. <xsl:when test="$total &gt; '1000' and $total &lt; '5000'">
  416. <xsl:value-of select="substring($total,1,1)"/>
  417. <xsl:text>,</xsl:text>
  418. <xsl:value-of select="substring($total,2)"/>
  419. <xsl:text> KB</xsl:text>
  420. </xsl:when>
  421. <xsl:otherwise>
  422. <xsl:value-of select="round($total div 1024)"/>
  423. <xsl:text> MB</xsl:text>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. </xsl:otherwise>
  427. </xsl:choose>
  428. </xsl:template>
  429. <!-- -->
  430. </xsl:stylesheet>