source: branches/stable/HELP_SOURCE/to_html.xsl

Last change on this file was 10842, checked in by westram, 11 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.1 KB
Line 
1
2<!DOCTYPE xsl:stylesheet [
3          <!ENTITY nbsp "&#160;">
4          <!ENTITY acute "&#180;">
5          <!ENTITY dotwidth "20">
6          <!ENTITY dotheight "16">
7          <!ENTITY br "&#xa;">
8          ]>
9
10
11<!-- used to create ARB help in HTML format -->
12
13<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14               version="1.0"
15               >
16
17  <!--  <xsl:output method="html" encoding="iso-8859-1" indent="no"/>-->
18  <xsl:output method="html" indent="no"/>
19
20  <xsl:param name="myname"/>
21  <xsl:param name="xml_location"/>
22
23  <!-- includes -->
24
25  <xsl:include href="date.xsl"/>
26
27  <xsl:variable name="rootpath">
28    <xsl:choose>
29      <xsl:when test="string-length(substring-before($myname,'/'))&gt;0">../</xsl:when>
30      <xsl:otherwise></xsl:otherwise>
31    </xsl:choose>
32  </xsl:variable>
33
34  <xsl:variable name="postscriptpath">
35    <xsl:value-of select="$rootpath"/><xsl:text>../help/</xsl:text>
36  </xsl:variable>
37  <xsl:variable name="pdfpath"><xsl:value-of select="$postscriptpath"/></xsl:variable>
38
39  <xsl:variable name="tableBorder">0</xsl:variable>
40
41  <xsl:variable name="author">ARB development</xsl:variable>
42  <xsl:variable name="maildomain">arb-home.de</xsl:variable>
43
44  <xsl:variable name="fontColor">black</xsl:variable>
45  <xsl:variable name="backgroundColor">white</xsl:variable>
46  <xsl:variable name="linkColor">blue</xsl:variable>
47  <xsl:variable name="visitedLinkColor">green</xsl:variable>
48  <xsl:variable name="activeLinkColor">red</xsl:variable>
49  <xsl:variable name="externalLinkColor">#aa0088</xsl:variable>
50
51  <xsl:variable name="linkSectionsColor">#ccccff</xsl:variable>
52
53  <xsl:variable name="lb"><xsl:text>&br;</xsl:text></xsl:variable> <!--used to detect line-breaks in XML-->
54
55  <!-- =============== -->
56  <!--     warning     -->
57  <!-- =============== -->
58
59  <xsl:template name="error">
60    <xsl:param name="text" select="'Unknown error'"/>
61    <xsl:message terminate="yes"><xsl:value-of select="$text"/></xsl:message>
62  </xsl:template>
63
64  <!-- ============ -->
65  <!--    LINKs     -->
66  <!-- ============ -->
67
68  <!--insert-link-->
69  <xsl:template name="insert-link">
70
71    <xsl:param name="address"/>
72    <xsl:param name="linktext"/>
73
74    <xsl:variable name="external">
75      <xsl:choose>
76        <xsl:when test="starts-with(substring-before($address,'.arb-home.de/'),'http://')">0</xsl:when><!--all arb-home-subdomains-->
77        <xsl:when test="starts-with($address,'http://arb-home.de/')">0</xsl:when>
78        <xsl:when test="starts-with($address,'http://')">1</xsl:when>
79        <xsl:otherwise>0</xsl:otherwise>
80      </xsl:choose>
81    </xsl:variable>
82
83    <xsl:choose>
84      <xsl:when test="$external = 1">
85        <!--if we have an external link -> create popup window-->
86        <A href="{$address}" target="_blank"><FONT color="{$externalLinkColor}"><xsl:value-of select="$linktext"/></FONT></A>
87      </xsl:when>
88      <xsl:otherwise>
89        <A href="{$address}"><xsl:value-of select="$linktext"/></A>
90      </xsl:otherwise>
91    </xsl:choose>
92  </xsl:template>
93
94  <!--insert-email-link-->
95  <xsl:template name="insert-email-link">
96    <xsl:param  name="linktext"/>
97    <xsl:param  name="address" select="arb"/>
98    <xsl:param  name="subject"/>
99
100    <xsl:variable name="add">
101      <xsl:choose>
102        <xsl:when test="string-length(substring-before($address,'@'))>0"><xsl:value-of select="$address"/></xsl:when>
103        <xsl:otherwise><xsl:value-of select="$address"/>@<xsl:value-of select="$maildomain"/></xsl:otherwise>
104      </xsl:choose>
105    </xsl:variable>
106    <xsl:variable name="addsubj">
107      <xsl:choose>
108        <xsl:when test="string-length($subject)>0"><xsl:value-of select="$add"/>?subject=<xsl:value-of select="$subject"/></xsl:when>
109        <xsl:otherwise><xsl:value-of select="$add"/></xsl:otherwise>
110      </xsl:choose>
111    </xsl:variable>
112    <A href="mailto:{$addsubj}">
113      <xsl:choose>
114        <xsl:when test="string-length($linktext)>0"><xsl:value-of select="$linktext"/></xsl:when>
115        <xsl:otherwise><xsl:value-of select="$add"/></xsl:otherwise>
116      </xsl:choose>
117    </A>
118  </xsl:template>
119
120
121  <!-- ============================== -->
122  <!--     insert document header     -->
123  <!-- ============================== -->
124  <xsl:template name="header" >
125    <xsl:param name="title" select="'Untitled'"/>
126    <xsl:comment>Generated from XML - XSLT-Stylesheet by Ralf Westram (ralf@arb-home.de) </xsl:comment>
127    <HEAD>
128      <META NAME="Author" CONTENT="{$author}"/>
129      <meta http-equiv="expires" content="86400"/>
130      <TITLE>ARB help: <xsl:value-of select="$title"/></TITLE>
131      <style type="text/css">
132        <xsl:text>
133          div {
134          margin-left:+10pt;
135          padding-top:3pt;
136          padding-bottom:3pt;
137<!--uncomment for layout fixes--><!--border:1px solid #ffdddd;-->}
138          h3 {
139          font-weight:normal;
140          padding:0px;
141          padding-top:3pt;
142          margin:0px;
143<!--border:1px solid #00bbbb;-->}
144<!--h1 { border:1px solid #008800; }--><!--h2 { border:1px solid #0000ff; }--></xsl:text>
145      </style>
146    </HEAD>
147  </xsl:template>
148
149  <!-- ======================== -->
150  <!--     link-to-document     -->
151  <!-- ======================== -->
152  <xsl:template name="link-to-document">
153    <xsl:param name="doc"/>
154    <xsl:param name="type"/>
155    <xsl:param name="missing"/>
156    <xsl:param name="quote"/>
157
158    <xsl:choose>
159      <xsl:when test="$type='ps'">
160        <A href="{concat($postscriptpath,$doc,'.gz')}">
161          <xsl:value-of select="$doc"/> (Postscript)
162        </A>
163      </xsl:when>
164      <xsl:when test="$type='pdf'">
165        <A href="{concat($pdfpath,$doc,'.gz')}">
166          <xsl:value-of select="$doc"/> (PDF)
167        </A>
168      </xsl:when>
169      <xsl:when test="$type='hlp'">
170        <xsl:variable name="docbase">
171          <xsl:value-of select="substring-before($doc,'.hlp')"/>
172        </xsl:variable>
173        <A href="{concat($rootpath,$docbase)}.html">
174          <xsl:choose>
175            <xsl:when test="$missing='1'">
176              <FONT color="red"><xsl:value-of select="concat('Missing Link to ',$doc)"/></FONT>
177            </xsl:when>
178            <xsl:otherwise>
179              <xsl:for-each select="document(concat($xml_location,'/',$docbase,'.xml'))">
180                <xsl:for-each select="PAGE/TITLE">
181                  <xsl:if test="$quote='1'">&acute;</xsl:if>
182                  <xsl:copy-of select="normalize-space(text())"/>
183                  <xsl:if test="$quote='1'">&acute;</xsl:if>
184                </xsl:for-each>
185              </xsl:for-each>
186            </xsl:otherwise>
187          </xsl:choose>
188        </A>
189      </xsl:when>
190      <xsl:otherwise>
191        <xsl:message terminate="yes">Illegal document type '<xsl:value-of select="$type"/>' in link-to-document</xsl:message>
192      </xsl:otherwise>
193    </xsl:choose>
194  </xsl:template>
195
196  <!-- =============== -->
197  <!--     uplinks     -->
198  <!-- =============== -->
199
200  <xsl:template match="UP" mode="uplinks">
201    <LI>
202      <xsl:call-template name="link-to-document">
203        <xsl:with-param name="doc" select="@dest"/>
204        <xsl:with-param name="type" select="@type"/>
205        <xsl:with-param name="missing" select="@missing"/>
206      </xsl:call-template>
207    </LI>
208  </xsl:template>
209
210  <xsl:template match="*" mode="uplinks">
211    <xsl:call-template name="error"><xsl:with-param name="text">Unwanted match in mode 'uplinks'</xsl:with-param></xsl:call-template>
212  </xsl:template>
213
214  <!-- ================ -->
215  <!--     sublinks     -->
216  <!-- ================ -->
217
218  <xsl:template match="SUB" mode="sublinks">
219    <LI>
220      <xsl:call-template name="link-to-document">
221        <xsl:with-param name="doc" select="@dest"/>
222        <xsl:with-param name="type" select="@type"/>
223        <xsl:with-param name="missing" select="@missing"/>
224      </xsl:call-template>
225    </LI>
226  </xsl:template>
227
228  <xsl:template match="*" mode="sublinks">
229    <xsl:call-template name="error"><xsl:with-param name="text">Unwanted match in mode 'sublinks'</xsl:with-param></xsl:call-template>
230  </xsl:template>
231
232  <!-- =================== -->
233  <!--     reflow mode     -->
234  <!-- =================== -->
235
236  <xsl:template match="text()" mode="reflow">
237    <xsl:variable name="normaltext"><xsl:value-of select="normalize-space(.)"/></xsl:variable>
238    <xsl:choose>
239      <xsl:when test="string-length($normaltext)='0'"></xsl:when><!--skip whitespace-only text-nodes-->
240      <xsl:otherwise>
241        <xsl:variable name="first"><xsl:value-of select="normalize-space(substring(.,1,1))"/></xsl:variable>
242        <xsl:variable name="last"><xsl:value-of select="normalize-space(substring(.,string-length(.)))"/></xsl:variable>
243        <xsl:if test="string-length($first)='0'"><!--if text starts with whitespace ..-->
244          <xsl:variable name="prevtag"><xsl:copy-of select="name(preceding-sibling::*[1])"/></xsl:variable>
245          <xsl:if test="$prevtag='LINK'"><!--.. and preceding-sibling is a LINK -> keep one space-->
246            <xsl:text> </xsl:text>
247          </xsl:if>
248        </xsl:if>
249
250        <xsl:value-of select="$normaltext"/>
251
252        <xsl:if test="string-length($last)='0'"><!--if text ends with whitespace ..-->
253          <xsl:variable name="nexttag"><xsl:copy-of select="name(following-sibling::*[1])"/></xsl:variable>
254          <xsl:if test="$nexttag='LINK'"><!--.. and following-sibling is a LINK -> keep one space-->
255            <xsl:text> </xsl:text>
256          </xsl:if>
257        </xsl:if>
258      </xsl:otherwise>
259    </xsl:choose>
260  </xsl:template>
261
262  <xsl:template match="LINK" mode="reflow">
263    <xsl:apply-templates select="." mode="link-recursion"/>
264  </xsl:template>
265  <xsl:template match="*" mode="reflow">
266    <xsl:call-template name="error"><xsl:with-param name="text">Illegal TAG <xsl:value-of select="name()"/> in mode &acute;reflow&acute;</xsl:with-param></xsl:call-template>
267  </xsl:template>
268
269  <!-- ========================= -->
270  <!--     preformatted mode     -->
271  <!-- ========================= -->
272
273<!--  <xsl:template match="text()" mode="preformatted-old"><PRE><FONT color="navy"><xsl:value-of select="substring-after(.,$lb)"/></FONT></PRE></xsl:template>-->
274
275  <xsl:template match="text()" mode="preformatted">
276    <xsl:variable name="before_lf"><xsl:value-of select="substring-before(.,$lb)"/></xsl:variable>
277
278    <xsl:choose>
279      <xsl:when test="normalize-space($before_lf)=''">
280        <xsl:variable name="after_lf"><xsl:value-of select="substring-after(.,$lb)"/></xsl:variable>
281        <xsl:choose>
282          <xsl:when test="normalize-space($after_lf)=''"><xsl:value-of select="."/></xsl:when>
283          <xsl:otherwise><xsl:value-of select="$after_lf"/></xsl:otherwise>
284        </xsl:choose>
285      </xsl:when>
286      <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
287    </xsl:choose>
288  </xsl:template>
289  <xsl:template match="LINK" mode="preformatted">
290    <xsl:apply-templates select="." mode="link-recursion"/>
291  </xsl:template>
292  <xsl:template match="*" mode="preformatted">
293    <xsl:call-template name="error"><xsl:with-param name="text">Illegal TAG <xsl:value-of select="name()"/> in mode &acute;preformatted&acute;</xsl:with-param></xsl:call-template>
294  </xsl:template>
295
296
297  <xsl:template match="LINK" mode="link-recursion">
298    <xsl:variable name="quoted">
299      <xsl:choose>
300        <xsl:when test="@quoted='0'">0</xsl:when>
301        <xsl:otherwise>1</xsl:otherwise>
302      </xsl:choose>
303    </xsl:variable>
304    <xsl:choose>
305      <xsl:when test="@type='hlp' or @type='ps' or @type='pdf'">
306        <xsl:call-template name="link-to-document">
307          <xsl:with-param name="doc" select="@dest"/>
308          <xsl:with-param name="type" select="@type"/>
309          <xsl:with-param name="missing" select="@missing"/>
310          <xsl:with-param name="quote" select="$quoted"/>
311        </xsl:call-template>
312      </xsl:when>
313      <xsl:when test="@type='www'">
314        <xsl:call-template name="insert-link">
315          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
316          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
317        </xsl:call-template>
318      </xsl:when>
319      <xsl:when test="@type='email'">
320        <xsl:call-template name="insert-email-link">
321          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
322          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
323          <xsl:with-param name="subject" select="concat('Concerning helppage ',$myname)"/>
324        </xsl:call-template>
325      </xsl:when>
326      <xsl:otherwise>
327        <xsl:call-template name="error"><xsl:with-param name="text">Unknown type '<xsl:value-of select="@type"/>'</xsl:with-param></xsl:call-template>
328      </xsl:otherwise>
329    </xsl:choose>
330  </xsl:template>
331
332  <xsl:template match="T" mode="condensed">
333    <xsl:choose>
334      <xsl:when test="@reflow='1'">
335          <xsl:apply-templates mode="reflow"/>
336      </xsl:when>
337      <xsl:otherwise>
338        <PRE><FONT color="navy" size="-1"><xsl:apply-templates mode="preformatted"/></FONT></PRE>
339      </xsl:otherwise>
340    </xsl:choose>
341  </xsl:template>
342
343  <xsl:template match="*" mode="condensed">
344    <xsl:apply-templates select="."/>
345  </xsl:template>
346
347  <xsl:template match="T">
348    <xsl:choose>
349      <xsl:when test="@reflow='1'">
350        <H3><xsl:apply-templates mode="reflow"/></H3>
351      </xsl:when>
352      <xsl:otherwise>
353        <PRE><FONT color="navy" size="-1"><xsl:apply-templates mode="preformatted"/></FONT></PRE>
354      </xsl:otherwise>
355    </xsl:choose>
356  </xsl:template>
357
358
359  <xsl:template match="ENTRY">
360    <LI>
361      <xsl:apply-templates mode="condensed"/>
362    </LI>
363  </xsl:template>
364
365  <xsl:template match="P">
366    <DIV><xsl:apply-templates mode="condensed"/></DIV>
367  </xsl:template>
368
369  <xsl:template match="ENUM">
370    <xsl:variable name="enumval"><xsl:value-of select="ENTRY[1]/@enumerated"/></xsl:variable>
371    <xsl:variable name="type">
372      <xsl:choose>
373        <xsl:when test="$enumval='a'">a</xsl:when>
374        <xsl:when test="$enumval='A'">A</xsl:when>
375        <xsl:otherwise>1</xsl:otherwise><!--fallback to 1. 2. 3. ..-->
376      </xsl:choose>
377    </xsl:variable>
378
379    <xsl:choose>
380      <xsl:when test="$type='1'">
381        <OL>
382          <xsl:apply-templates/>
383        </OL>
384      </xsl:when>
385      <xsl:otherwise>
386        <OL type="{$type}">
387          <xsl:apply-templates/>
388        </OL>
389      </xsl:otherwise>
390    </xsl:choose>
391
392    <BR/>
393  </xsl:template>
394  <xsl:template match="LIST">
395    <UL>
396      <xsl:apply-templates/>
397    </UL>
398    <BR/>
399  </xsl:template>
400
401  <xsl:template match="P" mode="top-level"><DIV><xsl:apply-templates/></DIV></xsl:template>
402  <xsl:template match="T|ENUM|LIST" mode="top-level"><xsl:apply-templates select="."/></xsl:template>
403
404  <xsl:template match="SECTION" mode="main">
405    <A name="{translate(@name,' ','_')}"></A>
406    <H2><xsl:value-of select="@name"/></H2>
407    <TABLE width="100%" border="{$tableBorder}">
408      <TR>
409        <TD align="right">
410          <TABLE width="97%" border="{$tableBorder}">
411            <TR>
412              <TD>
413                <xsl:apply-templates mode="top-level"/>
414              </TD>
415            </TR>
416            <TR><TD>&nbsp;</TD></TR>
417          </TABLE>
418        </TD>
419      </TR>
420    </TABLE>
421  </xsl:template>
422
423  <xsl:template match="SECTION" mode="content">
424    <LI><A href="#{translate(@name,' ','_')}"><xsl:value-of select="@name"/></A></LI>
425  </xsl:template>
426
427  <!-- ================================ -->
428  <!--     PAGE document wide layout    -->
429  <!-- ================================ -->
430
431  <xsl:template match="PAGE">
432    <HTML>
433      <xsl:variable name="title">
434        <xsl:for-each select="TITLE">
435          <xsl:value-of select="text()"/>
436        </xsl:for-each>
437      </xsl:variable>
438      <xsl:call-template name="header">
439        <xsl:with-param name="title" select="$title"/>
440      </xsl:call-template>
441      <BODY LEFTMARGIN="10" TEXT="{$fontColor}" BGCOLOR="{$backgroundColor}" LINK="{$linkColor}" VLINK="{$visitedLinkColor}" ALINK="{$activeLinkColor}">
442        <TABLE width="95%">
443          <TR>
444            <TD align="left" valign="top">
445              <!-- Search Google -->
446              <FORM method="GET" action="http://www.google.com/search" name="google">
447                <A HREF="http://www.google.com">
448                  <IMG SRC="Logo_25wht.gif" width="75" height="32" border="0" ALT="Google" align="absmiddle"/>
449                </A>
450                <INPUT TYPE="hidden" name="q"/>
451                <INPUT TYPE="hidden" name="hl" value="en"/>
452                <INPUT TYPE="hidden" name="as_sitesearch" value="help.arb-home.de"/>
453                <INPUT TYPE="text" name="q2" size="31" maxlength="255"/>
454                <INPUT type="submit" name="btnG" VALUE="Search help" onClick="google.q.value=google.q2.value;return true;"/>
455                <INPUT type="submit" name="btnG" VALUE="Search site" onClick="google.as_sitesearch.value='arb-home.de';google.q.value=google.q2.value;return true;"/>
456              </FORM>
457              <!-- Search Google -->
458            </TD>
459            <TD valign="top" align="right">
460              <FONT size="-1">
461                <NOBR>More docs on the
462                <xsl:call-template name="insert-link">
463                  <xsl:with-param name="linktext" select="'ARB website'"/>
464                  <xsl:with-param name="address" select="'http://rtfm.arb-home.de/'"/>
465                </xsl:call-template>.</NOBR><BR/>
466                See also <A href="{concat($rootpath,'help_index')}.html">index</A> of helppages.<BR/>
467                Last update on <xsl:value-of select="$date"/>.
468              </FONT>
469            </TD>
470          </TR>
471        </TABLE>
472        <TABLE border="{$tableBorder}" width="98%" align="center">
473          <TR bgcolor="{$linkSectionsColor}">
474            <xsl:text>
475            </xsl:text>
476            <TD valign="top" width="50%">Main topics:<BR/>
477              <UL>
478                <xsl:apply-templates select="UP" mode="uplinks"/>
479              </UL>
480            </TD>
481            <xsl:text>
482            </xsl:text>
483            <TD valign="top">Related topics:<BR/>
484              <UL>
485                <xsl:apply-templates select="SUB" mode="sublinks"/>
486              </UL>
487            </TD>
488            <xsl:text>
489            </xsl:text>
490          </TR>
491          <TR>
492            <TD colspan="2">
493              <H1><xsl:value-of select="$title"/></H1>
494              <UL><xsl:apply-templates select="SECTION" mode="content"/></UL>
495              <xsl:apply-templates select="SECTION" mode="main"/>
496            </TD>
497          </TR>
498        </TABLE>
499      </BODY>
500    </HTML>
501  </xsl:template>
502
503  <!-- ============ -->
504  <!--     text()   (should be last template)  -->
505  <!-- ============ -->
506
507  <xsl:template match="text()|*">
508   <xsl:choose>
509     <!-- tags-->
510     <xsl:when test="string-length(name())>0">
511       <xsl:call-template name="error"><xsl:with-param name="text">Unhandled TAG <xsl:value-of select="name()"/></xsl:with-param></xsl:call-template>
512     </xsl:when>
513     <!-- text() -->
514     <xsl:otherwise>
515       <xsl:variable name="self"><xsl:value-of select="."/></xsl:variable>
516       <xsl:choose>
517         <!--allow empty text-->
518         <xsl:when test="normalize-space($self)=''"></xsl:when>
519         <xsl:otherwise>
520           <!--           {<xsl:value-of select="."/>}-->
521           <xsl:call-template name="error"><xsl:with-param name="text">Unexpected text</xsl:with-param></xsl:call-template>
522         </xsl:otherwise>
523       </xsl:choose>
524     </xsl:otherwise>
525   </xsl:choose>
526  </xsl:template>
527
528
529</xsl:transform>
530
Note: See TracBrowser for help on using the repository browser.