XSLT 2.0 stylesheets for converting the man pages to HTML

This commit is contained in:
Moritz Bunkus 2011-10-31 10:15:23 +01:00
parent f1307055b6
commit 2353d55a71
5 changed files with 537 additions and 0 deletions

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="cmdsynopsis">
<div class="cmdsynopsis">
<span class="commandname"><xsl:value-of select="command"/></span>
<xsl:apply-templates select="group | arg">
<xsl:with-param name="previous" select="'normal'"/>
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="group">
<xsl:param name="previous" select="'closing'"/>
<xsl:if test="($previous = 'normal') or ($previous = 'closing')">
<xsl:text>&#x20;</xsl:text>
</xsl:if>
<xsl:text>[</xsl:text>
<xsl:for-each select="arg">
<xsl:apply-templates select=".">
<xsl:with-param name="previous" select="if (position() = 1) then 'opening' else 'normal'"/>
</xsl:apply-templates>
<xsl:if test="not(position() = last())">
<xsl:text>&#x20;|</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template name="output-arg">
<xsl:param name="start" select="''"/>
<xsl:param name="end" select="''"/>
<xsl:param name="class" select="'normal-arg'"/>
<!-- <span class="{$class}"> -->
<xsl:value-of select="$start"/>
<xsl:choose>
<xsl:when test="count(*) > 0">
<xsl:for-each select="arg">
<xsl:apply-templates select=".">
<xsl:with-param name="previous" select="if (position() = 1) then 'opening' else 'normal'"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$end"/>
<!-- </span> -->
</xsl:template>
<xsl:template match="arg">
<xsl:param name="previous" select="'closing'"/>
<xsl:if test="($previous = 'normal') or ($previous = 'closing')">
<xsl:text>&#x20;</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="@choice = 'req'">
<xsl:call-template name="output-arg">
<xsl:with-param name="start" select="'{'"/>
<xsl:with-param name="end" select="'}'"/>
<xsl:with-param name="class" select="'required-arg'"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="(@choice = '') or (@choice = 'opt')">
<xsl:call-template name="output-arg">
<xsl:with-param name="start" select="'['"/>
<xsl:with-param name="end" select="']'"/>
<xsl:with-param name="class" select="'optional-arg'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="output-arg"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
<!-- <xsl:strip-space elements="*"/> -->
<xsl:param name="this-man" select="/refentry/refmeta/refentrytitle"/>
<xsl:include href="head.xsl"/>
<xsl:include href="toc.xsl"/>
<xsl:include href="cmdsynopsis.xsl"/>
<xsl:template name="generate-anchor">
<xsl:value-of select="if (not(@id)) then generate-id(title) else @id"/>
</xsl:template>
<!-- Enable this for marking elements that match the default rules -->
<xsl:template match="*">
<xsl:text>(DEFAULT[</xsl:text><xsl:value-of select="name()"/><xsl:text>]::</xsl:text>
<xsl:apply-templates/>
<xsl:text>::DEFAULT)</xsl:text>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="refentry"/>
</xsl:template>
<xsl:template match="title"/>
<xsl:template match="abbrev | classname | code | command | constant | filename | foreignphrase | function | literal | option | parameter | varname">
<span class="{name()}"><xsl:apply-templates/></span>
</xsl:template>
<xsl:template match="productname">
<span class="productname"><xsl:apply-templates/></span>
<sup><xsl:text>(tm)</xsl:text></sup>
</xsl:template>
<xsl:template match="important">
<div class="important">
<p class="important-title">Important:</p>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="note">
<div class="note">
<p class="note-title">Note:</p>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="programlisting | screen">
<pre class="{name()}"><xsl:apply-templates mode="no-markup"/></pre>
</xsl:template>
<xsl:template match="refentry">
<html>
<xsl:call-template name="head"/>
<body>
<div class="heading">
<xsl:apply-templates select="refnamediv/refname"/>
<xsl:text> -- </xsl:text>
<xsl:apply-templates select="refnamediv/refpurpose"/>
</div>
<hr/>
<xsl:call-template name="toc"/>
<xsl:call-template name="content"/>
</body>
</html>
</xsl:template>
<xsl:template name="content">
<div class="content">
<xsl:for-each select="refsynopsisdiv | refsect1">
<xsl:if test="name() = 'refsetc1'">
<hr/>
</xsl:if>
<h1>
<xsl:variable name="anchor">
<xsl:call-template name="generate-anchor"/>
</xsl:variable>
<a name="{$anchor}">
<xsl:number format="1. " value="position()"/>
<xsl:value-of select="title"/>
</a>
</h1>
<xsl:apply-templates/>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="refsect2">
<h2>
<xsl:variable name="anchor">
<xsl:call-template name="generate-anchor"/>
</xsl:variable>
<a name="{$anchor}">
<xsl:number level="multiple" format="1. " count="refsynopsisdiv|refsect1|refsect2"/>
<xsl:value-of select="title"/>
</a>
</h2>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="emphasis">
<em><xsl:apply-templates/></em>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="link">
<a href="#{@linkend}"><xsl:value-of select="."/></a>
</xsl:template>
<xsl:template match="ulink">
<a href="{@url}"><xsl:value-of select="."/></a>
</xsl:template>
<xsl:template match="uri">
<a href="{.}"><xsl:value-of select="."/></a>
</xsl:template>
<xsl:template match="variablelist">
<table class="variablelist">
<thead>
<tr>
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="varlistentry"/>
</tbody>
</table>
</xsl:template>
<xsl:template match="varlistentry">
<tr>
<td class="varlistoption">
<xsl:choose>
<xsl:when test="@id"><a name="{@id}"><xsl:apply-templates select="term"/></a></xsl:when>
<xsl:otherwise><xsl:apply-templates select="term"/></xsl:otherwise>
</xsl:choose>
</td>
<td><xsl:apply-templates select="listitem"/></td>
</tr>
</xsl:template>
<xsl:template match="refname | refpurpose | term | varlistentry/listitem">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="orderedlist">
<ol>
<xsl:copy-of select="@id"/>
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="itemizedlist">
<ul>
<xsl:copy-of select="@id"/>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="orderedlist/listitem | itemizedlist/listitem">
<li>
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template match="optional">
<xsl:text>[</xsl:text><xsl:apply-templates/><xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="citerefentry">
<xsl:choose>
<xsl:when test="$this-man = refentrytitle">
<span class="productname"><xsl:value-of select="refentrytitle"/></span>
<xsl:text>(</xsl:text><xsl:value-of select="manvolnum"/><xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="matches(refentrytitle, '^(mmg|mkv)')">
<a href="{refentrytitle}.html">
<span class="productname"><xsl:value-of select="refentrytitle"/></span>
<xsl:text>(</xsl:text><xsl:value-of select="manvolnum"/><xsl:text>)</xsl:text>
</a>
</xsl:when>
<xsl:otherwise>
<a href="http://linux.die.net/man/{manvolnum}/{refentrytitle}" >
<span class="productname"><xsl:value-of select="refentrytitle"/></span>
<xsl:text>(</xsl:text><xsl:value-of select="manvolnum"/><xsl:text>)</xsl:text>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

14
doc/stylesheets/head.xsl Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="head">
<head>
<title>
<xsl:value-of select="refnamediv/refname"/>
<xsl:text> -- </xsl:text>
<xsl:value-of select="refnamediv/refpurpose"/>
</title>
<link rel="stylesheet" type="text/css" href="mkvtoolnix-doc.css"/>
</head>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,212 @@
@charset "utf-8";
body {
font-family: Verdana, sans-serif;
color: #000000;
background: #ffffff;
}
.heading {
font-weight: bold;
font-size: 158%;
text-align: center;
}
h1 {
font-size: 150%;
font-weight: bold;
}
h2 {
font-size: 125%;
font-weight: bold;
}
h3 {
font-size: 100%;
font-weight: bold;
text-decoration: underline;
}
a:link ,a:visited{
color: #0067ab;
text-decoration: none;
}
a:focus {
outline:1px dotted;
}
a:hover, a:active {
color: #0067ab;
outline: none;
text-decoration: underline;
}
.toc {
margin: 0px 20px 10px 20px;
border: 1px solid #BBB;
background-color: #dda;
color: #000;
background: #EEE;
padding: 1px 10px;
}
.toc ul {
list-style-type: none;
padding-left: 0px;
}
.content {
margin: 0px 20px 10px 20px;
border: 1px solid #BBB;
background-color: #dda;
color: #000;
background: #EEE;
padding: 1px 10px;
}
.abbrev {
}
.classname {
font-family: monospace;
}
.code {
background-color: #cccccc;
font-family: monospace;
}
.command, .commandname {
font-family: monospace;
}
.constant {
font-family: monospace;
}
.filename {
font-family: monospace;
}
.foreignphrase {
}
.function {
font-family: monospace;
}
.literal {
font-family: monospace;
}
.option {
color: #be5303;
font-family: monospace;
}
.parameter {
font-family: monospace;
font-style: italic;
border-bottom: 1px dashed black;
}
.productname {
font-style: italic;
}
.varname {
font-family: monospace;
}
.important-title {
text-decoration: underline;
font-weight: bold;
}
.important {
color: #000000;
background-color: #fae8b8;
border: 1px solid #be5303;
border-collapse: collapse;
margin: 10px 30px;
padding: 0px 10px;
}
.note-title {
text-decoration: underline;
font-weight: bold;
}
.note {
color: #000000;
background-color: #fae8b8;
border: 1px solid #be5303;
border-collapse: collapse;
margin: 10px 30px;
padding: 0px 10px;
}
.cmdsynopsis {
font-family: monospace;
color: #000000;
background-color: #d0d0d0;
border: 1px solid #0067ab;
padding: 3px 5px;
margin: 0px 5px;
}
.programlisting {
font-family: monospace;
color: #000000;
background-color: #d0d0d0;
border: 1px solid #0067ab;
padding: 3px 5px;
margin: 0px 5px;
}
.screen {
font-family: monospace;
background-color: #d0d0d0;
border: 1px solid #0067ab;
padding: 3px 5px;
margin: 0px 5px;
}
img {
border: none;
}
table.variablelist {
color: #ffffff;
background-color: #000000;
border: 1px solid #d0d0d0;
border-collapse: collapse;
}
table.variablelist th {
color: #000000;
background-color: #cccccc;
}
table.variablelist td {
color: #000000;
background-color: #ffffff;
border: 1px solid #d0d0d0;
padding: 3px;
vertical-align: top;
}
table.variablelist td.varlistoption {
white-space: nowrap;
}
td p:first-child {
margin-top: 0px;
}
td p:last-child {
margin-bottom: 0px;
}

24
doc/stylesheets/toc.xsl Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="toc">
<div id="toc" class="toc">
<h1><xsl:text>Table of contents</xsl:text></h1>
<ul>
<xsl:for-each select="refsynopsisdiv | refsect1">
<li>
<xsl:variable name="anchor">
<xsl:call-template name="generate-anchor"/>
</xsl:variable>
<a href="#{$anchor}">
<xsl:number level="multiple" format="1. " count="refsynopsisdiv|refsect1"/>
<xsl:value-of select="title"/>
</a>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>