pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / site / src / documentation / skins / common / xslt / html / document-to-html.xsl
1 <?xml version="1.0"?>
2 <!--
3   Licensed to the Apache Software Foundation (ASF) under one or more
4   contributor license agreements.  See the NOTICE file distributed with
5   this work for additional information regarding copyright ownership.
6   The ASF licenses this file to You under the Apache License, Version 2.0
7   (the "License"); you may not use this file except in compliance with
8   the License.  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 -->
18 <!--
19 This stylesheet contains the majority of templates for converting documentv11
20 to HTML.  It renders XML as HTML in this form:
21
22   <div class="content">
23    ...
24   </div>
25
26 ..which site-to-xhtml.xsl then combines with HTML from the index (book-to-menu.xsl)
27 and tabs (tab-to-menu.xsl) to generate the final HTML.
28
29 Section handling
30   - <a name/> anchors are added if the id attribute is specified
31
32 -->
33 <xsl:stylesheet version="1.0"
34                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
35   <xsl:param name="dynamic-page" select="'false'"/>
36   <xsl:param name="notoc"/>
37   <xsl:param name="path"/>
38 <!-- <xsl:include href="split.xsl"/> -->
39   <xsl:include href="dotdots.xsl"/>
40   <xsl:include href="pathutils.xsl"/>
41 <!-- Path to site root, eg '../../' -->
42   <xsl:variable name="root">
43     <xsl:call-template name="dotdots">
44       <xsl:with-param name="path" select="$path"/>
45     </xsl:call-template>
46   </xsl:variable>
47   <xsl:variable name="skin-img-dir" select="concat(string($root), 'skin/images')"/>
48   <xsl:template match="/">
49     <xsl:apply-templates mode="toc"/>
50     <xsl:apply-templates/>
51   </xsl:template>
52   <xsl:template match="document">
53     <div class="content">
54       <table summary="" class="title">
55         <tr>
56           <td valign="middle">
57             <xsl:if test="normalize-space(header/title)!=''">
58               <h1>
59                 <xsl:value-of select="header/title"/>
60               </h1>
61             </xsl:if>
62           </td>
63           <div id="skinconf-printlink"/>
64           <xsl:if test="$dynamic-page='false'">
65             <div id="skinconf-pdflink"/>
66             <div id="skinconf-xmllink"/>
67           </xsl:if>
68         </tr>
69       </table>
70       <xsl:if test="normalize-space(header/subtitle)!=''">
71         <h3>
72           <xsl:value-of select="header/subtitle"/>
73         </h3>
74       </xsl:if>
75       <xsl:apply-templates select="header/type"/>
76       <xsl:apply-templates select="header/notice"/>
77       <xsl:apply-templates select="header/abstract"/>
78       <xsl:apply-templates select="body"/>
79       <div class="attribution">
80         <xsl:apply-templates select="header/authors"/>
81         <xsl:if test="header/authors and header/version">
82 <xsl:text>; </xsl:text>
83         </xsl:if>
84         <xsl:apply-templates select="header/version"/>
85       </div>
86     </div>
87   </xsl:template>
88   <xsl:template match="body">
89     <div id="skinconf-toc-page"/>
90     <xsl:apply-templates/>
91   </xsl:template>
92 <!-- Generate a <a name="..."> tag for an @id -->
93   <xsl:template match="@id">
94     <xsl:if test="normalize-space(.)!=''"><a name="{.}"/>
95     </xsl:if>
96   </xsl:template>
97   <xsl:template match="section">
98 <!-- count the number of section in the ancestor-or-self axis to compute
99          the title element name later on -->
100     <xsl:variable name="sectiondepth" select="count(ancestor-or-self::section)"/><a name="{generate-id()}"/>
101     <xsl:apply-templates select="@id"/>
102 <!-- generate a title element, level 1 -> h3, level 2 -> h4 and so on... -->
103     <xsl:element name="{concat('h',$sectiondepth + 2)}">
104       <xsl:value-of select="title"/>
105       <xsl:if test="$notoc='true' and $sectiondepth = 3">
106         <span style="float: right"><a href="#{@id}-menu">^</a>
107         </span>
108       </xsl:if>
109     </xsl:element>
110 <!-- Indent FAQ entry text 15 pixels -->
111     <xsl:variable name="indent">
112       <xsl:choose>
113         <xsl:when test="$notoc='true' and $sectiondepth = 3">
114 <xsl:text>15</xsl:text>
115         </xsl:when>
116         <xsl:otherwise>
117 <xsl:text>0</xsl:text>
118         </xsl:otherwise>
119       </xsl:choose>
120     </xsl:variable>
121     <div style="margin-left: {$indent} ; border: 2px">
122       <xsl:apply-templates select="*[not(self::title)]"/>
123     </div>
124   </xsl:template>
125   <xsl:template match="note | warning | fixme">
126     <xsl:apply-templates select="@id"/>
127     <div>
128       <xsl:call-template name="add.class">
129         <xsl:with-param name="class">
130           <xsl:value-of select="local-name()"/>
131         </xsl:with-param>
132       </xsl:call-template>
133       <div class="label">
134         <xsl:choose>
135 <!-- FIXME: i18n Transformer here -->
136           <xsl:when test="@label">
137             <xsl:value-of select="@label"/>
138           </xsl:when>
139           <xsl:when test="local-name() = 'note'">Note</xsl:when>
140           <xsl:when test="local-name() = 'warning'">Warning</xsl:when>
141           <xsl:otherwise>Fixme (<xsl:value-of select="@author"/>)</xsl:otherwise>
142         </xsl:choose>
143       </div>
144       <div class="content">
145         <xsl:apply-templates/>
146       </div>
147     </div>
148   </xsl:template>
149   <xsl:template match="notice">
150     <div class="notice">
151 <!-- FIXME: i18n Transformer here -->
152 <xsl:text>Notice: </xsl:text>
153       <xsl:apply-templates/>
154     </div>
155   </xsl:template>
156   <xsl:template match="link">
157     <xsl:apply-templates select="@id"/><a>
158     <xsl:if test="@class='jump'">
159       <xsl:attribute name="target">_top</xsl:attribute>
160     </xsl:if>
161     <xsl:if test="@class='fork'">
162       <xsl:attribute name="target">_blank</xsl:attribute>
163     </xsl:if>
164     <xsl:copy-of select="@*"/>
165     <xsl:apply-templates/></a>
166   </xsl:template>
167   <xsl:template match="jump">
168     <xsl:apply-templates select="@id"/><a href="{@href}" target="_top">
169     <xsl:apply-templates/></a>
170   </xsl:template>
171   <xsl:template match="fork">
172     <xsl:apply-templates select="@id"/><a href="{@href}" target="_blank">
173     <xsl:apply-templates/></a>
174   </xsl:template>
175   <xsl:template match="p[@xml:space='preserve']">
176     <xsl:apply-templates select="@id"/>
177     <div class="pre">
178       <xsl:copy-of select="@id"/>
179       <xsl:apply-templates/>
180     </div>
181   </xsl:template>
182   <xsl:template match="source">
183     <xsl:apply-templates select="@id"/>
184     <pre class="code">
185 <!-- Temporarily removed long-line-splitter ... gives out-of-memory problems -->
186       <xsl:copy-of select="@id"/>
187       <xsl:apply-templates/>
188 <!--
189     <xsl:call-template name="format">
190     <xsl:with-param select="." name="txt" />
191      <xsl:with-param name="width">80</xsl:with-param>
192      </xsl:call-template>
193 -->
194     </pre>
195   </xsl:template>
196   <xsl:template match="anchor"><a name="{@id}">
197     <xsl:copy-of select="@id"/></a>
198   </xsl:template>
199   <xsl:template match="icon">
200     <xsl:apply-templates select="@id"/>
201     <img class="icon">
202       <xsl:copy-of select="@height | @width | @src | @alt | @id"/>
203     </img>
204   </xsl:template>
205   <xsl:template match="code">
206     <xsl:apply-templates select="@id"/>
207     <span>
208       <xsl:call-template name="add.class">
209         <xsl:with-param name="class">codefrag</xsl:with-param>
210       </xsl:call-template>
211       <xsl:copy-of select="@id"/>
212       <xsl:value-of select="."/>
213     </span>
214   </xsl:template>
215   <xsl:template match="figure">
216     <xsl:apply-templates select="@id"/>
217     <div align="center">
218       <xsl:copy-of select="@id"/>
219       <img class="figure">
220         <xsl:copy-of select="@height | @width | @src | @alt | @id"/>
221       </img>
222     </div>
223   </xsl:template>
224   <xsl:template match="table">
225     <xsl:apply-templates select="@id"/>
226     <xsl:choose>
227 <!-- Limit Forrest specific processing to tables without class -->
228       <xsl:when test="not(@class) or @class=''">
229         <table cellpadding="4" cellspacing="1" class="ForrestTable">
230           <xsl:copy-of select="@cellspacing | @cellpadding | @border | @class | @bgcolor |@id"/>
231           <xsl:apply-templates/>
232         </table>
233       </xsl:when>
234       <xsl:otherwise>
235 <!-- Tables with class are passed without change -->
236         <xsl:copy>
237           <xsl:copy-of select="@*"/>
238           <xsl:apply-templates/>
239         </xsl:copy>
240       </xsl:otherwise>
241     </xsl:choose>
242     <xsl:if test="@class = ''"></xsl:if>
243   </xsl:template>
244   <xsl:template match="acronym/@title">
245     <xsl:attribute name="title">
246       <xsl:value-of select="normalize-space(.)"/>
247     </xsl:attribute>
248   </xsl:template>
249   <xsl:template match="header/authors">
250     <xsl:for-each select="person">
251       <xsl:choose>
252         <xsl:when test="position()=1">by</xsl:when>
253         <xsl:otherwise>,</xsl:otherwise>
254       </xsl:choose>
255 <xsl:text> </xsl:text>
256       <xsl:value-of select="@name"/>
257     </xsl:for-each>
258   </xsl:template>
259   <xsl:template match="version">
260     <span class="version">
261       <xsl:apply-templates select="@major"/>
262       <xsl:apply-templates select="@minor"/>
263       <xsl:apply-templates select="@fix"/>
264       <xsl:apply-templates select="@tag"/>
265       <xsl:choose>
266         <xsl:when test="starts-with(., '$Revision: ')">
267           version <xsl:value-of select="substring(., 12, string-length(.) -11-2)"/>
268         </xsl:when>
269         <xsl:otherwise>
270           <xsl:value-of select="."/>
271         </xsl:otherwise>
272       </xsl:choose>
273     </span>
274   </xsl:template>
275   <xsl:template match="@major">
276      v<xsl:value-of select="."/>
277   </xsl:template>
278   <xsl:template match="@minor | @fix">
279     <xsl:value-of select="concat('.',.)"/>
280   </xsl:template>
281   <xsl:template match="@tag">
282     <xsl:value-of select="concat('-',.)"/>
283   </xsl:template>
284   <xsl:template match="type">
285     <p class="type">
286 <!-- FIXME: i18n Transformer here -->
287 <xsl:text>Type: </xsl:text>
288       <xsl:value-of select="."/>
289     </p>
290   </xsl:template>
291   <xsl:template match="abstract">
292     <p>
293       <xsl:apply-templates/>
294     </p>
295   </xsl:template>
296   <xsl:template name="email"><a>
297     <xsl:attribute name="href">
298       <xsl:value-of select="concat('mailto:',@email)"/>
299     </xsl:attribute>
300     <xsl:value-of select="@name"/></a>
301   </xsl:template>
302   <xsl:template name="generate-id">
303     <xsl:choose>
304       <xsl:when test="@id">
305         <xsl:value-of select="@id"/>
306       </xsl:when>
307       <xsl:when test="@title">
308         <xsl:value-of select="@title"/>
309       </xsl:when>
310       <xsl:otherwise>
311         <xsl:value-of select="generate-id(.)"/>
312       </xsl:otherwise>
313     </xsl:choose>
314   </xsl:template>
315 <!--  Templates for "toc" mode.  This will generate a complete
316         Table of Contents for the document.  This will then be used
317         by the site2xhtml to generate a Menu ToC and a Page ToC -->
318   <xsl:template match="document" mode="toc">
319     <xsl:apply-templates mode="toc"/>
320   </xsl:template>
321   <xsl:template match="body" mode="toc">
322     <tocitems>
323       <xsl:if test="../header/meta[@name='forrest.force-toc'] = 'true'">
324         <xsl:attribute name="force">true</xsl:attribute>
325       </xsl:if>
326       <xsl:apply-templates select="section" mode="toc">
327         <xsl:with-param name="level" select="1"/>
328       </xsl:apply-templates>
329     </tocitems>
330   </xsl:template>
331   <xsl:template match="section" mode="toc">
332     <xsl:param name="level"/>
333     <tocitem level="{$level}">
334       <xsl:attribute name="href">#<xsl:call-template name="generate-id"/>
335       </xsl:attribute>
336       <xsl:attribute name="title">
337         <xsl:value-of select="title"/>
338       </xsl:attribute>
339       <xsl:apply-templates mode="toc">
340         <xsl:with-param name="level" select="$level+1"/>
341       </xsl:apply-templates>
342     </tocitem>
343   </xsl:template>
344   <xsl:template name="add.class">
345 <!-- use the parameter to set class attribute -->
346 <!-- if there are already classes set, adds to them -->
347     <xsl:param name="class"/>
348     <xsl:attribute name="class">
349       <xsl:choose>
350         <xsl:when test="@class">
351           <xsl:value-of select="$class"/>
352 <xsl:text> </xsl:text>
353           <xsl:value-of select="@class"/>
354         </xsl:when>
355         <xsl:otherwise>
356           <xsl:value-of select="$class"/>
357         </xsl:otherwise>
358       </xsl:choose>
359     </xsl:attribute>
360   </xsl:template>
361   <xsl:template match="node()|@*" mode="toc"/>
362 <!-- End of "toc" mode templates -->
363   <xsl:template match="node()|@*" priority="-1">
364 <!-- id processing will create its own a-element so processing has to 
365          happen outside the copied element 
366     -->
367     <xsl:apply-templates select="@id"/>
368     <xsl:copy>
369       <xsl:apply-templates select="@*[name(.) != 'id']"/>
370       <xsl:copy-of select="@id"/>
371       <xsl:apply-templates/>
372     </xsl:copy>
373   </xsl:template>
374 </xsl:stylesheet>