docbook.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:db="http://docbook.org/docbook-ng"
  4. xmlns:exsl="http://exslt.org/common"
  5. exclude-result-prefixes="db exsl"
  6. version='1.0'>
  7. <xsl:output method="html"
  8. encoding="ISO-8859-1"
  9. indent="no"/>
  10. <!-- ********************************************************************
  11. $Id: docbook.xsl,v 1.1.1.1 2011-08-27 15:30:16 cmaier Exp $
  12. ********************************************************************
  13. This file is part of the XSL DocBook Stylesheet distribution.
  14. See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  15. and other information.
  16. ******************************************************************** -->
  17. <!-- ==================================================================== -->
  18. <xsl:include href="../VERSION"/>
  19. <xsl:include href="param.xsl"/>
  20. <xsl:include href="../lib/lib.xsl"/>
  21. <xsl:include href="../common/l10n.xsl"/>
  22. <xsl:include href="../common/common.xsl"/>
  23. <xsl:include href="../common/labels.xsl"/>
  24. <xsl:include href="../common/titles.xsl"/>
  25. <xsl:include href="../common/subtitles.xsl"/>
  26. <xsl:include href="../common/gentext.xsl"/>
  27. <xsl:include href="../common/targets.xsl"/>
  28. <xsl:include href="../common/olink.xsl"/>
  29. <xsl:include href="../common/pi.xsl"/>
  30. <xsl:include href="autotoc.xsl"/>
  31. <xsl:include href="autoidx.xsl"/>
  32. <xsl:include href="lists.xsl"/>
  33. <xsl:include href="callout.xsl"/>
  34. <xsl:include href="verbatim.xsl"/>
  35. <xsl:include href="graphics.xsl"/>
  36. <xsl:include href="xref.xsl"/>
  37. <xsl:include href="formal.xsl"/>
  38. <xsl:include href="table.xsl"/>
  39. <xsl:include href="htmltbl.xsl"/>
  40. <xsl:include href="sections.xsl"/>
  41. <xsl:include href="inline.xsl"/>
  42. <xsl:include href="footnote.xsl"/>
  43. <xsl:include href="html.xsl"/>
  44. <xsl:include href="info.xsl"/>
  45. <xsl:include href="keywords.xsl"/>
  46. <xsl:include href="division.xsl"/>
  47. <xsl:include href="toc.xsl"/>
  48. <xsl:include href="index.xsl"/>
  49. <xsl:include href="refentry.xsl"/>
  50. <xsl:include href="math.xsl"/>
  51. <xsl:include href="admon.xsl"/>
  52. <xsl:include href="component.xsl"/>
  53. <xsl:include href="biblio.xsl"/>
  54. <xsl:include href="glossary.xsl"/>
  55. <xsl:include href="block.xsl"/>
  56. <xsl:include href="task.xsl"/>
  57. <xsl:include href="qandaset.xsl"/>
  58. <xsl:include href="synop.xsl"/>
  59. <xsl:include href="titlepage.xsl"/>
  60. <xsl:include href="titlepage.templates.xsl"/>
  61. <xsl:include href="pi.xsl"/>
  62. <xsl:include href="ebnf.xsl"/>
  63. <xsl:include href="chunker.xsl"/>
  64. <xsl:include href="html-rtf.xsl"/>
  65. <xsl:include href="docbookng.xsl"/>
  66. <xsl:param name="stylesheet.result.type" select="'html'"/>
  67. <xsl:param name="htmlhelp.output" select="0"/>
  68. <!-- ==================================================================== -->
  69. <xsl:key name="id" match="*" use="@id|@xml:id"/>
  70. <!-- ==================================================================== -->
  71. <xsl:template match="*">
  72. <xsl:message>
  73. <xsl:text>No template matches </xsl:text>
  74. <xsl:value-of select="name(.)"/>
  75. <xsl:if test="parent::*">
  76. <xsl:text> in </xsl:text>
  77. <xsl:value-of select="name(parent::*)"/>
  78. </xsl:if>
  79. <xsl:text>.</xsl:text>
  80. </xsl:message>
  81. <font color="red">
  82. <xsl:text>&lt;</xsl:text>
  83. <xsl:value-of select="name(.)"/>
  84. <xsl:text>&gt;</xsl:text>
  85. <xsl:apply-templates/>
  86. <xsl:text>&lt;/</xsl:text>
  87. <xsl:value-of select="name(.)"/>
  88. <xsl:text>&gt;</xsl:text>
  89. </font>
  90. </xsl:template>
  91. <xsl:template match="text()">
  92. <xsl:value-of select="."/>
  93. </xsl:template>
  94. <xsl:template name="body.attributes">
  95. <xsl:attribute name="bgcolor">white</xsl:attribute>
  96. <xsl:attribute name="text">black</xsl:attribute>
  97. <xsl:attribute name="link">#0000FF</xsl:attribute>
  98. <xsl:attribute name="vlink">#840084</xsl:attribute>
  99. <xsl:attribute name="alink">#0000FF</xsl:attribute>
  100. </xsl:template>
  101. <xsl:template name="head.content">
  102. <xsl:param name="node" select="."/>
  103. <xsl:param name="title">
  104. <xsl:apply-templates select="$node" mode="object.title.markup.textonly"/>
  105. </xsl:param>
  106. <title>
  107. <xsl:copy-of select="$title"/>
  108. </title>
  109. <xsl:if test="$html.stylesheet != ''">
  110. <xsl:call-template name="output.html.stylesheets">
  111. <xsl:with-param name="stylesheets" select="normalize-space($html.stylesheet)"/>
  112. </xsl:call-template>
  113. </xsl:if>
  114. <xsl:if test="$link.mailto.url != ''">
  115. <link rev="made"
  116. href="{$link.mailto.url}"/>
  117. </xsl:if>
  118. <xsl:if test="$html.base != ''">
  119. <base href="{$html.base}"/>
  120. </xsl:if>
  121. <meta name="generator" content="DocBook XSL Stylesheets V{$VERSION}"/>
  122. <link href="docbook.css" rel="stylesheet" type="text/css"/>
  123. <xsl:if test="$generate.meta.abstract != 0">
  124. <xsl:variable name="info" select="(articleinfo
  125. |bookinfo
  126. |prefaceinfo
  127. |chapterinfo
  128. |appendixinfo
  129. |sectioninfo
  130. |sect1info
  131. |sect2info
  132. |sect3info
  133. |sect4info
  134. |sect5info
  135. |referenceinfo
  136. |refentryinfo
  137. |partinfo
  138. |info
  139. |docinfo)[1]"/>
  140. <xsl:if test="$info and $info/abstract">
  141. <meta name="description">
  142. <xsl:attribute name="content">
  143. <xsl:for-each select="$info/abstract[1]/*">
  144. <xsl:value-of select="."/>
  145. <xsl:if test="position() &lt; last()">
  146. <xsl:text> </xsl:text>
  147. </xsl:if>
  148. </xsl:for-each>
  149. </xsl:attribute>
  150. </meta>
  151. </xsl:if>
  152. </xsl:if>
  153. <xsl:if test="($draft.mode = 'yes' or
  154. ($draft.mode = 'maybe' and
  155. ancestor-or-self::*[@status][1]/@status = 'draft'))
  156. and $draft.watermark.image != ''">
  157. <style type="text/css"><xsl:text>
  158. body { background-image: url('</xsl:text>
  159. <xsl:value-of select="$draft.watermark.image"/><xsl:text>');
  160. background-repeat: no-repeat;
  161. background-position: top left;
  162. /* The following properties make the watermark "fixed" on the page. */
  163. /* I think that's just a bit too distracting for the reader... */
  164. /* background-attachment: fixed; */
  165. /* background-position: center center; */
  166. }</xsl:text>
  167. </style>
  168. </xsl:if>
  169. <xsl:apply-templates select="." mode="head.keywords.content"/>
  170. </xsl:template>
  171. <xsl:template name="output.html.stylesheets">
  172. <xsl:param name="stylesheets" select="''"/>
  173. <xsl:choose>
  174. <xsl:when test="contains($stylesheets, ' ')">
  175. <link rel="stylesheet" href="{substring-before($stylesheets, ' ')}">
  176. <xsl:if test="$html.stylesheet.type != ''">
  177. <xsl:attribute name="type">
  178. <xsl:value-of select="$html.stylesheet.type"/>
  179. </xsl:attribute>
  180. </xsl:if>
  181. </link>
  182. <xsl:call-template name="output.html.stylesheets">
  183. <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
  184. </xsl:call-template>
  185. </xsl:when>
  186. <xsl:when test="$stylesheets != ''">
  187. <link rel="stylesheet" href="{$stylesheets}">
  188. <xsl:if test="$html.stylesheet.type != ''">
  189. <xsl:attribute name="type">
  190. <xsl:value-of select="$html.stylesheet.type"/>
  191. </xsl:attribute>
  192. </xsl:if>
  193. </link>
  194. </xsl:when>
  195. </xsl:choose>
  196. </xsl:template>
  197. <!-- ============================================================ -->
  198. <xsl:template match="*" mode="head.keywords.content">
  199. <xsl:apply-templates select="chapterinfo/keywordset" mode="html.header"/>
  200. <xsl:apply-templates select="appendixinfo/keywordset" mode="html.header"/>
  201. <xsl:apply-templates select="prefaceinfo/keywordset" mode="html.header"/>
  202. <xsl:apply-templates select="bookinfo/keywordset" mode="html.header"/>
  203. <xsl:apply-templates select="setinfo/keywordset" mode="html.header"/>
  204. <xsl:apply-templates select="articleinfo/keywordset" mode="html.header"/>
  205. <xsl:apply-templates select="artheader/keywordset" mode="html.header"/>
  206. <xsl:apply-templates select="sect1info/keywordset" mode="html.header"/>
  207. <xsl:apply-templates select="sect2info/keywordset" mode="html.header"/>
  208. <xsl:apply-templates select="sect3info/keywordset" mode="html.header"/>
  209. <xsl:apply-templates select="sect4info/keywordset" mode="html.header"/>
  210. <xsl:apply-templates select="sect5info/keywordset" mode="html.header"/>
  211. <xsl:apply-templates select="refsect1info/keywordset" mode="html.header"/>
  212. <xsl:apply-templates select="refsect2info/keywordset" mode="html.header"/>
  213. <xsl:apply-templates select="refsect3info/keywordset" mode="html.header"/>
  214. <xsl:apply-templates select="bibliographyinfo/keywordset" mode="html.header"/>
  215. <xsl:apply-templates select="glossaryinfo/keywordset" mode="html.header"/>
  216. <xsl:apply-templates select="indexinfo/keywordset" mode="html.header"/>
  217. <xsl:apply-templates select="refentryinfo/keywordset" mode="html.header"/>
  218. <xsl:apply-templates select="partinfo/keywordset" mode="html.header"/>
  219. <xsl:apply-templates select="referenceinfo/keywordset" mode="html.header"/>
  220. <xsl:apply-templates select="docinfo/keywordset" mode="html.header"/>
  221. <xsl:apply-templates select="info/keywordset" mode="html.header"/>
  222. <xsl:if test="$inherit.keywords != 0
  223. and parent::*">
  224. <xsl:apply-templates select="parent::*" mode="head.keywords.content"/>
  225. </xsl:if>
  226. </xsl:template>
  227. <!-- ============================================================ -->
  228. <xsl:template name="system.head.content">
  229. <xsl:param name="node" select="."/>
  230. <!-- system.head.content is like user.head.content, except that
  231. it is called before head.content. This is important because it
  232. means, for example, that <style> elements output by system.head.content
  233. have a lower CSS precedence than the users stylesheet. -->
  234. </xsl:template>
  235. <!-- ============================================================ -->
  236. <xsl:template name="user.preroot">
  237. <!-- Pre-root output, can be used to output comments and PIs. -->
  238. <!-- This must not output any element content! -->
  239. </xsl:template>
  240. <xsl:template name="user.head.content">
  241. <xsl:param name="node" select="."/>
  242. </xsl:template>
  243. <xsl:template name="user.header.navigation">
  244. <xsl:param name="node" select="."/>
  245. </xsl:template>
  246. <xsl:template name="user.header.content">
  247. <xsl:param name="node" select="."/>
  248. </xsl:template>
  249. <xsl:template name="user.footer.content">
  250. <xsl:param name="node" select="."/>
  251. </xsl:template>
  252. <xsl:template name="user.footer.navigation">
  253. <xsl:param name="node" select="."/>
  254. </xsl:template>
  255. <xsl:template match="/">
  256. <xsl:choose>
  257. <xsl:when test="function-available('exsl:node-set')
  258. and namespace-uri(*[1]) = 'http://docbook.org/docbook-ng'">
  259. <!-- Hack! If someone hands us a DocBook NG document, toss the namespace -->
  260. <!-- and continue. Someday we may reverse this logic and add the namespace -->
  261. <!-- to documents that don't have one. But not before the whole stylesheet -->
  262. <!-- has been converted to use namespaces. i.e., don't hold your breath -->
  263. <xsl:message>Stripping NS from DocBook-NG document.</xsl:message>
  264. <xsl:variable name="nons">
  265. <xsl:apply-templates mode="stripNS"/>
  266. </xsl:variable>
  267. <xsl:message>Processing stripped document.</xsl:message>
  268. <xsl:apply-templates select="exsl:node-set($nons)"/>
  269. </xsl:when>
  270. <xsl:otherwise>
  271. <xsl:choose>
  272. <xsl:when test="$rootid != ''">
  273. <xsl:choose>
  274. <xsl:when test="count(key('id',$rootid)) = 0">
  275. <xsl:message terminate="yes">
  276. <xsl:text>ID '</xsl:text>
  277. <xsl:value-of select="$rootid"/>
  278. <xsl:text>' not found in document.</xsl:text>
  279. </xsl:message>
  280. </xsl:when>
  281. <xsl:otherwise>
  282. <xsl:if test="$collect.xref.targets = 'yes' or
  283. $collect.xref.targets = 'only'">
  284. <xsl:apply-templates select="key('id', $rootid)"
  285. mode="collect.targets"/>
  286. </xsl:if>
  287. <xsl:if test="$collect.xref.targets != 'only'">
  288. <xsl:apply-templates select="key('id',$rootid)"
  289. mode="process.root"/>
  290. <xsl:if test="$tex.math.in.alt != ''">
  291. <xsl:apply-templates select="key('id',$rootid)"
  292. mode="collect.tex.math"/>
  293. </xsl:if>
  294. </xsl:if>
  295. </xsl:otherwise>
  296. </xsl:choose>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xsl:if test="$collect.xref.targets = 'yes' or
  300. $collect.xref.targets = 'only'">
  301. <xsl:apply-templates select="/" mode="collect.targets"/>
  302. </xsl:if>
  303. <xsl:if test="$collect.xref.targets != 'only'">
  304. <xsl:apply-templates select="/" mode="process.root"/>
  305. <xsl:if test="$tex.math.in.alt != ''">
  306. <xsl:apply-templates select="/" mode="collect.tex.math"/>
  307. </xsl:if>
  308. </xsl:if>
  309. </xsl:otherwise>
  310. </xsl:choose>
  311. </xsl:otherwise>
  312. </xsl:choose>
  313. </xsl:template>
  314. <xsl:template match="*" mode="process.root">
  315. <xsl:variable name="doc" select="self::*"/>
  316. <xsl:call-template name="user.preroot"/>
  317. <xsl:call-template name="root.messages"/>
  318. <html>
  319. <head>
  320. <xsl:call-template name="system.head.content">
  321. <xsl:with-param name="node" select="$doc"/>
  322. </xsl:call-template>
  323. <xsl:call-template name="head.content">
  324. <xsl:with-param name="node" select="$doc"/>
  325. </xsl:call-template>
  326. <xsl:call-template name="user.head.content">
  327. <xsl:with-param name="node" select="$doc"/>
  328. </xsl:call-template>
  329. </head>
  330. <body>
  331. <xsl:call-template name="body.attributes"/>
  332. <xsl:call-template name="user.header.content">
  333. <xsl:with-param name="node" select="$doc"/>
  334. </xsl:call-template>
  335. <xsl:apply-templates select="."/>
  336. <xsl:call-template name="user.footer.content">
  337. <xsl:with-param name="node" select="$doc"/>
  338. </xsl:call-template>
  339. </body>
  340. </html>
  341. </xsl:template>
  342. <xsl:template name="root.messages">
  343. <!-- redefine this any way you'd like to output messages -->
  344. <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
  345. </xsl:template>
  346. <!-- ==================================================================== -->
  347. <xsl:template name="chunk">
  348. <xsl:param name="node" select="."/>
  349. <!-- The default is that we are not chunking... -->
  350. <xsl:text>0</xsl:text>
  351. </xsl:template>
  352. <!-- ==================================================================== -->
  353. <xsl:template match="*" mode="stripNS">
  354. <xsl:choose>
  355. <xsl:when test="namespace-uri(.) = 'http://docbook.org/docbook-ng'">
  356. <xsl:element name="{local-name(.)}">
  357. <xsl:copy-of select="@*"/>
  358. <xsl:apply-templates mode="stripNS"/>
  359. </xsl:element>
  360. </xsl:when>
  361. <xsl:otherwise>
  362. <xsl:copy>
  363. <xsl:copy-of select="@*"/>
  364. <xsl:apply-templates mode="stripNS"/>
  365. </xsl:copy>
  366. </xsl:otherwise>
  367. </xsl:choose>
  368. </xsl:template>
  369. <xsl:template match="db:link" mode="stripNS">
  370. <xsl:variable xmlns:xlink="http://www.w3.org/1999/xlink"
  371. name="href" select="@xlink:href|@href"/>
  372. <xsl:choose>
  373. <xsl:when test="$href != '' and not(starts-with($href,'#'))">
  374. <ulink url="{$href}">
  375. <xsl:for-each select="@*">
  376. <xsl:if test="local-name(.) != 'href'">
  377. <xsl:copy/>
  378. </xsl:if>
  379. </xsl:for-each>
  380. <xsl:apply-templates mode="stripNS"/>
  381. </ulink>
  382. </xsl:when>
  383. <xsl:when test="$href != '' and starts-with($href,'#')">
  384. <link linkend="{substring-after($href,'#')}">
  385. <xsl:for-each select="@*">
  386. <xsl:if test="local-name(.) != 'href'">
  387. <xsl:copy/>
  388. </xsl:if>
  389. </xsl:for-each>
  390. <xsl:apply-templates mode="stripNS"/>
  391. </link>
  392. </xsl:when>
  393. <xsl:otherwise>
  394. <link>
  395. <xsl:copy-of select="@*"/>
  396. <xsl:apply-templates mode="stripNS"/>
  397. </link>
  398. </xsl:otherwise>
  399. </xsl:choose>
  400. </xsl:template>
  401. <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
  402. <xsl:copy/>
  403. </xsl:template>
  404. <!-- ==================================================================== -->
  405. </xsl:stylesheet>