formal.xsl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?xml version="1.0" encoding="ASCII"?>
  2. <!--This file was created automatically by html2xhtml-->
  3. <!--from the HTML stylesheets.-->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
  5. <!-- ********************************************************************
  6. $Id: formal.xsl 9501 2012-07-16 00:14:50Z bobstayton $
  7. ********************************************************************
  8. This file is part of the XSL DocBook Stylesheet distribution.
  9. See ../README or http://docbook.sf.net/release/xsl/current/ for
  10. copyright and other information.
  11. ******************************************************************** -->
  12. <xsl:param name="formal.object.break.after">1</xsl:param>
  13. <xsl:template name="formal.object">
  14. <xsl:param name="placement" select="'before'"/>
  15. <xsl:param name="class">
  16. <xsl:apply-templates select="." mode="class.value"/>
  17. </xsl:param>
  18. <xsl:call-template name="id.warning"/>
  19. <xsl:variable name="content">
  20. <div class="{$class}">
  21. <xsl:call-template name="id.attribute">
  22. <xsl:with-param name="conditional" select="0"/>
  23. </xsl:call-template>
  24. <xsl:call-template name="anchor">
  25. <xsl:with-param name="conditional" select="0"/>
  26. </xsl:call-template>
  27. <xsl:choose>
  28. <xsl:when test="$placement = 'before'">
  29. <xsl:call-template name="formal.object.heading"/>
  30. <div class="{$class}-contents">
  31. <xsl:apply-templates/>
  32. </div>
  33. <!-- HACK: This doesn't belong inside formal.object; it
  34. should be done by the table template, but I want
  35. the link to be inside the DIV, so... -->
  36. <xsl:if test="local-name(.) = 'table'">
  37. <xsl:call-template name="table.longdesc"/>
  38. </xsl:if>
  39. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  40. </xsl:when>
  41. <xsl:otherwise>
  42. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  43. <div class="{$class}-contents"><xsl:apply-templates/></div>
  44. <!-- HACK: This doesn't belong inside formal.object; it
  45. should be done by the table template, but I want
  46. the link to be inside the DIV, so... -->
  47. <xsl:if test="local-name(.) = 'table'">
  48. <xsl:call-template name="table.longdesc"/>
  49. </xsl:if>
  50. <xsl:call-template name="formal.object.heading"/>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. </div>
  54. <xsl:if test="not($formal.object.break.after = '0')">
  55. <br class="{$class}-break"/>
  56. </xsl:if>
  57. </xsl:variable>
  58. <xsl:variable name="floatstyle">
  59. <xsl:call-template name="floatstyle"/>
  60. </xsl:variable>
  61. <xsl:choose>
  62. <xsl:when test="$floatstyle != ''">
  63. <xsl:call-template name="floater">
  64. <xsl:with-param name="class"><xsl:value-of select="$class"/>-float</xsl:with-param>
  65. <xsl:with-param name="floatstyle" select="$floatstyle"/>
  66. <xsl:with-param name="content" select="$content"/>
  67. </xsl:call-template>
  68. </xsl:when>
  69. <xsl:otherwise>
  70. <xsl:copy-of select="$content"/>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. </xsl:template>
  74. <xsl:template name="formal.object.heading">
  75. <xsl:param name="object" select="."/>
  76. <xsl:param name="title">
  77. <xsl:apply-templates select="$object" mode="object.title.markup">
  78. <xsl:with-param name="allow-anchors" select="1"/>
  79. </xsl:apply-templates>
  80. </xsl:param>
  81. <xsl:choose>
  82. <xsl:when test="$make.clean.html != 0">
  83. <xsl:variable name="html.class" select="concat(local-name($object),'-title')"/>
  84. <div class="{$html.class}">
  85. <xsl:copy-of select="$title"/>
  86. </div>
  87. </xsl:when>
  88. <xsl:otherwise>
  89. <p class="title">
  90. <strong xmlns:xslo="http://www.w3.org/1999/XSL/Transform">
  91. <xsl:copy-of select="$title"/>
  92. </strong>
  93. </p>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:template>
  97. <xsl:template name="informal.object">
  98. <xsl:param name="class">
  99. <xsl:apply-templates select="." mode="class.value"/>
  100. </xsl:param>
  101. <xsl:variable name="content">
  102. <div class="{$class}">
  103. <xsl:call-template name="id.attribute"/>
  104. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  105. <xsl:call-template name="anchor"/>
  106. <xsl:apply-templates/>
  107. <!-- HACK: This doesn't belong inside formal.object; it
  108. should be done by the table template, but I want
  109. the link to be inside the DIV, so... -->
  110. <xsl:if test="local-name(.) = 'informaltable'">
  111. <xsl:call-template name="table.longdesc"/>
  112. </xsl:if>
  113. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  114. </div>
  115. </xsl:variable>
  116. <xsl:variable name="floatstyle">
  117. <xsl:call-template name="floatstyle"/>
  118. </xsl:variable>
  119. <xsl:choose>
  120. <xsl:when test="$floatstyle != ''">
  121. <xsl:call-template name="floater">
  122. <xsl:with-param name="class"><xsl:value-of select="$class"/>-float</xsl:with-param>
  123. <xsl:with-param name="floatstyle" select="$floatstyle"/>
  124. <xsl:with-param name="content" select="$content"/>
  125. </xsl:call-template>
  126. </xsl:when>
  127. <xsl:otherwise>
  128. <xsl:copy-of select="$content"/>
  129. </xsl:otherwise>
  130. </xsl:choose>
  131. </xsl:template>
  132. <xsl:template name="semiformal.object">
  133. <xsl:param name="placement" select="'before'"/>
  134. <xsl:param name="class" select="local-name(.)"/>
  135. <xsl:choose>
  136. <xsl:when test="title or info/title">
  137. <xsl:call-template name="formal.object">
  138. <xsl:with-param name="placement" select="$placement"/>
  139. <xsl:with-param name="class" select="$class"/>
  140. </xsl:call-template>
  141. </xsl:when>
  142. <xsl:otherwise>
  143. <xsl:call-template name="informal.object">
  144. <xsl:with-param name="class" select="$class"/>
  145. </xsl:call-template>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:template>
  149. <xsl:template match="figure">
  150. <xsl:variable name="param.placement" select="substring-after(normalize-space($formal.title.placement), concat(local-name(.), ' '))"/>
  151. <xsl:variable name="placement">
  152. <xsl:choose>
  153. <xsl:when test="contains($param.placement, ' ')">
  154. <xsl:value-of select="substring-before($param.placement, ' ')"/>
  155. </xsl:when>
  156. <xsl:when test="$param.placement = ''">before</xsl:when>
  157. <xsl:otherwise>
  158. <xsl:value-of select="$param.placement"/>
  159. </xsl:otherwise>
  160. </xsl:choose>
  161. </xsl:variable>
  162. <xsl:call-template name="formal.object">
  163. <xsl:with-param name="placement" select="$placement"/>
  164. </xsl:call-template>
  165. </xsl:template>
  166. <xsl:template match="table">
  167. <xsl:choose>
  168. <xsl:when test="tgroup|mediaobject|graphic">
  169. <xsl:call-template name="calsTable"/>
  170. </xsl:when>
  171. <xsl:when test="caption">
  172. <xsl:call-template name="htmlTable.with.caption"/>
  173. </xsl:when>
  174. <xsl:otherwise>
  175. <!-- do not use xsl:copy because of XHTML's needs -->
  176. <div>
  177. <xsl:call-template name="generate.class.attribute"/>
  178. <xsl:call-template name="id.attribute"/>
  179. <xsl:call-template name="anchor"/>
  180. <xsl:element name="table" namespace="http://www.w3.org/1999/xhtml">
  181. <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
  182. <xsl:call-template name="htmlTable"/>
  183. </xsl:element>
  184. </div>
  185. </xsl:otherwise>
  186. </xsl:choose>
  187. </xsl:template>
  188. <!-- Handle html markup table like formal.object -->
  189. <xsl:template name="htmlTable.with.caption">
  190. <xsl:param name="class">
  191. <xsl:apply-templates select="." mode="class.value"/>
  192. </xsl:param>
  193. <xsl:variable name="param.placement" select="substring-after(normalize-space($formal.title.placement), concat(local-name(.), ' '))"/>
  194. <xsl:variable name="placement">
  195. <xsl:choose>
  196. <xsl:when test="contains($param.placement, ' ')">
  197. <xsl:value-of select="substring-before($param.placement, ' ')"/>
  198. </xsl:when>
  199. <xsl:when test="$param.placement = ''">before</xsl:when>
  200. <xsl:otherwise>
  201. <xsl:value-of select="$param.placement"/>
  202. </xsl:otherwise>
  203. </xsl:choose>
  204. </xsl:variable>
  205. <xsl:call-template name="id.warning"/>
  206. <xsl:variable name="content">
  207. <div class="{$class}">
  208. <xsl:call-template name="id.attribute">
  209. <xsl:with-param name="conditional" select="0"/>
  210. </xsl:call-template>
  211. <xsl:call-template name="anchor">
  212. <xsl:with-param name="conditional" select="0"/>
  213. </xsl:call-template>
  214. <xsl:choose>
  215. <xsl:when test="$placement = 'before'">
  216. <xsl:call-template name="formal.object.heading"/>
  217. <div class="{$class}-contents">
  218. <xsl:apply-templates select="." mode="htmlTable"/>
  219. </div>
  220. <xsl:call-template name="table.longdesc"/>
  221. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  222. </xsl:when>
  223. <xsl:otherwise>
  224. <xsl:if test="$spacing.paras != 0"><p/></xsl:if>
  225. <div class="{$class}-contents">
  226. <xsl:apply-templates select="." mode="htmlTable"/>
  227. </div>
  228. <xsl:call-template name="table.longdesc"/>
  229. <xsl:call-template name="formal.object.heading"/>
  230. </xsl:otherwise>
  231. </xsl:choose>
  232. </div>
  233. <xsl:if test="not($formal.object.break.after = '0')">
  234. <br class="{$class}-break"/>
  235. </xsl:if>
  236. </xsl:variable>
  237. <xsl:variable name="floatstyle">
  238. <xsl:call-template name="floatstyle"/>
  239. </xsl:variable>
  240. <xsl:choose>
  241. <xsl:when test="$floatstyle != ''">
  242. <xsl:call-template name="floater">
  243. <xsl:with-param name="class"><xsl:value-of select="$class"/>-float</xsl:with-param>
  244. <xsl:with-param name="floatstyle" select="$floatstyle"/>
  245. <xsl:with-param name="content" select="$content"/>
  246. </xsl:call-template>
  247. </xsl:when>
  248. <xsl:otherwise>
  249. <xsl:copy-of select="$content"/>
  250. </xsl:otherwise>
  251. </xsl:choose>
  252. </xsl:template>
  253. <xsl:template name="calsTable">
  254. <xsl:if test="tgroup/tbody/tr |tgroup/thead/tr |tgroup/tfoot/tr">
  255. <xsl:message terminate="yes">Broken table: tr descendent of CALS Table.</xsl:message>
  256. </xsl:if>
  257. <xsl:variable name="param.placement" select="substring-after(normalize-space($formal.title.placement), concat(local-name(.), ' '))"/>
  258. <xsl:variable name="placement">
  259. <xsl:choose>
  260. <xsl:when test="contains($param.placement, ' ')">
  261. <xsl:value-of select="substring-before($param.placement, ' ')"/>
  262. </xsl:when>
  263. <xsl:when test="$param.placement = ''">before</xsl:when>
  264. <xsl:otherwise>
  265. <xsl:value-of select="$param.placement"/>
  266. </xsl:otherwise>
  267. </xsl:choose>
  268. </xsl:variable>
  269. <xsl:call-template name="formal.object">
  270. <xsl:with-param name="placement" select="$placement"/>
  271. </xsl:call-template>
  272. </xsl:template>
  273. <xsl:template match="table|informaltable" mode="class.value">
  274. <xsl:choose>
  275. <xsl:when test="@tabstyle">
  276. <xsl:value-of select="@tabstyle"/>
  277. </xsl:when>
  278. <xsl:otherwise>
  279. <xsl:value-of select="local-name(.)"/>
  280. </xsl:otherwise>
  281. </xsl:choose>
  282. </xsl:template>
  283. <xsl:template name="htmlTable">
  284. <xsl:if test="tgroup/tbody/row |tgroup/thead/row |tgroup/tfoot/row">
  285. <xsl:message terminate="yes">Broken table: row descendent of HTML table.</xsl:message>
  286. </xsl:if>
  287. <xsl:apply-templates mode="htmlTable"/>
  288. <xsl:if test=".//footnote|../title//footnote">
  289. <tbody class="footnotes">
  290. <tr>
  291. <td colspan="50">
  292. <xsl:apply-templates select=".//footnote|../title//footnote" mode="table.footnote.mode"/>
  293. </td>
  294. </tr>
  295. </tbody>
  296. </xsl:if>
  297. </xsl:template>
  298. <xsl:template match="example">
  299. <xsl:variable name="param.placement" select="substring-after(normalize-space($formal.title.placement), concat(local-name(.), ' '))"/>
  300. <xsl:variable name="placement">
  301. <xsl:choose>
  302. <xsl:when test="contains($param.placement, ' ')">
  303. <xsl:value-of select="substring-before($param.placement, ' ')"/>
  304. </xsl:when>
  305. <xsl:when test="$param.placement = ''">before</xsl:when>
  306. <xsl:otherwise>
  307. <xsl:value-of select="$param.placement"/>
  308. </xsl:otherwise>
  309. </xsl:choose>
  310. </xsl:variable>
  311. <xsl:call-template name="formal.object">
  312. <xsl:with-param name="placement" select="$placement"/>
  313. </xsl:call-template>
  314. </xsl:template>
  315. <xsl:template match="equation">
  316. <xsl:variable name="param.placement" select="substring-after(normalize-space($formal.title.placement), concat(local-name(.), ' '))"/>
  317. <xsl:variable name="placement">
  318. <xsl:choose>
  319. <xsl:when test="contains($param.placement, ' ')">
  320. <xsl:value-of select="substring-before($param.placement, ' ')"/>
  321. </xsl:when>
  322. <xsl:when test="$param.placement = ''">before</xsl:when>
  323. <xsl:otherwise>
  324. <xsl:value-of select="$param.placement"/>
  325. </xsl:otherwise>
  326. </xsl:choose>
  327. </xsl:variable>
  328. <xsl:call-template name="formal.object">
  329. <xsl:with-param name="placement" select="$placement"/>
  330. </xsl:call-template>
  331. </xsl:template>
  332. <xsl:template match="figure/title"/>
  333. <xsl:template match="figure/titleabbrev"/>
  334. <xsl:template match="table/title"/>
  335. <xsl:template match="table/titleabbrev"/>
  336. <xsl:template match="table/textobject"/>
  337. <xsl:template match="example/title"/>
  338. <xsl:template match="example/titleabbrev"/>
  339. <xsl:template match="equation/title"/>
  340. <xsl:template match="equation/titleabbrev"/>
  341. <xsl:template match="informalfigure">
  342. <xsl:call-template name="informal.object"/>
  343. </xsl:template>
  344. <xsl:template match="informalexample">
  345. <xsl:call-template name="informal.object"/>
  346. </xsl:template>
  347. <xsl:template match="informaltable">
  348. <xsl:choose>
  349. <xsl:when test="tgroup|mediaobject|graphic">
  350. <xsl:call-template name="informal.object"/>
  351. </xsl:when>
  352. <xsl:otherwise>
  353. <div>
  354. <xsl:call-template name="generate.class.attribute"/>
  355. <xsl:call-template name="id.attribute"/>
  356. <xsl:call-template name="anchor"/>
  357. <xsl:element name="table" namespace="http://www.w3.org/1999/xhtml">
  358. <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
  359. <xsl:call-template name="htmlTable"/>
  360. </xsl:element>
  361. </div>
  362. </xsl:otherwise>
  363. </xsl:choose>
  364. </xsl:template>
  365. <xsl:template match="informaltable/textobject"/>
  366. <xsl:template name="table.longdesc">
  367. <!-- HACK: This doesn't belong inside formal.objectt; it should be done by -->
  368. <!-- the table template, but I want the link to be inside the DIV, so... -->
  369. <xsl:variable name="longdesc.uri">
  370. <xsl:call-template name="longdesc.uri">
  371. <xsl:with-param name="mediaobject" select="."/>
  372. </xsl:call-template>
  373. </xsl:variable>
  374. <xsl:variable name="irrelevant">
  375. <!-- write.longdesc returns the filename ... -->
  376. <xsl:call-template name="write.longdesc">
  377. <xsl:with-param name="mediaobject" select="."/>
  378. </xsl:call-template>
  379. </xsl:variable>
  380. <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0 and textobject[not(phrase)]">
  381. <xsl:call-template name="longdesc.link">
  382. <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
  383. </xsl:call-template>
  384. </xsl:if>
  385. </xsl:template>
  386. <xsl:template match="informalequation">
  387. <xsl:call-template name="informal.object"/>
  388. </xsl:template>
  389. <xsl:template name="floatstyle">
  390. <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
  391. <xsl:choose>
  392. <xsl:when test="@floatstyle != ''">
  393. <xsl:value-of select="@floatstyle"/>
  394. </xsl:when>
  395. <xsl:when test="@float = '1'">
  396. <xsl:value-of select="$default.float.class"/>
  397. </xsl:when>
  398. <xsl:otherwise>
  399. <xsl:value-of select="@float"/>
  400. </xsl:otherwise>
  401. </xsl:choose>
  402. </xsl:if>
  403. </xsl:template>
  404. <xsl:template name="floater">
  405. <xsl:param name="content"/>
  406. <xsl:param name="class" select="'float'"/>
  407. <xsl:param name="floatstyle" select="'left'"/>
  408. <div class="{$class}">
  409. <xsl:if test="$floatstyle = 'left' or $floatstyle = 'right'">
  410. <xsl:attribute name="style">
  411. <xsl:text>float: </xsl:text>
  412. <xsl:value-of select="$floatstyle"/>
  413. <xsl:text>;</xsl:text>
  414. </xsl:attribute>
  415. </xsl:if>
  416. <xsl:copy-of select="$content"/>
  417. </div>
  418. </xsl:template>
  419. </xsl:stylesheet>