formal.xsl 16 KB

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