1
0

refentry.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version='1.0'>
  4. <!-- ********************************************************************
  5. $Id: refentry.xsl 8235 2009-02-09 16:22:14Z xmldoc $
  6. ********************************************************************
  7. This file is part of the XSL DocBook Stylesheet distribution.
  8. See ../README or http://docbook.sf.net/release/xsl/current/ for
  9. copyright and other information.
  10. ******************************************************************** -->
  11. <!-- ==================================================================== -->
  12. <xsl:template match="refnamediv">
  13. <xsl:choose>
  14. <xsl:when test="preceding-sibling::refnamediv">
  15. <!-- * No title on secondary refnamedivs! -->
  16. <!-- * Just put a single line break instead -->
  17. <xsl:text>.br&#10;</xsl:text>
  18. </xsl:when>
  19. <xsl:otherwise>
  20. <xsl:call-template name="make.subheading">
  21. <xsl:with-param name="title">
  22. <xsl:apply-templates select="." mode="subheading.markup"/>
  23. </xsl:with-param>
  24. </xsl:call-template>
  25. </xsl:otherwise>
  26. </xsl:choose>
  27. <xsl:call-template name="mark.subheading"/>
  28. <!-- * if we have multiple Refname instances, separate the names -->
  29. <!-- * with commas -->
  30. <xsl:for-each select="refname">
  31. <xsl:if test="position()>1">
  32. <xsl:text>, </xsl:text>
  33. </xsl:if>
  34. <xsl:call-template name="string.subst">
  35. <!-- * To create the name(s) for this man page, replace any -->
  36. <!-- * spaces in the refname(s) with underscores. This ensures -->
  37. <!-- * that tools like lexgrog(1) will be able to parse the name -->
  38. <!-- * (lexgrog won’t parse names that contain spaces). -->
  39. <xsl:with-param name="string" select="."/>
  40. <xsl:with-param name="target" select="' '"/>
  41. <xsl:with-param name="replacement" select="'_'"/>
  42. </xsl:call-template>
  43. </xsl:for-each>
  44. <!-- * The man(7) man pages says: -->
  45. <!-- * -->
  46. <!-- * The only required heading is NAME, which should be the -->
  47. <!-- * first section and be followed on the next line by a one -->
  48. <!-- * line description of the program: -->
  49. <!-- * -->
  50. <!-- * .SH NAME chess \- the game of chess -->
  51. <!-- * -->
  52. <!-- * It is extremely important that this format is followed, -->
  53. <!-- * and that there is a backslash before the single dash -->
  54. <!-- * which follows the command name. This syntax is used by -->
  55. <!-- * the makewhatis(8) program to create a database of short -->
  56. <!-- * command descriptions for the whatis(1) and apropos(1) -->
  57. <!-- * commands. -->
  58. <!-- * -->
  59. <xsl:if test="refpurpose/node()">
  60. <xsl:text> \- </xsl:text>
  61. <xsl:variable name="refpurpose">
  62. <xsl:apply-templates select="refpurpose/node()"/>
  63. </xsl:variable>
  64. <xsl:value-of select="normalize-space($refpurpose)"/>
  65. </xsl:if>
  66. <xsl:text>&#10;</xsl:text>
  67. </xsl:template>
  68. <xsl:template match="refsynopsisdiv">
  69. <xsl:call-template name="make.subheading">
  70. <xsl:with-param name="title">
  71. <xsl:apply-templates select="." mode="subheading.markup"/>
  72. </xsl:with-param>
  73. </xsl:call-template>
  74. <xsl:apply-templates/>
  75. </xsl:template>
  76. <xsl:template match="refsect1|refentry/refsection">
  77. <xsl:variable name="title">
  78. <xsl:apply-templates select="." mode="subheading.markup"/>
  79. </xsl:variable>
  80. <xsl:call-template name="make.subheading">
  81. <xsl:with-param name="title">
  82. <xsl:value-of select="normalize-space($title)"/>
  83. </xsl:with-param>
  84. </xsl:call-template>
  85. <xsl:apply-templates/>
  86. </xsl:template>
  87. <xsl:template match="refsect2|refentry/refsection/refsection">
  88. <xsl:call-template name="mark.subheading"/>
  89. <xsl:variable name="title">
  90. <xsl:apply-templates
  91. select="(info/title
  92. |refsectioninfo/title
  93. |refsect1info/title
  94. |title)[1]/node()"/>
  95. </xsl:variable>
  96. <xsl:text>.SS "</xsl:text>
  97. <xsl:value-of select="normalize-space($title)"/>
  98. <xsl:text>"&#10;</xsl:text>
  99. <xsl:call-template name="mark.subheading"/>
  100. <xsl:choose>
  101. <!-- * If default-indentation adjustment is on, then indent the -->
  102. <!-- * child content of this Refsect2 -->
  103. <xsl:when test="not($man.indent.refsect = 0)">
  104. <xsl:text>.RS&#10;</xsl:text>
  105. <xsl:apply-templates/>
  106. <xsl:text>.RE&#10;</xsl:text>
  107. </xsl:when>
  108. <xsl:otherwise>
  109. <!-- * If default-indentation adjustment is on, then do not -->
  110. <!-- * indent the child content of this Refsect2, because -->
  111. <!-- * the title is already "sticking out to the left" -->
  112. <!-- * (as the groff_man(7) man page describes it), which -->
  113. <!-- * actually means the title is indented by the value of -->
  114. <!-- * the SN register, which appears by default to be -->
  115. <!-- * about half of the default indentation value -->
  116. <xsl:apply-templates/>
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:template>
  120. <xsl:template match="refsect3|refentry/refsection/refsection/refsection">
  121. <xsl:variable name="title">
  122. <xsl:value-of select="(info/title
  123. |refsectioninfo/title
  124. |refsect1info/title
  125. |title)[1]"/>
  126. </xsl:variable>
  127. <xsl:choose>
  128. <!-- * If default-indentation adjustment is on, then indent the -->
  129. <!-- * child content of this Refsect3 or Refsection. -->
  130. <xsl:when test="not($man.indent.refsect != 0)">
  131. <xsl:call-template name="nested-section-title"/>
  132. <xsl:text>.RS</xsl:text>
  133. <xsl:if test="not($man.indent.width = '')">
  134. <xsl:text> </xsl:text>
  135. <xsl:value-of select="$man.indent.width"/>
  136. </xsl:if>
  137. <xsl:text>&#10;</xsl:text>
  138. <xsl:apply-templates/>
  139. <xsl:text>.RE&#10;</xsl:text>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <!-- * If default-indentation adjustment is on, then do not -->
  143. <!-- * indent the child content of this Refsect2, because -->
  144. <!-- * the title is already "sticking out to the left" -->
  145. <!-- * (as the groff_man(7) man page describes it), which -->
  146. <!-- * actually means the title is indented by the value of -->
  147. <!-- * the SN register, which appears by default to be -->
  148. <!-- * about half of the default indentation value -->
  149. <xsl:text>.ti (\n(SNu * 5u / 3u)&#10;</xsl:text>
  150. <xsl:call-template name="nested-section-title"/>
  151. <xsl:apply-templates/>
  152. </xsl:otherwise>
  153. </xsl:choose>
  154. </xsl:template>
  155. <xsl:template match="refsection">
  156. <!-- * This template is used for a nested Refsection that is -->
  157. <!-- * is a child of a Refsect3-level section (The numberd -->
  158. <!-- * Refsect hierarchy in DocBook ends with Refsect3, so -->
  159. <!-- * there is not actually a Refsect4 element.) -->
  160. <xsl:variable name="title">
  161. <xsl:value-of select="(info/title
  162. |refsectioninfo/title
  163. |refsect1info/title
  164. |title)[1]"/>
  165. </xsl:variable>
  166. <xsl:variable name="indent-width">
  167. <xsl:if test="not($man.indent.refsect = 0)">
  168. <!-- * If default-indentation adjustment is on, then indent the -->
  169. <!-- * child content of this Refsect3 or Refsection. -->
  170. <xsl:text>(\n(SNu)&#10;</xsl:text>
  171. </xsl:if>
  172. </xsl:variable>
  173. <xsl:call-template name="nested-section-title"/>
  174. <xsl:text>.RS (\n(SNu)&#10;</xsl:text>
  175. <xsl:apply-templates/>
  176. <xsl:text>.RE&#10;</xsl:text>
  177. </xsl:template>
  178. <!-- ==================================================================== -->
  179. <xsl:template match="refsect1|refentry/refsection"
  180. mode="subheading.markup">
  181. <xsl:variable name="title" select="(info/title
  182. |refsectioninfo/title
  183. |refsect1info/title
  184. |title)[1]"/>
  185. <xsl:apply-templates select="$title" mode="title.markup"/>
  186. </xsl:template>
  187. <xsl:template match="refsect1|refentry/refsection"
  188. mode="title.markup">
  189. <!-- * Note: This template is used just for generating the text for -->
  190. <!-- * cross-references to Refsect1 or top-level Refsection instances. -->
  191. <xsl:variable name="title" select="(info/title
  192. |refsectioninfo/title
  193. |refsect1info/title
  194. |title)[1]"/>
  195. <xsl:call-template name="process.SH.xref">
  196. <xsl:with-param name="title">
  197. <xsl:apply-templates select="$title" mode="title.markup"/>
  198. </xsl:with-param>
  199. </xsl:call-template>
  200. </xsl:template>
  201. <!-- * Output of Titles from Xref with Endterm needs to be handled -->
  202. <!-- * separately from output for Endterm-less Xref -->
  203. <xsl:template match="refsect1/title
  204. |refentry/refsection/title
  205. |refsynopsisdiv/title"
  206. mode="endterm">
  207. <xsl:call-template name="process.SH.xref">
  208. <xsl:with-param name="title">
  209. <xsl:apply-templates/>
  210. </xsl:with-param>
  211. </xsl:call-template>
  212. </xsl:template>
  213. <xsl:template match="refsynopsisdiv" mode="subheading.markup">
  214. <xsl:param name="allow-anchors" select="0"/>
  215. <xsl:variable name="title">
  216. <xsl:call-template name="get.refsynopsisdiv.title">
  217. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  218. </xsl:call-template>
  219. </xsl:variable>
  220. <xsl:value-of select="$title"/>
  221. </xsl:template>
  222. <xsl:template match="refsynopsisdiv" mode="title.markup">
  223. <!-- * Note: This template is used just for generating the text for -->
  224. <!-- * cross-references to Refsynopsisdiv instances. -->
  225. <xsl:param name="allow-anchors" select="0"/>
  226. <xsl:variable name="title">
  227. <xsl:call-template name="get.refsynopsisdiv.title">
  228. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  229. </xsl:call-template>
  230. </xsl:variable>
  231. <xsl:call-template name="process.SH.xref">
  232. <xsl:with-param name="title" select="$title"/>
  233. </xsl:call-template>
  234. </xsl:template>
  235. <xsl:template name="get.refsynopsisdiv.title">
  236. <xsl:param name="allow-anchors"/>
  237. <xsl:choose>
  238. <xsl:when test="info/title
  239. |refsynopsisdivinfo/title
  240. |title">
  241. <xsl:apply-templates
  242. select="(info/title
  243. |refsynopsisdivinfo/title
  244. |title)[1]" mode="title.markup">
  245. <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
  246. </xsl:apply-templates>
  247. </xsl:when>
  248. <xsl:otherwise>
  249. <xsl:call-template name="gentext">
  250. <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
  251. </xsl:call-template>
  252. </xsl:otherwise>
  253. </xsl:choose>
  254. </xsl:template>
  255. <xsl:template match="refnamediv" mode="subheading.markup">
  256. <xsl:call-template name="gentext">
  257. <xsl:with-param name="key" select="'RefName'"/>
  258. </xsl:call-template>
  259. </xsl:template>
  260. <xsl:template match="refnamediv" mode="title.markup">
  261. <xsl:call-template name="process.SH.xref">
  262. <xsl:with-param name="title">
  263. <xsl:call-template name="gentext">
  264. <xsl:with-param name="key" select="'RefName'"/>
  265. </xsl:call-template>
  266. </xsl:with-param>
  267. </xsl:call-template>
  268. </xsl:template>
  269. <xsl:template match="refnamediv" mode="xref-to">
  270. <xsl:apply-templates select="." mode="title.markup"/>
  271. </xsl:template>
  272. <!-- * suppress any title we don't otherwise process elsewhere -->
  273. <xsl:template match="title"/>
  274. <!-- ==================================================================== -->
  275. <xsl:template name="process.SH.xref">
  276. <xsl:param name="title"/>
  277. <xsl:choose>
  278. <xsl:when test="not($man.output.better.ps.enabled = 0)">
  279. <xsl:text>\c</xsl:text>
  280. <xsl:text>&#x2592;</xsl:text>
  281. <xsl:text>.SH-xref </xsl:text>
  282. <xsl:text>"</xsl:text>
  283. <xsl:value-of select="$title"/>
  284. <xsl:text>\c"</xsl:text>
  285. <xsl:text>&#x2592;</xsl:text>
  286. <xsl:text>\&amp;</xsl:text>
  287. </xsl:when>
  288. <xsl:otherwise>
  289. <xsl:call-template name="string.upper">
  290. <xsl:with-param name="string" select="$title"/>
  291. </xsl:call-template>
  292. </xsl:otherwise>
  293. </xsl:choose>
  294. </xsl:template>
  295. </xsl:stylesheet>