html.xsl revision 0097a4f3e468c0192a2ce52ffee7bc8cea0a620b
2N/A<?xml version="1.0"?>
2N/A
2N/A<!--
2N/A Copyright 2003-2004 The Apache Software Foundation
2N/A
2N/A Licensed under the Apache License, Version 2.0 (the "License");
2N/A you may not use this file except in compliance with the License.
2N/A You may obtain a copy of the License at
2N/A
2N/A http://www.apache.org/licenses/LICENSE-2.0
2N/A
2N/A Unless required by applicable law or agreed to in writing, software
2N/A distributed under the License is distributed on an "AS IS" BASIS,
2N/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2N/A See the License for the specific language governing permissions and
2N/A limitations under the License.
2N/A-->
2N/A
2N/A<xsl:stylesheet version="1.0"
2N/A xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
727N/A xmlns="http://www.w3.org/1999/xhtml">
2N/A
2N/A
32N/A<!-- ==================================================================== -->
32N/A<!-- Ordinary HTML that must be converted to latex -->
313N/A<!-- ==================================================================== -->
313N/A
313N/A<xsl:template match="ul">
313N/A<xsl:text>\begin{itemize}
313N/A</xsl:text>
313N/A<xsl:apply-templates/>
313N/A<xsl:text>\end{itemize}
313N/A</xsl:text>
313N/A</xsl:template>
313N/A
313N/A<xsl:template match="ol">
313N/A<xsl:text>\begin{enumerate}
313N/A</xsl:text>
313N/A<xsl:apply-templates/>
313N/A<xsl:text>\end{enumerate}
313N/A</xsl:text>
127N/A</xsl:template>
127N/A
127N/A<xsl:template match="li">
127N/A<xsl:text>\item </xsl:text>
538N/A<xsl:apply-templates/>
538N/A<xsl:text>
538N/A</xsl:text>
538N/A</xsl:template>
538N/A
538N/A<xsl:template match="dl">
538N/A<xsl:text>\begin{description}
538N/A</xsl:text>
327N/A<xsl:apply-templates/>
327N/A<xsl:text>\end{description}
327N/A</xsl:text>
327N/A</xsl:template>
327N/A
327N/A<xsl:template match="dt">
327N/A<xsl:text>\item[</xsl:text><xsl:apply-templates/>
327N/A<xsl:text>] </xsl:text>
327N/A</xsl:template>
327N/A
327N/A<xsl:template match="dd">
327N/A<xsl:apply-templates/>
177N/A</xsl:template>
177N/A
2N/A<!-- Latex doesn't like successive line breaks, so replace any
145N/A sequence of two or more br separated only by white-space with
26N/A one line break followed by smallskips. -->
38N/A<xsl:template match="br">
38N/A<xsl:choose>
26N/A<xsl:when test="name(preceding-sibling::node()[1])='br' or name(preceding-sibling::node()[1])='indent'">
26N/A<xsl:text>\smallskip </xsl:text>
477N/A</xsl:when>
538N/A<xsl:when test="name(preceding-sibling::node()[2])='br' or name(preceding-sibling::node()[2])='indent'">
38N/A <xsl:choose>
2N/A <xsl:when test="normalize-space(preceding-sibling::node()[1])=''">
6N/A <xsl:text>\smallskip </xsl:text>
2N/A </xsl:when>
727N/A <xsl:otherwise>
2N/A <!-- Don't put a line break if we are the last thing -->
34N/A <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
34N/A <xsl:text>\\ </xsl:text>
94N/A </xsl:if>
94N/A </xsl:otherwise>
156N/A </xsl:choose>
156N/A</xsl:when>
34N/A<xsl:otherwise>
59N/A <!-- Don't put a line break if we are the last thing -->
72N/A <xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
72N/A <xsl:text>\\ </xsl:text>
72N/A </xsl:if>
59N/A</xsl:otherwise>
2N/A</xsl:choose>
85N/A</xsl:template>
61N/A
61N/A<xsl:template match="p">
220N/A<xsl:apply-templates/>
61N/A<xsl:text>\par
61N/A</xsl:text>
172N/A</xsl:template>
61N/A
61N/A<xsl:template match="code">
220N/A<xsl:text>\texttt{</xsl:text>
220N/A<xsl:apply-templates/>
61N/A<xsl:text>}</xsl:text>
172N/A</xsl:template>
454N/A
61N/A<xsl:template match="strong">
172N/A<xsl:text>\textbf{</xsl:text>
61N/A<xsl:apply-templates/>
152N/A<xsl:text>}</xsl:text>
74N/A</xsl:template>
61N/A
220N/A<xsl:template match="em">
85N/A<xsl:text>\textit{</xsl:text>
172N/A<xsl:apply-templates/>
61N/A<xsl:text>}</xsl:text>
172N/A</xsl:template>
61N/A
172N/A<!-- Value-of used here explicitly because we don't wan't latex-escaping
61N/Aperformed. Of course, this will conflict with html where some tags are
61N/Ainterpreted in pre -->
220N/A<xsl:template match="pre">
61N/A<xsl:text>\begin{verbatim}
454N/A</xsl:text>
61N/A<xsl:value-of select="."/>
172N/A<xsl:text>\end{verbatim}
61N/A</xsl:text>
172N/A</xsl:template>
61N/A
152N/A<xsl:template match="blockquote">
152N/A<xsl:text>\begin{quotation}
220N/A</xsl:text>
61N/A<xsl:apply-templates/>
61N/A<xsl:text>\end{quotation}
43N/A</xsl:text>
220N/A</xsl:template>
43N/A
120N/A<!-- XXX: We need to deal with table headers -->
64N/A
64N/A<xsl:template match="table">
64N/A<xsl:variable name="table-type">
43N/A <xsl:choose>
43N/A <xsl:when test="count(tr) &gt; 15">longtable</xsl:when>
120N/A <xsl:otherwise>tabular</xsl:otherwise>
64N/A </xsl:choose>
64N/A</xsl:variable>
64N/A
220N/A<xsl:text>\begin{</xsl:text><xsl:value-of select="$table-type"/>
64N/A<xsl:text>}{|</xsl:text>
64N/A<xsl:choose>
486N/A<xsl:when test="columnspec">
486N/A <xsl:for-each select="columnspec/column">
64N/A <xsl:text>l</xsl:text>
64N/A <xsl:if test="../../@border and not(position()=last())">
64N/A <xsl:text>|</xsl:text>
64N/A </xsl:if>
64N/A </xsl:for-each>
64N/A</xsl:when>
64N/A<xsl:otherwise>
43N/A <xsl:for-each select="tr[1]/*">
16N/A <xsl:text>l</xsl:text>
16N/A <xsl:if test="../../@border and not(position()=last())">
16N/A <xsl:text>|</xsl:text>
34N/A </xsl:if>
34N/A </xsl:for-each>
16N/A</xsl:otherwise>
6N/A</xsl:choose>
12N/A<xsl:text>|}\hline
12N/A</xsl:text>
12N/A<xsl:apply-templates select="tr"/>
12N/A<xsl:text>\hline\end{</xsl:text>
12N/A<xsl:value-of select="$table-type"/>
12N/A<xsl:text>}
12N/A</xsl:text>
12N/A</xsl:template>
12N/A
12N/A<xsl:template match="tr">
12N/A <xsl:apply-templates select="td|th"/>
369N/A <xsl:text>\\</xsl:text>
369N/A <xsl:if test="../@border and not(position()=last())">
369N/A <xsl:text>\hline</xsl:text>
61N/A </xsl:if>
61N/A <xsl:text>
61N/A</xsl:text>
61N/A</xsl:template>
61N/A
12N/A<xsl:template match="td">
181N/A <xsl:variable name="pos" select="position()"/>
181N/A <xsl:text>\begin{minipage}[t]{</xsl:text>
12N/A <xsl:choose>
61N/A <xsl:when test="/columnspec">
61N/A <xsl:value-of select="/columnspec/column[$pos]/@width"/>
12N/A </xsl:when>
279N/A <xsl:otherwise>
279N/A <xsl:value-of select=".95 div last()"/>
181N/A </xsl:otherwise>
181N/A </xsl:choose>
181N/A <xsl:text>\textwidth}\small </xsl:text>
2N/A <xsl:apply-templates/>
99N/A <xsl:text>\end{minipage}</xsl:text>
99N/A <xsl:if test="not(position()=last())">
99N/A <xsl:text> &amp; </xsl:text>
181N/A </xsl:if>
181N/A</xsl:template>
181N/A
181N/A<xsl:template match="th">
181N/A <xsl:variable name="pos" select="position()"/>
99N/A <xsl:text>\begin{minipage}[t]{</xsl:text>
40N/A <xsl:choose>
40N/A <xsl:when test="/columnspec">
40N/A <xsl:value-of select="/columnspec/column[$pos]/@width"/>
40N/A </xsl:when>
43N/A <xsl:otherwise>
40N/A <xsl:value-of select=".95 div last()"/>
127N/A </xsl:otherwise>
2N/A </xsl:choose>
99N/A <xsl:text>\textwidth}\bfseries </xsl:text>
206N/A <xsl:apply-templates/>
2N/A <xsl:text>\end{minipage}</xsl:text>
99N/A <xsl:if test="not(position()=last())">
206N/A <xsl:text> &amp; </xsl:text>
2N/A </xsl:if>
151N/A</xsl:template>
206N/A
2N/A<!--
151N/A This is a horrible hack, but it seems to mostly work. It does a
206N/A few things:
2N/A
2N/A 1. Transforms references starting in http:// to footnotes with the
206N/A appropriate hyperref macro to make them clickable. (This needs
2N/A to be expanded to deal with news: and needs to be adjusted to
61N/A deal with "#", which is creating bad links at the moment.)
61N/A
61N/A 2. For intra-document references, constructs the appropriate absolute
61N/A reference using a latex \pageref.
61N/A This involves applying a simplified version of the
16N/A general URL resolution rules to deal with ../. It only works for
16N/A one level of subdirectory.
727N/A
727N/A 3. It is also necessary to deal with the fact that index pages
727N/A get references as "/".
727N/A-->
727N/A<xsl:template match="a">
727N/A<xsl:apply-templates/>
727N/A<xsl:if test="@href">
727N/A<xsl:variable name="relpath" select="document(/*/@metafile)/metafile/relpath" />
148N/A<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
148N/A<xsl:variable name="fileref">
148N/A <xsl:choose>
148N/A <xsl:when test="contains(@href, '.html')">
2N/A <xsl:value-of select="substring-before(@href, '.html')"/>
47N/A </xsl:when>
2N/A <xsl:otherwise>
727N/A <xsl:value-of select="concat(@href, 'index')"/>
727N/A </xsl:otherwise>
727N/A </xsl:choose>
2N/A</xsl:variable>
2N/A<xsl:choose>
148N/A
2N/A<xsl:when test="starts-with(@href, 'http:') or starts-with(@href, 'news:') or starts-with(@href, 'mailto:')">
146N/A <xsl:if test="not(.=@href)">
146N/A <xsl:text>\footnote{</xsl:text>
146N/A <xsl:text>\href{</xsl:text>
146N/A <xsl:call-template name="replace-string">
727N/A <xsl:with-param name="text" select="@href"/>
146N/A <xsl:with-param name="replace" select="'#'"/>
116N/A <xsl:with-param name="with" select="'\#'"/>
116N/A </xsl:call-template>
260N/A <xsl:text>}{</xsl:text>
260N/A <xsl:call-template name="ltescape">
277N/A <xsl:with-param name="string" select="@href"/>
260N/A </xsl:call-template>
260N/A <xsl:text>}}</xsl:text>
260N/A </xsl:if>
260N/A</xsl:when>
260N/A<xsl:when test="starts-with(@href, '#')">
260N/A<!-- Don't do inter-section references -->
260N/A</xsl:when>
127N/A<xsl:otherwise>
260N/A <xsl:text> (p.\ \pageref{</xsl:text>
260N/A <xsl:call-template name="replace-string">
260N/A <xsl:with-param name="replace" select="'#'"/>
260N/A <xsl:with-param name="with" select="':'"/>
260N/A <xsl:with-param name="text">
260N/A <xsl:choose>
260N/A <xsl:when test="$relpath='.'">
260N/A <xsl:value-of select="concat('/',$fileref)"/>
260N/A </xsl:when>
260N/A <xsl:otherwise>
260N/A <xsl:choose>
260N/A <xsl:when test="starts-with($fileref,'..')">
2N/A <xsl:value-of select="substring-after($fileref,'..')"/>
2N/A </xsl:when>
82N/A <xsl:otherwise>
99N/A <xsl:value-of select="concat($path,$fileref)"/>
99N/A </xsl:otherwise>
302N/A </xsl:choose>
2N/A </xsl:otherwise>
105N/A </xsl:choose>
2N/A </xsl:with-param>
70N/A </xsl:call-template>
2N/A <xsl:text>}) </xsl:text>
160N/A</xsl:otherwise>
160N/A</xsl:choose>
160N/A</xsl:if>
160N/A</xsl:template>
165N/A
2N/A<xsl:template match="img">
2N/A<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
2N/A<xsl:text>\includegraphics{</xsl:text>
7N/A <xsl:call-template name="replace-string">
142N/A <xsl:with-param name="text" select="concat('.',$path,@src)"/>
43N/A <xsl:with-param name="replace" select="'.gif'"/>
43N/A <xsl:with-param name="with" select="''"/>
16N/A </xsl:call-template>
43N/A<xsl:text>}</xsl:text>
138N/A</xsl:template>
224N/A
224N/A</xsl:stylesheet>
61N/A