html.xsl 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="html"/>
  4. <xsl:template match="/">
  5. <xsl:apply-templates select="document"/>
  6. </xsl:template>
  7. <xsl:template match="annotation"/>
  8. <xsl:template match="document">
  9. <html lang="{@xml:lang}">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  12. <title><xsl:value-of select="title"/></title>
  13. <style type="text/css">
  14. body {
  15. font-family: verdana, sans-serif;
  16. font-size: 10pt;
  17. background-color: #777777;
  18. margin: 0;
  19. }
  20. div.page-wrap {
  21. background-color: white;
  22. width: 210mm; /* A4 */
  23. margin: 0 auto;
  24. padding: 2mm 5mm;
  25. }
  26. p, div {
  27. margin-top: 6pt;
  28. margin-bottom: 0;
  29. }
  30. h1, h2, h3, h4, h5, h6 {
  31. font-weight: bold;
  32. margin-top: 9pt;
  33. margin-bottom: 12pt;
  34. margin-left: 0;
  35. }
  36. h1 { font-size: 16pt; }
  37. h2 { font-size: 13pt; }
  38. h3 { font-size: 11pt; }
  39. h4 { font-size: 11pt; }
  40. span.h1_num, span.h2_num {
  41. margin-right: 2em;
  42. font-family: sans-serif;
  43. }
  44. span.h3_num, span.h4_num {
  45. margin-right: 2em;
  46. font-weight: normal;
  47. font-size: smaller;
  48. }
  49. h1.main-title {
  50. font-size: 2em;
  51. font-weight: bold;
  52. }
  53. a.toc { text-decoration: none; }
  54. a.toc:hover { text-decoration: underline; }
  55. pre.code {
  56. background-color: #EEE;
  57. border: 1px solid #CCCCCC;
  58. padding-top: 6pt;
  59. padding-bottom: 6pt;
  60. padding-left: 2pt;
  61. font-family: monospace;
  62. font-size: 10pt;
  63. width: 17.3cm; /* 80ch */
  64. }
  65. pre.prototype {
  66. font-family: monospace;
  67. margin-top: 0;
  68. margin-bottom: 0;
  69. }
  70. div.section {
  71. font-weight: bold;
  72. }
  73. div.todo {
  74. color: red;
  75. font-weight: bold;
  76. }
  77. span.ver {
  78. font-size: smaller;
  79. color: #C0C0C0;
  80. }
  81. span.nonterminal {
  82. font-family: monospace;
  83. font-style: italic;
  84. }
  85. span.sign {
  86. color: #C0C0C0;
  87. font-family: monospace;
  88. font-size: 9pt;
  89. font-weight: bold;
  90. }
  91. blockquote {
  92. margin-top: 6pt;
  93. margin-bottom: 0;
  94. margin-right: 0;
  95. }
  96. blockquote * {
  97. margin-top: 0;
  98. margin-bottom: 0;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <div class="page-wrap">
  104. <xsl:apply-templates select="title" mode="document"/>
  105. <xsl:call-template name="toc"/>
  106. <xsl:apply-templates>
  107. <xsl:with-param name="chapter_level" select="1"/>
  108. </xsl:apply-templates>
  109. </div>
  110. </body>
  111. </html>
  112. </xsl:template>
  113. <xsl:template match="chapter">
  114. <xsl:param name="chapter_level"/>
  115. <xsl:param name="chapter_prefix"/>
  116. <!-- Detect position of the current chapter relatively sibling chapters -->
  117. <xsl:variable name="my-id" select="generate-id()"/>
  118. <xsl:variable name="pos">
  119. <xsl:for-each select="../chapter">
  120. <xsl:if test="generate-id() = $my-id">
  121. <xsl:value-of select="position()"/>
  122. </xsl:if>
  123. </xsl:for-each>
  124. </xsl:variable>
  125. <xsl:apply-templates select="title" mode="chapter">
  126. <xsl:with-param name="level" select="$chapter_level"/>
  127. <xsl:with-param name="no" select="concat($chapter_prefix, $pos)"/>
  128. </xsl:apply-templates>
  129. <xsl:apply-templates>
  130. <xsl:with-param name="chapter_level" select="$chapter_level+1"/>
  131. <xsl:with-param name="chapter_prefix" select="concat($chapter_prefix, $pos, '.')"/>
  132. </xsl:apply-templates>
  133. </xsl:template>
  134. <xsl:template name="toc">
  135. <table style="font-size:10pt;" cellspacing="0" cellpadding="0">
  136. <caption style="text-align:left"><h2>Contents</h2></caption>
  137. <xsl:call-template name="toc-entry"/>
  138. </table>
  139. </xsl:template>
  140. <xsl:template name="toc-entry">
  141. <xsl:param name="prefix"/>
  142. <xsl:param name="level" select="1"/>
  143. <xsl:for-each select="chapter">
  144. <xsl:variable name="chap" select="concat($prefix, position())"/>
  145. <tr>
  146. <td style="padding-right:1ex">
  147. <xsl:value-of select="$chap"/>
  148. </td>
  149. <td>
  150. <xsl:if test="$level > 2">
  151. <xsl:attribute name="style">padding-left:4ex</xsl:attribute>
  152. </xsl:if>
  153. <a class="toc" href="#chapter-{translate($chap,'.','_')}">
  154. <xsl:apply-templates select="title" mode="toc"/>
  155. </a>
  156. </td>
  157. </tr>
  158. <xsl:call-template name="toc-entry">
  159. <xsl:with-param name="prefix" select="concat($chap, '.')"/>
  160. <xsl:with-param name="level" select="$level + 1"/>
  161. </xsl:call-template>
  162. <xsl:if test="$level = 1">
  163. <!-- Space between level 1 chapters -->
  164. <tr><td colspan="2" style="font-size:5pt;">&#xA0;</td></tr>
  165. </xsl:if>
  166. </xsl:for-each>
  167. </xsl:template>
  168. <xsl:template match="title"/>
  169. <xsl:template match="title" mode="document">
  170. <h1 class="main-title">
  171. <xsl:apply-templates/>
  172. <xsl:if test="/document/@version">
  173. <span class="ver">
  174. <xsl:value-of select="concat(' v', /document/@version)"/>
  175. <xsl:if test="/document/@status and /document/@status != 'Release'">
  176. <xsl:value-of select="concat(' [', /document/@status, ']')"/>
  177. </xsl:if>
  178. </span>
  179. </xsl:if>
  180. </h1>
  181. </xsl:template>
  182. <xsl:template match="title" mode="chapter">
  183. <xsl:param name="level"/>
  184. <xsl:param name="no"/>
  185. <xsl:element name="h{$level}">
  186. <span class="h{$level}_num"><xsl:value-of select="$no"/></span>
  187. <a id="chapter-{translate($no,'.','_')}"/>
  188. <xsl:apply-templates/>
  189. </xsl:element>
  190. </xsl:template>
  191. <xsl:template match="title" mode="section">
  192. <div class="section"><xsl:apply-templates/></div>
  193. </xsl:template>
  194. <xsl:template match="title" mode="toc">
  195. <xsl:apply-templates/>
  196. </xsl:template>
  197. <xsl:template match="p">
  198. <p><xsl:apply-templates/></p>
  199. </xsl:template>
  200. <xsl:template match="tt">
  201. <tt><xsl:apply-templates/></tt>
  202. </xsl:template>
  203. <xsl:template match="u">
  204. <u><xsl:apply-templates/></u>
  205. </xsl:template>
  206. <xsl:template match="b">
  207. <b><xsl:apply-templates/></b>
  208. </xsl:template>
  209. <xsl:template match="nt">
  210. <span class="nonterminal"><xsl:apply-templates/></span>
  211. </xsl:template>
  212. <xsl:template match="list[@style='numbered']">
  213. <ol>
  214. <xsl:for-each select="item">
  215. <li><xsl:apply-templates/></li>
  216. </xsl:for-each>
  217. </ol>
  218. </xsl:template>
  219. <xsl:template match="list[@style='bulleted']">
  220. <ul>
  221. <xsl:for-each select="item">
  222. <li><xsl:apply-templates/></li>
  223. </xsl:for-each>
  224. </ul>
  225. </xsl:template>
  226. <xsl:template match="list[@style='nomarks']">
  227. <ul style="list-style-type:none">
  228. <xsl:for-each select="item">
  229. <li><xsl:apply-templates/></li>
  230. </xsl:for-each>
  231. </ul>
  232. </xsl:template>
  233. <xsl:template match="list">
  234. <div class="todo">Invalid list style</div>
  235. <xsl:apply-templates/>
  236. </xsl:template>
  237. <xsl:template match="link">
  238. <a href="{.}"><xsl:apply-templates/></a>
  239. </xsl:template>
  240. <xsl:template match="link[@href]">
  241. <a href="{@href}"><xsl:apply-templates/></a>
  242. </xsl:template>
  243. <xsl:template match="code-block | tty">
  244. <pre class="code"><xsl:apply-templates/></pre>
  245. </xsl:template>
  246. <xsl:template match="section">
  247. <xsl:apply-templates select="title" mode="section"/>
  248. <xsl:apply-templates/>
  249. </xsl:template>
  250. <xsl:template match="note">
  251. <div><u><b>Note</b></u>: <xsl:apply-templates/></div>
  252. </xsl:template>
  253. <xsl:template match="note[parent::synopsis]">
  254. <div><u>Note</u>: <xsl:apply-templates/></div>
  255. </xsl:template>
  256. <xsl:template match="precondition">
  257. <div><u>Precondition</u>: <xsl:apply-templates/></div>
  258. </xsl:template>
  259. <xsl:template match="postcondition">
  260. <div><u>Postcondition</u>: <xsl:apply-templates/></div>
  261. </xsl:template>
  262. <xsl:template match="invariant">
  263. <div><u>Invariant</u>: <xsl:apply-templates/></div>
  264. </xsl:template>
  265. <xsl:template match="synopsis">
  266. <div>
  267. <xsl:apply-templates select="prototype" mode="synopsis"/>
  268. <blockquote><xsl:apply-templates/></blockquote>
  269. </div>
  270. </xsl:template>
  271. <xsl:template match="prototype"/>
  272. <xsl:template match="prototype" mode="synopsis">
  273. <pre class="prototype"><xsl:apply-templates/></pre>
  274. </xsl:template>
  275. <xsl:template match="sign">
  276. <span class="sign">[<xsl:apply-templates/>]</span>
  277. </xsl:template>
  278. <xsl:template match="TODO">
  279. <div class="todo">[TODO<xsl:if test="string(.)">: <xsl:value-of select="."/>
  280. </xsl:if>]</div>
  281. </xsl:template>
  282. </xsl:stylesheet>