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