123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="UTF-8"
- doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
- doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
- <xsl:variable name="lang" select="string(/document/@xml:lang)"/>
- <xsl:key name="chapters" match="chapter" use="@xml:id"/>
- <xsl:template match="/">
- <xsl:apply-templates select="document"/>
- </xsl:template>
- <xsl:template match="annotation"/>
- <xsl:template match="document">
- <html lang="{@xml:lang}">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title><xsl:value-of select="title"/></title>
- <style type="text/css">
- body {
- font-family: verdana, sans-serif;
- font-size: 10pt;
- background-color: #777777;
- margin: 0;
- }
- div.page-wrap {
- background-color: white;
- width: 210mm; /* A4 */
- margin: 0 auto;
- padding: 2mm 5mm;
- }
- p, div {
- margin-top: 6pt;
- margin-bottom: 0;
- }
- h1, h2, h3, h4, h5, h6 {
- font-weight: bold;
- margin-top: 9pt;
- margin-bottom: 12pt;
- margin-left: 0;
- }
- h1 { font-size: 16pt; }
- h2 { font-size: 13pt; }
- h3 { font-size: 11pt; }
- h4 { font-size: 11pt; }
- span.h1_num, span.h2_num {
- margin-right: 2em;
- font-family: sans-serif;
- }
- span.h3_num, span.h4_num {
- margin-right: 2em;
- font-weight: normal;
- font-size: smaller;
- }
- h1.main-title {
- font-size: 2em;
- font-weight: bold;
- }
- caption.toc {
- text-align: left;
- font-weight: bold;
- font-size: 13pt;
- margin-top: 9pt;
- margin-bottom: 12pt;
- margin-left: 0;
- }
- td.toc-chapter-no {
- padding-right: 1ex;
- vertical-align: top;
- }
- a { text-decoration: none; }
- a:hover { text-decoration: underline; }
- pre.code {
- background-color: #EEE;
- border: 1px solid #CCCCCC;
- padding-top: 6pt;
- padding-bottom: 6pt;
- padding-left: 2pt;
- font-family: monospace;
- font-size: 10pt;
- width: 17.3cm; /* 80ch */
- }
- pre.prototype {
- font-family: monospace;
- margin-top: 0;
- margin-bottom: 0;
- }
- div.section {
- font-weight: bold;
- }
- div.todo {
- color: red;
- font-weight: bold;
- }
- span.ver {
- font-size: smaller;
- color: #C0C0C0;
- }
- span.nonterminal {
- font-family: monospace;
- font-style: italic;
- }
- span.sign {
- color: #C0C0C0;
- font-family: monospace;
- font-size: 9pt;
- font-weight: bold;
- }
- blockquote {
- margin-top: 6pt;
- margin-bottom: 0;
- margin-right: 0;
- }
- blockquote * {
- margin-top: 0;
- margin-bottom: 0;
- }
- </style>
- </head>
- <body>
- <div class="page-wrap">
- <xsl:apply-templates select="title" mode="document"/>
- <xsl:call-template name="toc"/>
- <xsl:apply-templates>
- <xsl:with-param name="chapter_level" select="1"/>
- </xsl:apply-templates>
- </div>
- </body>
- </html>
- </xsl:template>
- <xsl:template match="chapter">
- <xsl:param name="chapter_level"/>
- <xsl:param name="chapter_prefix"/>
- <!-- Detect position of the current chapter relatively sibling chapters -->
- <xsl:variable name="my-id" select="generate-id()"/>
- <xsl:variable name="pos">
- <xsl:for-each select="../chapter">
- <xsl:if test="generate-id() = $my-id">
- <xsl:value-of select="position()"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:apply-templates select="title" mode="chapter">
- <xsl:with-param name="level" select="$chapter_level"/>
- <xsl:with-param name="no" select="concat($chapter_prefix, $pos)"/>
- </xsl:apply-templates>
- <xsl:apply-templates>
- <xsl:with-param name="chapter_level" select="$chapter_level+1"/>
- <xsl:with-param name="chapter_prefix" select="concat($chapter_prefix, $pos, '.')"/>
- </xsl:apply-templates>
- </xsl:template>
- <xsl:template name="toc">
- <table style="font-size:10pt;" cellspacing="0" cellpadding="0">
- <caption class="toc">
- <xsl:choose>
- <xsl:when test="$lang='ru'">Содержание</xsl:when>
- <xsl:otherwise>Contents</xsl:otherwise>
- </xsl:choose>
- </caption>
- <xsl:call-template name="toc-entry"/>
- </table>
- </xsl:template>
- <xsl:template name="toc-entry">
- <xsl:param name="prefix"/>
- <xsl:param name="level" select="1"/>
- <xsl:for-each select="chapter">
- <xsl:variable name="chap" select="concat($prefix, position())"/>
- <tr>
- <td class="toc-chapter-no">
- <xsl:value-of select="$chap"/>
- </td>
- <td>
- <xsl:if test="$level > 2">
- <xsl:attribute name="style">padding-left:4ex</xsl:attribute>
- </xsl:if>
- <a href="#{@xml:id}">
- <xsl:if test="not(string(@xml:id))">
- <xsl:attribute name="style">color:red;</xsl:attribute>
- </xsl:if>
- <xsl:apply-templates select="title" mode="toc"/>
- </a>
- </td>
- </tr>
- <xsl:call-template name="toc-entry">
- <xsl:with-param name="prefix" select="concat($chap, '.')"/>
- <xsl:with-param name="level" select="$level + 1"/>
- </xsl:call-template>
- <xsl:if test="$level = 1">
- <!-- Space between level 1 chapters -->
- <tr><td colspan="2" style="font-size:5pt;"> </td></tr>
- </xsl:if>
- </xsl:for-each>
- </xsl:template>
- <xsl:template match="title"/>
- <xsl:template match="title" mode="document">
- <h1 class="main-title">
- <xsl:apply-templates/>
- <xsl:if test="/document/@version">
- <span class="ver">
- <xsl:value-of select="concat(' v', /document/@version)"/>
- <xsl:if test="/document/@status and /document/@status != 'Release'">
- <xsl:value-of select="concat(' [', /document/@status, ']')"/>
- </xsl:if>
- </span>
- </xsl:if>
- </h1>
- </xsl:template>
- <xsl:template match="title" mode="chapter">
- <xsl:param name="level"/>
- <xsl:param name="no"/>
- <xsl:element name="h{$level}">
- <xsl:attribute name="id">
- <xsl:value-of select="../@xml:id"/>
- </xsl:attribute>
- <span class="h{$level}_num">
- <xsl:value-of select="$no"/>
- </span>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:template>
- <xsl:template match="title" mode="section">
- <div class="section"><xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="title" mode="toc">
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template match="p">
- <p><xsl:apply-templates/></p>
- </xsl:template>
- <xsl:template match="tt">
- <tt><xsl:apply-templates/></tt>
- </xsl:template>
- <xsl:template match="u">
- <u><xsl:apply-templates/></u>
- </xsl:template>
- <xsl:template match="b">
- <b><xsl:apply-templates/></b>
- </xsl:template>
- <xsl:template match="nt">
- <span class="nonterminal"><xsl:apply-templates/></span>
- </xsl:template>
- <xsl:template match="list[@style='numbered']">
- <ol>
- <xsl:for-each select="item">
- <li><xsl:apply-templates/></li>
- </xsl:for-each>
- </ol>
- </xsl:template>
- <xsl:template match="list[@style='bulleted']">
- <ul>
- <xsl:for-each select="item">
- <li><xsl:apply-templates/></li>
- </xsl:for-each>
- </ul>
- </xsl:template>
- <xsl:template match="list[@style='nomarks']">
- <ul style="list-style-type:none">
- <xsl:for-each select="item">
- <li><xsl:apply-templates/></li>
- </xsl:for-each>
- </ul>
- </xsl:template>
- <xsl:template match="list">
- <div class="todo">Invalid list style</div>
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template match="link">
- <a href="{.}"><xsl:apply-templates/></a>
- </xsl:template>
- <xsl:template match="link[@href]">
- <a href="{@href}"><xsl:apply-templates/></a>
- </xsl:template>
- <xsl:template match="xref">
- <a href="#{@to}">
- <xsl:apply-templates select="key('chapters', @to)/title/node()"/>
- </a>
- </xsl:template>
- <xsl:template match="code-block | tty">
- <pre class="code"><xsl:apply-templates/></pre>
- </xsl:template>
- <xsl:template match="section">
- <xsl:apply-templates select="title" mode="section"/>
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template match="note">
- <div><u><b>
- <xsl:choose>
- <xsl:when test="$lang='ru'">Замечание</xsl:when>
- <xsl:otherwise>Note</xsl:otherwise>
- </xsl:choose>
- </b></u>: <xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="note[parent::synopsis]">
- <div><u>
- <xsl:choose>
- <xsl:when test="$lang='ru'">Замечание</xsl:when>
- <xsl:otherwise>Note</xsl:otherwise>
- </xsl:choose>
- </u>: <xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="precondition">
- <div><u>
- <xsl:choose>
- <xsl:when test="$lang='ru'">Предусловие</xsl:when>
- <xsl:otherwise>Precondition</xsl:otherwise>
- </xsl:choose>
- </u>: <xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="postcondition">
- <div><u>
- <xsl:choose>
- <xsl:when test="$lang='ru'">Постусловие</xsl:when>
- <xsl:otherwise>Postcondition</xsl:otherwise>
- </xsl:choose>
- </u>: <xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="invariant">
- <div><u>
- <xsl:choose>
- <xsl:when test="$lang='ru'">Инвариант</xsl:when>
- <xsl:otherwise>Invariant</xsl:otherwise>
- </xsl:choose>
- </u>: <xsl:apply-templates/></div>
- </xsl:template>
- <xsl:template match="synopsis">
- <div>
- <xsl:apply-templates select="prototype" mode="synopsis"/>
- <blockquote><xsl:apply-templates/></blockquote>
- </div>
- </xsl:template>
- <xsl:template match="prototype"/>
- <xsl:template match="prototype" mode="synopsis">
- <pre class="prototype"><xsl:apply-templates/></pre>
- </xsl:template>
- <xsl:template match="sign">
- <span class="sign">[<xsl:apply-templates/>]</span>
- </xsl:template>
- <xsl:template match="TODO">
- <div class="todo">[TODO<xsl:if test="string(.)">: <xsl:value-of select="."/>
- </xsl:if>]</div>
- </xsl:template>
- </xsl:stylesheet>
|