1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<!-- ==================================================================== -->
<!-- Ordinary HTML that must be converted to latex -->
<!-- ==================================================================== -->
<xsl:template match="ul">
<xsl:text>\begin{itemize}
</xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{itemize}
</xsl:text>
</xsl:template>
<xsl:template match="ol">
<xsl:text>\begin{enumerate}
</xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{enumerate}
</xsl:text>
</xsl:template>
<xsl:template match="li">
<xsl:text>\item </xsl:text>
<xsl:apply-templates/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="dl">
<xsl:text>\begin{description}
</xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{description}
</xsl:text>
</xsl:template>
<xsl:template match="dt">
<xsl:text>\item[</xsl:text><xsl:apply-templates/>
<xsl:text>] </xsl:text>
</xsl:template>
<xsl:template match="dd">
<xsl:apply-templates/>
</xsl:template>
<!-- Latex doesn't like successive line breaks, so replace any
sequence of two or more br separated only by white-space with
one line break followed by smallskips. -->
<xsl:template match="br">
<xsl:choose>
<xsl:when test="name(preceding-sibling::node()[1])='br' or name(preceding-sibling::node()[1])='indent'">
<xsl:text>\smallskip </xsl:text>
</xsl:when>
<xsl:when test="name(preceding-sibling::node()[2])='br' or name(preceding-sibling::node()[2])='indent'">
<xsl:choose>
<xsl:when test="normalize-space(preceding-sibling::node()[1])=''">
<xsl:text>\smallskip </xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Don't put a line break if we are the last thing -->
<xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
<xsl:text>\\ </xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- Don't put a line break if we are the last thing -->
<xsl:if test="not(position()=last()) and not(position()=last()-1 and normalize-space(following-sibling::node()[1])='')">
<xsl:text>\\ </xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="p">
<xsl:apply-templates/>
<xsl:text>\par
</xsl:text>
</xsl:template>
<xsl:template match="code">
<xsl:text>\texttt{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="strong">
<xsl:text>\textbf{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="em">
<xsl:text>\textit{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}</xsl:text>
</xsl:template>
<!-- Value-of used here explicitly because we don't wan't latex-escaping
performed. Of course, this will conflict with html where some tags are
interpreted in pre -->
<xsl:template match="pre">
<xsl:text>\begin{verbatim}
</xsl:text>
<xsl:value-of select="."/>
<xsl:text>\end{verbatim}
</xsl:text>
</xsl:template>
<xsl:template match="blockquote">
<xsl:text>\begin{quotation}
</xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{quotation}
</xsl:text>
</xsl:template>
<!-- XXX: We need to deal with table headers -->
<xsl:template match="table">
<xsl:variable name="table-type">
<xsl:choose>
<xsl:when test="count(tr) > 15">longtable</xsl:when>
<xsl:otherwise>tabular</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:text>\begin{</xsl:text><xsl:value-of select="$table-type"/>
<xsl:text>}{|</xsl:text>
<xsl:choose>
<xsl:when test="columnspec">
<xsl:for-each select="columnspec/column">
<xsl:text>l</xsl:text>
<xsl:if test="../../@border and not(position()=last())">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="tr[1]/*">
<xsl:text>l</xsl:text>
<xsl:if test="../../@border and not(position()=last())">
<xsl:text>|</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:text>|}\hline
</xsl:text>
<xsl:apply-templates select="tr"/>
<xsl:text>\hline\end{</xsl:text>
<xsl:value-of select="$table-type"/>
<xsl:text>}
</xsl:text>
</xsl:template>
<xsl:template match="tr">
<xsl:apply-templates select="td|th"/>
<xsl:text>\\</xsl:text>
<xsl:if test="../@border and not(position()=last())">
<xsl:text>\hline</xsl:text>
</xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="td">
<xsl:variable name="pos" select="position()"/>
<xsl:text>\begin{minipage}[t]{</xsl:text>
<xsl:choose>
<xsl:when test="../../columnspec">
<xsl:value-of select="../../columnspec/column[$pos]/@width"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=".95 div last()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>\textwidth}\small </xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{minipage}</xsl:text>
<xsl:if test="not(position()=last())">
<xsl:text> & </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="th">
<xsl:variable name="pos" select="position()"/>
<xsl:text>\begin{minipage}[t]{</xsl:text>
<xsl:choose>
<xsl:when test="../../columnspec">
<xsl:value-of select="../../columnspec/column[$pos]/@width"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=".95 div last()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>\textwidth}\bfseries </xsl:text>
<xsl:apply-templates/>
<xsl:text>\end{minipage}</xsl:text>
<xsl:if test="not(position()=last())">
<xsl:text> & </xsl:text>
</xsl:if>
</xsl:template>
<!--
This is a horrible hack, but it seems to mostly work. It does a
few things:
1. Transforms references starting in http:// to footnotes with the
appropriate hyperref macro to make them clickable. (This needs
to be expanded to deal with news: and needs to be adjusted to
deal with "#", which is creating bad links at the moment.)
2. For intra-document references, constructs the appropriate absolute
reference using a latex \pageref.
This involves applying a simplified version of the
general URL resolution rules to deal with ../. It only works for
one level of subdirectory.
3. It is also necessary to deal with the fact that index pages
get references as "/".
-->
<xsl:template match="a">
<xsl:apply-templates/>
<xsl:if test="@href">
<xsl:variable name="relpath" select="document(/*/@metafile)/metafile/relpath" />
<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
<xsl:variable name="fileref">
<xsl:choose>
<xsl:when test="contains(@href, '.html')">
<xsl:value-of select="substring-before(@href, '.html')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(@href, 'index')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="starts-with(@href, 'http:') or starts-with(@href, 'news:') or starts-with(@href, 'mailto:')">
<xsl:if test="not(.=@href)">
<xsl:text>\footnote{</xsl:text>
<xsl:text>\href{</xsl:text>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="@href"/>
<xsl:with-param name="replace" select="'#'"/>
<xsl:with-param name="with" select="'\#'"/>
</xsl:call-template>
<xsl:text>}{</xsl:text>
<xsl:call-template name="ltescape">
<xsl:with-param name="string" select="@href"/>
</xsl:call-template>
<xsl:text>}}</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="starts-with(@href, '#')">
<!-- Don't do inter-section references -->
</xsl:when>
<xsl:otherwise>
<xsl:text> (p.\ \pageref{</xsl:text>
<xsl:call-template name="replace-string">
<xsl:with-param name="replace" select="'#'"/>
<xsl:with-param name="with" select="':'"/>
<xsl:with-param name="text">
<xsl:choose>
<xsl:when test="$relpath='.'">
<xsl:value-of select="concat('/',$fileref)"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="starts-with($fileref,'..')">
<xsl:value-of select="substring-after($fileref,'..')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($path,$fileref)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:text>}) </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="img">
<xsl:variable name="path" select="document(/*/@metafile)/metafile/path" />
<xsl:text>\includegraphics{</xsl:text>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="concat('.',$path,@src)"/>
<xsl:with-param name="replace" select="'.gif'"/>
<xsl:with-param name="with" select="''"/>
</xsl:call-template>
<xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>
|