html.xsl 8.9 KB

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