docbook.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:exsl="http://exslt.org/common"
  4. xmlns:ng="http://docbook.org/docbook-ng"
  5. xmlns:db="http://docbook.org/ns/docbook"
  6. exclude-result-prefixes="exsl"
  7. version='1.0'>
  8. <xsl:import href="../html/docbook.xsl"/>
  9. <xsl:import href="../html/manifest.xsl"/>
  10. <!-- * html-synop.xsl file is generated by build -->
  11. <xsl:import href="html-synop.xsl"/>
  12. <xsl:output method="text"
  13. encoding="UTF-8"
  14. indent="no"/>
  15. <!-- ********************************************************************
  16. $Id: docbook.xsl 8841 2010-08-14 07:21:25Z mzjn $
  17. ********************************************************************
  18. This file is part of the XSL DocBook Stylesheet distribution.
  19. See ../README or http://docbook.sf.net/release/xsl/current/ for
  20. copyright and other information.
  21. ******************************************************************** -->
  22. <!-- ==================================================================== -->
  23. <xsl:include href="../common/refentry.xsl"/>
  24. <xsl:include href="../common/charmap.xsl"/>
  25. <xsl:include href="param.xsl"/>
  26. <xsl:include href="utility.xsl"/>
  27. <xsl:include href="info.xsl"/>
  28. <xsl:include href="other.xsl"/>
  29. <xsl:include href="refentry.xsl"/>
  30. <xsl:include href="block.xsl"/>
  31. <xsl:include href="inline.xsl"/>
  32. <xsl:include href="synop.xsl"/>
  33. <xsl:include href="lists.xsl"/>
  34. <xsl:include href="endnotes.xsl"/>
  35. <xsl:include href="table.xsl"/>
  36. <xsl:include href="pi.xsl"/>
  37. <!-- * we rename the following just to avoid using params with "man" -->
  38. <!-- * prefixes in the table.xsl stylesheet (because that stylesheet -->
  39. <!-- * can potentially be reused for more than just man output) -->
  40. <xsl:param name="tbl.font.headings" select="$man.font.table.headings"/>
  41. <xsl:param name="tbl.font.title" select="$man.font.table.title"/>
  42. <xsl:param name="stylesheet.result.type" select="'manpages'"/>
  43. <!-- ==================================================================== -->
  44. <xsl:template match="/">
  45. <!-- * Get a title for current doc so that we let the user -->
  46. <!-- * know what document we are processing at this point. -->
  47. <xsl:variable name="doc.title">
  48. <xsl:call-template name="get.doc.title"/>
  49. </xsl:variable>
  50. <xsl:choose>
  51. <!-- * when we find a namespaced document, strip the -->
  52. <!-- * namespace and then continue processing it. -->
  53. <xsl:when test="//self::db:*">
  54. <xsl:call-template name="log.message">
  55. <xsl:with-param name="level">Note</xsl:with-param>
  56. <xsl:with-param name="source" select="$doc.title"/>
  57. <xsl:with-param name="context-desc">
  58. <xsl:text>namesp. cut</xsl:text>
  59. </xsl:with-param>
  60. <xsl:with-param name="message">
  61. <xsl:text>stripped namespace before processing</xsl:text>
  62. </xsl:with-param>
  63. </xsl:call-template>
  64. <xsl:variable name="stripns">
  65. <xsl:apply-templates mode="stripNS"/>
  66. </xsl:variable>
  67. <xsl:call-template name="log.message">
  68. <xsl:with-param name="level">Note</xsl:with-param>
  69. <xsl:with-param name="source" select="$doc.title"/>
  70. <xsl:with-param name="context-desc">
  71. <xsl:text>namesp. cut</xsl:text>
  72. </xsl:with-param>
  73. <xsl:with-param name="message">
  74. <xsl:text>processing stripped document</xsl:text>
  75. </xsl:with-param>
  76. </xsl:call-template>
  77. <xsl:apply-templates select="exsl:node-set($stripns)"/>
  78. </xsl:when>
  79. <xsl:when test="//*[local-name() = 'refentry']">
  80. <!-- * Check to see if we have any refentry children in this -->
  81. <!-- * document; if so, process them. The reason we use -->
  82. <!-- * local-name()=refentry (instead of just //refentry) to to -->
  83. <!-- * check for refentry children is because this stylsheet is -->
  84. <!-- * also post-processed by the stylesheet build to create the -->
  85. <!-- * manpages/profile-docbook.xsl, and the refentry child check -->
  86. <!-- * in the profile-docbook.xsl stylesheet won't work if we do -->
  87. <!-- * a simple //refentry check. -->
  88. <xsl:apply-templates select="//refentry"/>
  89. <!-- * if $man.output.manifest.enabled is non-zero, -->
  90. <!-- * generate a manifest file -->
  91. <xsl:if test="not($man.output.manifest.enabled = 0)">
  92. <xsl:call-template name="generate.manifest">
  93. <xsl:with-param name="filename">
  94. <xsl:choose>
  95. <xsl:when test="not($man.output.manifest.filename = '')">
  96. <!-- * If a name for the manifest file is specified, -->
  97. <!-- * use that name. -->
  98. <xsl:value-of select="$man.output.manifest.filename"/>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <!-- * Otherwise, if user has unset -->
  102. <!-- * $man.output.manifest.filename, default to -->
  103. <!-- * using "MAN.MANIFEST" as the filename. Because -->
  104. <!-- * $man.output.manifest.enabled is non-zero and -->
  105. <!-- * so we must have a filename in order to -->
  106. <!-- * generate the manifest. -->
  107. <xsl:text>MAN.MANIFEST</xsl:text>
  108. </xsl:otherwise>
  109. </xsl:choose>
  110. </xsl:with-param>
  111. </xsl:call-template>
  112. </xsl:if>
  113. </xsl:when>
  114. <xsl:otherwise>
  115. <!-- * Otherwise, the document does not contain any -->
  116. <!-- * refentry elements, so log/emit message and stop. -->
  117. <xsl:call-template name="log.message">
  118. <xsl:with-param name="level">Erro</xsl:with-param>
  119. <xsl:with-param name="source" select="$doc.title"/>
  120. <xsl:with-param name="context-desc">
  121. <xsl:text> no refentry</xsl:text>
  122. </xsl:with-param>
  123. <xsl:with-param name="message">
  124. <xsl:text>No refentry elements found</xsl:text>
  125. <xsl:if test="$doc.title != ''">
  126. <xsl:text> in "</xsl:text>
  127. <xsl:choose>
  128. <xsl:when test="string-length($doc.title) &gt; 30">
  129. <xsl:value-of select="substring($doc.title,1,30)"/>
  130. <xsl:text>...</xsl:text>
  131. </xsl:when>
  132. <xsl:otherwise>
  133. <xsl:value-of select="$doc.title"/>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. <xsl:text>"</xsl:text>
  137. </xsl:if>
  138. <xsl:text>.</xsl:text>
  139. </xsl:with-param>
  140. </xsl:call-template>
  141. </xsl:otherwise>
  142. </xsl:choose>
  143. </xsl:template>
  144. <!-- ============================================================== -->
  145. <xsl:template match="refentry">
  146. <xsl:param name="lang">
  147. <xsl:call-template name="l10n.language"/>
  148. </xsl:param>
  149. <!-- * Just use the first refname found as the "name" of the man -->
  150. <!-- * page (which may different from the "title"...) -->
  151. <xsl:variable name="first.refname" select="refnamediv[1]/refname[1]"/>
  152. <xsl:call-template name="root.messages">
  153. <xsl:with-param name="refname" select="$first.refname"/>
  154. </xsl:call-template>
  155. <!-- * Because there are several times when we need to check *info of -->
  156. <!-- * each refentry and its ancestors, we get those and store the -->
  157. <!-- * data from them as a node-set in memory. -->
  158. <!-- * Make a node-set with contents of *info -->
  159. <xsl:variable name="get.info"
  160. select="ancestor-or-self::*/*[substring(local-name(),
  161. string-length(local-name()) - 3) = 'info']"
  162. />
  163. <xsl:variable name="info" select="exsl:node-set($get.info)"/>
  164. <!-- * The get.refentry.metadata template is in -->
  165. <!-- * ../common/refentry.xsl. It looks for metadata in $info -->
  166. <!-- * and in various other places and then puts it into a form -->
  167. <!-- * that's easier for us to digest. -->
  168. <xsl:variable name="get.refentry.metadata">
  169. <xsl:call-template name="get.refentry.metadata">
  170. <xsl:with-param name="refname" select="$first.refname"/>
  171. <xsl:with-param name="info" select="$info"/>
  172. <xsl:with-param name="prefs" select="$refentry.metadata.prefs"/>
  173. </xsl:call-template>
  174. </xsl:variable>
  175. <xsl:variable name="refentry.metadata" select="exsl:node-set($get.refentry.metadata)"/>
  176. <!-- * Assemble the various parts into a complete page, then store into -->
  177. <!-- * $manpage.contents so that we can manipluate them further. -->
  178. <xsl:variable name="manpage.contents">
  179. <!-- * preprocessor invocation (need for legacy AT&T troff use) -->
  180. <!-- * this tells troff to pre-process the page through tbl(1) -->
  181. <!-- * (groff can figure it out automatically, but AT&T troff can't) -->
  182. <xsl:text>'\" t&#10;</xsl:text>
  183. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  184. <!-- * top.comment = commented-out section at top of roff source -->
  185. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  186. <xsl:call-template name="top.comment">
  187. <xsl:with-param name="info" select="$info"/>
  188. <xsl:with-param name="date" select="$refentry.metadata/date"/>
  189. <xsl:with-param name="title" select="$refentry.metadata/title"/>
  190. <xsl:with-param name="manual" select="$refentry.metadata/manual"/>
  191. <xsl:with-param name="source" select="$refentry.metadata/source"/>
  192. <xsl:with-param name="refname" select="$first.refname"/>
  193. </xsl:call-template>
  194. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  195. <!-- * TH.title.line = title line in header/footer of man page -->
  196. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  197. <xsl:call-template name="TH.title.line">
  198. <!-- * .TH TITLE section extra1 extra2 extra3 -->
  199. <!-- * -->
  200. <!-- * According to the man(7) man page: -->
  201. <!-- * -->
  202. <!-- * extra1 = date, "the date of the last revision" -->
  203. <!-- * extra2 = source, "the source of the command" -->
  204. <!-- * extra3 = manual, "the title of the manual -->
  205. <!-- * (e.g., Linux Programmer's Manual)" -->
  206. <!-- * -->
  207. <!-- * So, we end up with: -->
  208. <!-- * -->
  209. <!-- * .TH TITLE section date source manual -->
  210. <!-- * -->
  211. <xsl:with-param name="title" select="$refentry.metadata/title"/>
  212. <xsl:with-param name="section" select="$refentry.metadata/section"/>
  213. <xsl:with-param name="extra1" select="$refentry.metadata/date"/>
  214. <xsl:with-param name="extra2" select="$refentry.metadata/source"/>
  215. <xsl:with-param name="extra3" select="$refentry.metadata/manual"/>
  216. </xsl:call-template>
  217. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  218. <!-- * (re)define some macros -->
  219. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  220. <xsl:call-template name="define.portability.macros"/>
  221. <xsl:if test="not($man.output.better.ps.enabled = 0)">
  222. <xsl:call-template name="define.macros"/>
  223. </xsl:if>
  224. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  225. <!-- * Set default hyphenation, justification, indentation, and -->
  226. <!-- * line-breaking -->
  227. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  228. <xsl:call-template name="set.default.formatting"/>
  229. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  230. <!-- * Main body of man page -->
  231. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  232. <xsl:text>.\" -----------------------------------------------------------------&#10;</xsl:text>
  233. <xsl:text>.\" * MAIN CONTENT STARTS HERE *&#10;</xsl:text>
  234. <xsl:text>.\" -----------------------------------------------------------------&#10;</xsl:text>
  235. <xsl:apply-templates/>
  236. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  237. <!-- * AUTHOR section -->
  238. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  239. <xsl:if test="not($man.authors.section.enabled = 0)">
  240. <xsl:call-template name="author.section">
  241. <xsl:with-param name="info" select="$info"/>
  242. </xsl:call-template>
  243. </xsl:if>
  244. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  245. <!-- * COPYRIGHT section -->
  246. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  247. <xsl:if test="not($man.copyright.section.enabled = 0)">
  248. <xsl:call-template name="copyright.section">
  249. <xsl:with-param name="info" select="$info"/>
  250. </xsl:call-template>
  251. </xsl:if>
  252. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  253. <!-- * NOTES list (only if user wants endnotes numbered and/or listed) -->
  254. <!-- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  255. <xsl:if test="$man.endnotes.list.enabled != 0 or
  256. $man.endnotes.are.numbered != 0">
  257. <xsl:call-template name="endnotes.list"/>
  258. </xsl:if>
  259. </xsl:variable> <!-- * end of manpage.contents -->
  260. <!-- * Prepare the page contents for final output, then store in -->
  261. <!-- * $manpage.contents.prepared so the we can pass it on to the -->
  262. <!-- * write.text.chunk() function -->
  263. <xsl:variable name="manpage.contents.prepared">
  264. <!-- * "Preparing" the page contents involves, at a minimum, -->
  265. <!-- * doubling any backslashes found (so they aren't interpreted -->
  266. <!-- * as roff escapes). -->
  267. <!-- * -->
  268. <!-- * If $charmap.enabled is true, "preparing" the page contents also -->
  269. <!-- * involves applying a character map to convert Unicode symbols and -->
  270. <!-- * special characters into corresponding roff escape sequences. -->
  271. <xsl:call-template name="prepare.manpage.contents">
  272. <xsl:with-param name="content" select="$manpage.contents"/>
  273. </xsl:call-template>
  274. </xsl:variable>
  275. <!-- * Write the prepared page contents to disk to create -->
  276. <!-- * the final man page. -->
  277. <xsl:call-template name="write.man.file">
  278. <xsl:with-param name="name" select="$first.refname"/>
  279. <xsl:with-param name="section" select="$refentry.metadata/section"/>
  280. <xsl:with-param name="lang" select="$lang"/>
  281. <xsl:with-param name="content" select="$manpage.contents.prepared"/>
  282. </xsl:call-template>
  283. <!-- * Generate "stub" (alias) pages (if any needed) -->
  284. <xsl:call-template name="write.stubs">
  285. <xsl:with-param name="first.refname" select="$first.refname"/>
  286. <xsl:with-param name="section" select="$refentry.metadata/section"/>
  287. <xsl:with-param name="lang" select="$lang"/>
  288. </xsl:call-template>
  289. </xsl:template>
  290. </xsl:stylesheet>