html.xsl revision 0097a4f3e468c0192a2ce52ffee7bc8cea0a620b
2N/A<?
xml version="1.0"?>
2N/A Copyright 2003-2004 The Apache Software Foundation 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 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<
xsl:
stylesheet version="1.0" 32N/A<!-- ==================================================================== --> 32N/A<!-- Ordinary HTML that must be converted to latex --> 313N/A<!-- ==================================================================== --> 313N/A<
xsl:
template match="ul">
313N/A<
xsl:
text>\begin{itemize}
313N/A<
xsl:
template match="ol">
313N/A<
xsl:
text>\begin{enumerate}
313N/A<
xsl:
text>\end{enumerate}
127N/A<
xsl:
template match="li">
127N/A<
xsl:
text>\item </
xsl:
text>
538N/A<
xsl:
template match="dl">
538N/A<
xsl:
text>\begin{description}
327N/A<
xsl:
text>\end{description}
327N/A<
xsl:
template match="dt">
327N/A<
xsl:
text>\item[</
xsl:
text><
xsl:
apply-
templates/>
327N/A<
xsl:
template match="dd">
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">
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>
538N/A<
xsl:
when test="name(preceding-sibling::node()[2])='br' or name(preceding-sibling::node()[2])='indent'">
2N/A <
xsl:
when test="normalize-space(preceding-sibling::node()[1])=''">
6N/A <
xsl:
text>\smallskip </
xsl:
text>
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>
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>
61N/A<
xsl:
template match="p">
61N/A<
xsl:
template match="code">
220N/A<
xsl:
text>\texttt{</
xsl:
text>
61N/A<
xsl:
text>}</
xsl:
text>
61N/A<
xsl:
template match="strong">
172N/A<
xsl:
text>\textbf{</
xsl:
text>
61N/A<
xsl:
apply-
templates/>
220N/A<
xsl:
template match="em">
85N/A<
xsl:
text>\textit{</
xsl:
text>
61N/A<
xsl:
text>}</
xsl:
text>
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}
61N/A<
xsl:
value-
of select="."/>
172N/A<
xsl:
text>\end{verbatim}
152N/A<
xsl:
template match="blockquote">
152N/A<
xsl:
text>\begin{quotation}
61N/A<
xsl:
apply-
templates/>
61N/A<
xsl:
text>\end{quotation}
120N/A<!-- XXX: We need to deal with table headers --> 64N/A<
xsl:
template match="table">
64N/A<
xsl:
variable name="table-type">
43N/A <
xsl:
when test="count(tr) > 15">longtable</
xsl:
when>
120N/A <
xsl:
otherwise>tabular</
xsl:
otherwise>
220N/A<
xsl:
text>\begin{</
xsl:
text><
xsl:
value-
of select="$table-type"/>
64N/A<
xsl:
text>}{|</
xsl:
text>
486N/A<
xsl:
when test="columnspec">
64N/A <
xsl:
text>l</
xsl:
text>
64N/A <
xsl:
if test="../../@border and not(position()=last())">
64N/A <
xsl:
text>|</
xsl:
text>
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>
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:
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>
12N/A<
xsl:
template match="td">
181N/A <
xsl:
variable name="pos" select="position()"/>
181N/A <
xsl:
text>\begin{minipage}[t]{</
xsl:
text>
279N/A <
xsl:
value-
of select=".95 div last()"/>
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> & </
xsl:
text>
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:
value-
of select=".95 div last()"/>
99N/A <
xsl:
text>\textwidth}\bfseries </
xsl:
text>
2N/A <
xsl:
text>\end{minipage}</
xsl:
text>
99N/A <
xsl:
if test="not(position()=last())">
206N/A <
xsl:
text> & </
xsl:
text>
151N/A This is a horrible hack, but it seems to mostly work. It does 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 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 3. It is also necessary to deal with the fact that index pages 727N/A<
xsl:
template match="a">
148N/A<
xsl:
variable name="fileref">
148N/A <
xsl:
when test="contains(@href, '.html')">
2N/A <
xsl:
value-
of select="substring-before(@href, '.html')"/>
727N/A <
xsl:
value-
of select="concat(@href, 'index')"/>
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="'\#'"/>
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:
text>}}</
xsl:
text>
260N/A<
xsl:
when test="starts-with(@href, '#')">
260N/A<!-- Don't do inter-section references --> 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:
when test="$relpath='.'">
260N/A <
xsl:
value-
of select="concat('/',$fileref)"/>
260N/A <
xsl:
when test="starts-with($fileref,'..')">
2N/A <
xsl:
value-
of select="substring-after($fileref,'..')"/>
99N/A <
xsl:
value-
of select="concat($path,$fileref)"/>
70N/A </
xsl:
call-
template>
2N/A <
xsl:
text>}) </
xsl:
text>
2N/A<
xsl:
template match="img">
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>