summaryrefslogtreecommitdiff
path: root/doc/html2texi.xsl
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html2texi.xsl')
-rw-r--r--doc/html2texi.xsl367
1 files changed, 367 insertions, 0 deletions
diff --git a/doc/html2texi.xsl b/doc/html2texi.xsl
new file mode 100644
index 0000000..dc432c6
--- /dev/null
+++ b/doc/html2texi.xsl
@@ -0,0 +1,367 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:info="http://planete-kraus.eu/ns/info">
+
+ <xsl:output method="text"/>
+
+ <xsl:template match="html:html">
+ <xsl:text>\input texinfo @c -*-texinfo-*-&#xa;</xsl:text>
+ <xsl:text>@comment $Id@w{$}&#xa;</xsl:text>
+ <xsl:if test="@xml:lang">
+ <xsl:text>@documentlanguage </xsl:text>
+ <xsl:value-of select="@xml:lang" />
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:if>
+ <xsl:apply-templates select="html:head" />
+ <xsl:text>@contents&#xa;</xsl:text>
+ <xsl:apply-templates select="html:body" />
+ <xsl:text>@bye&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:head">
+ <xsl:text>@comment %**start of header&#xa;</xsl:text>
+ <xsl:text>@include version.texi&#xa;</xsl:text>
+ <xsl:text>@settitle </xsl:text>
+ <xsl:apply-templates select="html:title" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@syncodeindex pg cp&#xa;</xsl:text>
+ <xsl:text>@syncodeindex fn cp&#xa;</xsl:text>
+ <xsl:text>@syncodeindex vr cp&#xa;</xsl:text>
+ <xsl:text>@syncodeindex tp cp&#xa;</xsl:text>
+ <xsl:text>@comment %**end of header&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates select="info:copying" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates select="info:dircategory" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates select="info:direntry" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@titlepage&#xa;</xsl:text>
+ <xsl:text>@title </xsl:text>
+ <xsl:apply-templates select="html:title" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@subtitle for version @value{VERSION}, @value{UPDATED}&#xa;</xsl:text>
+ <xsl:text>@author </xsl:text>
+ <xsl:apply-templates select="info:author" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@page&#xa;</xsl:text>
+ <xsl:text>@vskip 0pt plus 1fill&#xa;</xsl:text>
+ <xsl:text>@insertcopying&#xa;</xsl:text>
+ <xsl:text>@end titlepage&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:copying">
+ <xsl:text>@copying&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end copying&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:quotation">
+ <xsl:text>@quotation&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end quotation&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:version">
+ <xsl:text>@value{VERSION}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:updated">
+ <xsl:text>@value{UPDATED}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:copyright-symbol">
+ <xsl:text>@copyright{}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:dircategory">
+ <xsl:text>@dircategory </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:direntry">
+ <xsl:text>@direntry&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end direntry&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:direntry-entry">
+ <xsl:text>* </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>: (</xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>)</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:author">
+ <xsl:apply-templates />
+ </xsl:template>
+
+ <xsl:template match="html:a[starts-with(@href, 'mailto:')]">
+ <xsl:apply-templates />
+ <xsl:text> (@email{</xsl:text>
+ <xsl:variable name="address" select="substring-after(@href, 'mailto:')" />
+ <xsl:value-of select="substring-before($address, '@')" />
+ <xsl:text>@@</xsl:text>
+ <xsl:value-of select="substring-after($address, '@')" />
+ <xsl:text>})</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:body">
+ <xsl:text>@ifnottex&#xa;</xsl:text>
+ <xsl:text>@node Top&#xa;</xsl:text>
+ <xsl:text>@top Webid-oidc&#xa;</xsl:text>
+ <xsl:apply-templates select="child::*[not(self::html:h1) and count(preceding-sibling::html:h1) = 0]" />
+ <xsl:text>@end ifnottex&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@menu&#xa;</xsl:text>
+ <xsl:apply-templates mode="menu" select="html:h1" />
+ <xsl:text>@end menu&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates select="child::*[self::html:h1 or count(preceding-sibling::html:h1) >= 1]" />
+ </xsl:template>
+
+ <xsl:template match="*" mode="menu">
+ <xsl:text>* </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>::&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:h1">
+ <xsl:text>@node </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@</xsl:text>
+ <xsl:choose>
+ <xsl:when test="@type">
+ <xsl:value-of select="@type" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>chapter</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:variable name="chapter-number"
+ select="count(preceding-sibling::html:h1) + 1" />
+ <xsl:if test="count(following-sibling::html:h2[count(preceding-sibling::html:h1) = $chapter-number]) > 0">
+ <!-- There are sub-sections; we need a menu -->
+ <xsl:text>@menu&#xA;</xsl:text>
+ <xsl:apply-templates mode="menu"
+ select="following-sibling::html:h2[count(preceding-sibling::html:h1) = $chapter-number]" />
+ <xsl:text>@end menu&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="html:h2">
+ <xsl:text>@node </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>@section </xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="text()">
+ <!-- Normalize the spaces, but keep one space before or after if
+ needed -->
+ <xsl:variable name="normalized" select="normalize-space(.)" />
+ <xsl:variable name="first-char">
+ <xsl:value-of select="substring(., 1, 1)" />
+ </xsl:variable>
+ <xsl:variable name="last-char">
+ <xsl:value-of select="substring(., string-length(.))" />
+ </xsl:variable>
+ <xsl:variable name="first-char-space">
+ <xsl:if test="$first-char = ' ' or $first-char = '&#x9;' or $first-char = '&#xA;'">
+ <xsl:text> </xsl:text>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:variable name="last-char-space">
+ <xsl:if test="$last-char = ' ' or $last-char = '&#x9;' or $last-char = '&#xA;'">
+ <xsl:text> </xsl:text>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:variable name="space-left">
+ <xsl:if test="count(preceding-sibling::*) >= 1 ">
+ <xsl:value-of select="$first-char-space" />
+ </xsl:if>
+ </xsl:variable>
+ <xsl:variable name="space-right">
+ <xsl:if test="count(following-sibling::*) >= 1 ">
+ <xsl:value-of select="$last-char-space" />
+ </xsl:if>
+ </xsl:variable>
+ <xsl:if test="$normalized != ''">
+ <xsl:value-of select="$space-left" />
+ <xsl:value-of select="$normalized" />
+ <xsl:value-of select="$space-right" />
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="html:p[position() &lt; last()]">
+ <!-- Leave an empty line -->
+ <xsl:apply-templates />
+ <xsl:text>@c fill&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:p">
+ <xsl:apply-templates />
+ <xsl:text>@c fill&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:dfn">
+ <xsl:text>@dfn{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:pre">
+ <xsl:text>@code{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:deffn">
+ <xsl:text>@deffn </xsl:text>
+ <xsl:value-of select="@type" />
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="arglist">
+ <xsl:with-param name="arguments" select="@arguments" />
+ </xsl:call-template>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end deffn&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:deffnx">
+ <xsl:text>@deffnx </xsl:text>
+ <xsl:value-of select="@type" />
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="arglist">
+ <xsl:with-param name="arguments" select="@arguments" />
+ </xsl:call-template>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:defvr">
+ <xsl:text>@defvr {</xsl:text>
+ <xsl:value-of select="@type" />
+ <xsl:text>} </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end defvr&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:deftp">
+ <xsl:text>@deftp {</xsl:text>
+ <xsl:value-of select="@type" />
+ <xsl:text>} </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="arglist">
+ <xsl:with-param name="arguments" select="@arguments" />
+ </xsl:call-template>
+ <xsl:text>&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end deftp&#xa;</xsl:text>
+ <xsl:text>&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:var">
+ <xsl:call-template name="arglist">
+ <xsl:with-param name="arguments">
+ <xsl:apply-templates />
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="arglist">
+ <xsl:param name="arguments" />
+ <xsl:variable name="content" select="normalize-space($arguments)" />
+ <xsl:choose>
+ <xsl:when test="contains($content, ' ')">
+ <xsl:call-template name="arglist">
+ <xsl:with-param
+ name="arguments"
+ select="substring-before($content, ' ')" />
+ </xsl:call-template>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="arglist">
+ <xsl:with-param
+ name="arguments"
+ select="substring-after($content, ' ')" />
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$content != ''">
+ <xsl:text>@var{</xsl:text>
+ <xsl:value-of select="$content" />
+ <xsl:text>}</xsl:text>
+ </xsl:when>
+ <xsl:otherwise />
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="html:strong">
+ <xsl:text>@strong{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:ul">
+ <xsl:text>@itemize&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end itemize&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:ol">
+ <xsl:text>@enumerate&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@end enumerate&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:li">
+ <xsl:text>@item&#xa;</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>@c fill&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="html:emph">
+ <xsl:text>@emph{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:var">
+ <xsl:text>@var{</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>}</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:gfdl">
+ <xsl:text>@include fdl.texi&#xa;&#xa;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="info:printindex">
+ <xsl:text>@printindex cp&#xa;&#xa;</xsl:text>
+ </xsl:template>
+</xsl:stylesheet>