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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
19 site-to-xhtml.xsl is the final stage in HTML page production. It merges HTML from
20 document-to-html.xsl, tab-to-menu.xsl and book-to-menu.xsl, and adds the site header,
21 footer, searchbar, css etc. As input, it takes XML of the form:
36 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37 xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
38 <xsl:variable name="config" select="//skinconfig"/>
39 <!-- If true, a txt link for this page will not be generated -->
40 <xsl:variable name="disable-txt-link" select="//skinconfig/disable-txt-link"/>
41 <!-- If true, a PDF link for this page will not be generated -->
42 <xsl:variable name="disable-pdf-link" select="//skinconfig/disable-pdf-link"/>
43 <!-- If true, a "print" link for this page will not be generated -->
44 <xsl:variable name="disable-print-link" select="//skinconfig/disable-print-link"/>
45 <!-- If true, an XML link for this page will not be generated -->
46 <xsl:variable name="disable-xml-link" select="//skinconfig/disable-xml-link"/>
47 <!-- If true, a POD link for this page will not be generated -->
48 <xsl:variable name="disable-pod-link" select="//skinconfig/disable-pod-link"/>
49 <!-- Get the location where to generate the minitoc -->
50 <xsl:variable name="minitoc-location" select="//skinconfig/toc/@location"/>
51 <xsl:param name="path"/>
52 <xsl:include href="dotdots.xsl"/>
53 <xsl:include href="pathutils.xsl"/>
54 <xsl:include href="renderlogo.xsl"/>
55 <!-- Path (..'s) to the root directory -->
56 <xsl:variable name="root">
57 <xsl:call-template name="dotdots">
58 <xsl:with-param name="path" select="$path"/>
61 <!-- Source filename (eg 'foo.xml') of current page -->
62 <xsl:variable name="filename">
63 <xsl:call-template name="filename">
64 <xsl:with-param name="path" select="$path"/>
67 <!-- Path of Lucene search results page (relative to $root) -->
68 <xsl:param name="lucene-search" select="'lucene-search.html'"/>
69 <xsl:variable name="filename-noext">
70 <xsl:call-template name="filename-noext">
71 <xsl:with-param name="path" select="$path"/>
74 <!-- Whether to obfuscate email links -->
75 <xsl:variable name="obfuscate-mail-links" select="//skinconfig/obfuscate-mail-links"/>
76 <!-- If true, the font size script will not be rendered -->
77 <xsl:variable name="disable-font-script" select="//skinconfig/disable-font-script"/>
78 <!-- If true, an the images on all external links will not be added -->
79 <xsl:variable name="disable-external-link-image" select="//skinconfig/disable-external-link-image"/>
80 <xsl:variable name="skin-img-dir" select="concat(string($root), 'skin/images')"/>
81 <xsl:variable name="spacer" select="concat($root, 'skin/images/spacer.gif')"/>
82 <xsl:template name="breadcrumbs">
83 <xsl:if test="(//skinconfig/trail/link1/@name)and(//skinconfig/trail/link1/@name!='')"><a href="{//skinconfig/trail/link1/@href}">
84 <xsl:value-of select="//skinconfig/trail/link1/@name"/></a>
86 <xsl:if test="(//skinconfig/trail/link2/@name)and(//skinconfig/trail/link2/@name!='')"> > <a href="{//skinconfig/trail/link2/@href}">
87 <xsl:value-of select="//skinconfig/trail/link2/@name"/></a>
89 <xsl:if test="(//skinconfig/trail/link3/@name)and(//skinconfig/trail/link3/@name!='')"> > <a href="{//skinconfig/trail/link3/@href}">
90 <xsl:value-of select="//skinconfig/trail/link3/@name"/></a>
92 <script type="text/javascript" language="JavaScript" src="{$root}skin/breadcrumbs.js"/>
94 <xsl:template match="site">
97 <title><xsl:value-of select="div[@class='content']/table/tr/td/h1"/></title>
98 <xsl:if test="//skinconfig/favicon-url"><link rel="shortcut icon">
99 <xsl:attribute name="href">
100 <xsl:value-of select="concat($root,//skinconfig/favicon-url)"/>
101 </xsl:attribute></link>
105 <xsl:if test="//skinconfig/group-url">
106 <xsl:call-template name="renderlogo">
107 <xsl:with-param name="name" select="//skinconfig/group-name"/>
108 <xsl:with-param name="url" select="//skinconfig/group-url"/>
109 <xsl:with-param name="logo" select="//skinconfig/group-logo"/>
110 <xsl:with-param name="root" select="$root"/>
111 <xsl:with-param name="description" select="//skinconfig/group-description"/>
114 <xsl:call-template name="renderlogo">
115 <xsl:with-param name="name" select="//skinconfig/project-name"/>
116 <xsl:with-param name="url" select="//skinconfig/project-url"/>
117 <xsl:with-param name="logo" select="//skinconfig/project-logo"/>
118 <xsl:with-param name="root" select="$root"/>
119 <xsl:with-param name="description" select="//skinconfig/project-description"/>
121 <xsl:comment>================= start Tabs ==================</xsl:comment>
122 <xsl:apply-templates select="div[@class='tab']"/>
123 <xsl:comment>================= end Tabs ==================</xsl:comment>
124 <xsl:comment>================= start Menu items ==================</xsl:comment>
125 <xsl:apply-templates select="div[@class='menu']"/>
126 <xsl:comment>================= end Menu items ==================</xsl:comment>
127 <xsl:comment>================= start Content==================</xsl:comment>
128 <xsl:apply-templates select="div[@class='content']"/>
129 <xsl:comment>================= end Content==================</xsl:comment>
130 <xsl:comment>================= start Footer ==================</xsl:comment>
132 <xsl:when test="$config/copyright-link"><a>
133 <xsl:attribute name="href">
134 <xsl:value-of select="$config/copyright-link"/>
136 Copyright © <xsl:value-of select="$config/year"/>
137 <xsl:call-template name="current-year">
138 <xsl:with-param name="copyrightyear" select="$config/year"/>
139 </xsl:call-template> 
140 <xsl:value-of select="$config/vendor"/></a>
143 Copyright © <xsl:value-of select="$config/year"/>
144 <xsl:call-template name="current-year">
145 <xsl:with-param name="copyrightyear" select="$config/year"/>
146 </xsl:call-template> 
147 <xsl:value-of select="$config/vendor"/>
151 <script language="JavaScript" type="text/javascript"><![CDATA[<!--
152 document.write(" - "+"Last Published: " + document.lastModified);
154 <xsl:if test="//skinconfig/host-logo and not(//skinconfig/host-logo = '')"><a href="{//skinconfig/host-url}">
155 <xsl:call-template name="renderlogo">
156 <xsl:with-param name="name" select="//skinconfig/host-name"/>
157 <xsl:with-param name="url" select="//skinconfig/host-url"/>
158 <xsl:with-param name="logo" select="//skinconfig/host-logo"/>
159 <xsl:with-param name="root" select="$root"/>
160 </xsl:call-template></a>
162 <xsl:if test="$filename = 'index.html' and //skinconfig/credits">
163 <xsl:for-each select="//skinconfig/credits/credit[not(@role='pdf')]">
164 <xsl:call-template name="renderlogo">
165 <xsl:with-param name="name" select="name"/>
166 <xsl:with-param name="url" select="url"/>
167 <xsl:with-param name="logo" select="image"/>
168 <xsl:with-param name="root" select="$root"/>
169 <xsl:with-param name="width" select="width"/>
170 <xsl:with-param name="height" select="height"/>
173 </xsl:if><a href="http://validator.w3.org/check/referer">
174 <img class="skin" border="0"
175 src="http://www.w3.org/Icons/valid-html401"
176 alt="Valid HTML 4.01!" height="31" width="88"/></a>
180 <!-- Add links to any standards-compliance logos -->
181 <xsl:template name="compliancy-logos">
182 <xsl:if test="$filename = 'index.html' and //skinconfig/disable-compliance-links = 'false'"><a href="http://validator.w3.org/check/referer">
183 <img class="logoImage"
184 src="{$skin-img-dir}/valid-html401.png"
185 alt="Valid HTML 4.01!" title="Valid HTML 4.01!" height="31" width="88" border="0"/></a><a href="http://jigsaw.w3.org/css-validator/check/referer">
186 <img class="logoImage"
187 src="{$skin-img-dir}/vcss.png"
188 alt="Valid CSS!" title="Valid CSS!" height="31" width="88" border="0"/></a>
191 <!-- Generates the PDF link -->
192 <xsl:template match="div[@id='skinconf-pdflink']">
193 <xsl:if test="not($config/disable-pdf-link) or $disable-pdf-link = 'false'">
194 <td align="center" width="40" nowrap="nowrap"><a href="{$filename-noext}.pdf" class="dida">
195 <img class="skin" src="{$skin-img-dir}/pdfdoc.gif" alt="PDF"/>
201 <!-- Generates the TXT link -->
202 <xsl:template match="div[@id='skinconf-txtlink']">
203 <xsl:if test="$disable-txt-link = 'false'">
204 <td align="center" width="40" nowrap="nowrap"><a href="{$filename-noext}.txt" class="dida">
205 <img class="skin" src="{$skin-img-dir}/txtdoc.png" alt="TXT"/>
211 <!-- Generates the POD link -->
212 <xsl:template match="div[@id='skinconf-podlink']">
213 <xsl:if test="$disable-pod-link = 'false'">
214 <td align="center" width="40" nowrap="nowrap"><a href="{$filename-noext}.pod" class="dida">
215 <img class="skin" src="{$skin-img-dir}/poddoc.png" alt="POD"/>
221 <!-- Generates the XML link -->
222 <xsl:template match="div[@id='skinconf-xmllink']">
223 <xsl:if test="$disable-xml-link = 'false'">
224 <td align="center" width="40" nowrap="nowrap"><a href="{$filename-noext}.xml" class="dida">
225 <img class="skin" src="{$skin-img-dir}/xmldoc.gif" alt="XML"/>
231 <!-- Generates the "printer friendly version" link -->
232 <xsl:template match="div[@id='skinconf-printlink']">
233 <xsl:if test="$disable-print-link = 'false'">
234 <script type="text/javascript" language="Javascript">
242 var NS = (navigator.appName == "Netscape");
243 var VERSION = parseInt(navigator.appVersion);
245 document.write('<td align="center" width="40" nowrap="nowrap">');
246 document.write(' <a href="javascript:printit()" class="dida">');
247 document.write(' <img class="skin" src="{$skin-img-dir}/printer.gif" alt="Print this Page"/><br />');
248 document.write(' print</a>');
249 document.write('</td>');
254 <!-- handle all obfuscating mail links and disabling external link images -->
255 <xsl:template match="a">
257 <xsl:when test="$obfuscate-mail-links='true' and starts-with(@href, 'mailto:') and contains(@href, '@')">
258 <xsl:variable name="mailto-1" select="substring-before(@href,'@')"/>
259 <xsl:variable name="mailto-2" select="substring-after(@href,'@')"/>
260 <xsl:variable name="obfuscation" select="normalize-space(//skinconfig/obfuscate-mail-value)"/><a href="{$mailto-1}{$obfuscation}{$mailto-2}">
261 <xsl:apply-templates/></a>
263 <xsl:when test="not($disable-external-link-image='true') and contains(@href, ':') and not(contains(@href, //skinconfig/group-url)) and not(contains(@href, //skinconfig/project-url))"><a href="{@href}" class="external">
264 <xsl:apply-templates/></a>
267 <!-- xsl:copy-of makes sure we copy <a href> as well as <a name>
268 or any other <a ...> forms -->
269 <xsl:copy-of select="."/>
273 <xsl:template match="div[@id='skinconf-toc-page']">
274 <xsl:if test="$config/toc">
275 <xsl:if test="contains($minitoc-location,'page')">
276 <xsl:if test="(count(//tocitems/tocitem) >= $config/toc/@min-sections) or (//tocitems/@force = 'true')">
277 <xsl:call-template name="minitoc">
278 <xsl:with-param name="tocroot" select="//tocitems"/>
284 <xsl:template name="minitoc">
285 <xsl:param name="tocroot"/>
286 <xsl:if test="(count($tocroot/tocitem) >= $config/toc/@min-sections) or ($tocroot/@force = 'true')">
287 <xsl:if test="contains($config/toc/@location,'page')">
289 <xsl:for-each select="$tocroot/tocitem">
290 <li><a href="{@href}">
291 <xsl:value-of select="@title"/></a>
292 <xsl:if test="@level<//skinconfig/toc/@max-depth+1">
293 <xsl:call-template name="minitoc">
294 <xsl:with-param name="tocroot" select="."/>
302 <xsl:template name="html-meta">
303 <meta name="Generator" content="Apache Forrest"/>
304 <meta name="Forrest-version">
305 <xsl:attribute name="content">
306 <xsl:value-of select="//info/forrest-version"/>
309 <meta name="Forrest-skin-name">
310 <xsl:attribute name="content">
311 <xsl:value-of select="//info/project-skin"/>
315 <!-- meta information from v 2.0 documents
316 FIXME: the match is really inefficient -->
317 <xsl:template name="meta-data">
318 <xsl:for-each select="//meta-data/meta">
319 <xsl:element name="meta">
320 <xsl:attribute name="name">
321 <xsl:value-of select="@name"/>
323 <xsl:attribute name="content">
324 <xsl:value-of select="."/>
326 <xsl:if test="@xml:lang">
327 <xsl:attribute name="lang">
328 <xsl:value-of select="@xml:lang"/>
334 <xsl:template name="feedback">
336 <xsl:value-of select="$config/feedback"/>
338 <xsl:when test="$config/feedback/@href and not($config/feedback/@href='')"><a id="feedbackto">
339 <xsl:attribute name="href">
340 <xsl:value-of select="$config/feedback/@href"/>
341 <xsl:value-of select="$path"/>
343 <xsl:value-of select="$config/feedback/@to"/></a>
346 <xsl:value-of select="$config/feedback/@to"/>
351 <xsl:template match="node()|@*" priority="-1">
353 <xsl:apply-templates select="@*"/>
354 <xsl:apply-templates/>
357 <!-- inception year copyright management -->
358 <xsl:template name="current-year">
359 <!-- Displays the current year after the inception year (in the copyright i.e: 2002-2005)
360 - the copyright year (2005 by default) can be indicated in the copyrightyear parameter,
361 - the year format (yyyy by default) can be indicated in the dateformat parameter,
362 - the dates separator (- by default) can be indicated in the dateseparator parameter.
363 For instance the following call will format the year on 2 digits and separates the dates
366 <xsl:call-template name="current-year">
367 <xsl:with-param name="copyrightyear" select="'02'"/>
368 <xsl:with-param name="dateformat" select="'yy'"/>
369 <xsl:with-param name="dateseparator" select="'/'"/>
371 Warning, to enable inception year, inception attribute must be set to "true" in copyright/year/@inception
373 <xsl:param name="copyrightyear">2005</xsl:param>
374 <xsl:param name="dateformat">yyyy</xsl:param>
375 <xsl:param name="dateseparator">-</xsl:param>
376 <xsl:if test="$copyrightyear[@inception = 'true']">
377 <xsl:variable name="tz" select='java:java.util.SimpleTimeZone.new(0,"GMT+00:00")' />
378 <xsl:variable name="formatter" select="java:java.text.SimpleDateFormat.new($dateformat)"/>
379 <xsl:variable name="settz" select="java:setTimeZone($formatter, $tz)" />
380 <xsl:variable name="date" select="java:java.util.Date.new()"/>
381 <xsl:variable name="year" select="java:format($formatter, $date)"/>
382 <xsl:if test="$copyrightyear != $year">
383 <xsl:value-of select="$dateseparator"/>
384 <xsl:value-of select="$year"/>