source: tags/arb_5.3/HELP_SOURCE/to_help.xsl

Last change on this file was 5775, checked in by westram, 15 years ago
  • made help generator bit more robust
    • local link types are no longer detected by extension (*.ps, *pdf) in stylesheets. it is now done once in arb_help2xml.
    • '.hlp' extension is no longer suppressed (in xml)
    • all local link types may have missing attribute
    • arb_help2xml checks for existance of .pdf and .ps now
    • warn about all dead links during compilation (and abort on invalid links)
    • fixed most broken links in helpfiles
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.8 KB
Line 
1<?xml version="1.0"?>
2
3<!--          <!ENTITY acute "&#180;">-->
4
5<!DOCTYPE xsl:stylesheet [
6          <!ENTITY nbsp "&#160;">
7          <!ENTITY acute "&#39;">
8          <!ENTITY dotwidth "20">
9          <!ENTITY dotheight "16">
10          <!ENTITY tab "&#x9;">
11          <!ENTITY br "&#xa;">
12          ]>
13
14
15<!-- used to create ARB help in internal format -->
16
17
18<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
19               version="1.0"
20               >
21
22<!--  <xsl:output method="text" encoding='iso-8859-15'/>-->
23  <xsl:output method="text"/>
24
25  <xsl:param name="myname"/>
26  <xsl:param name="xml_location"/>
27
28  <!-- includes -->
29
30  <xsl:include href="date.xsl"/>
31
32  <xsl:variable name="rootpath">
33    <xsl:choose>
34      <xsl:when test="string-length(substring-before($myname,'/'))&gt;0">../</xsl:when>
35      <xsl:otherwise></xsl:otherwise>
36    </xsl:choose>
37  </xsl:variable>
38
39  <xsl:variable name="author">ARB development</xsl:variable>
40  <xsl:variable name="maildomain">arb-home.de</xsl:variable>
41
42  <xsl:variable name="width" select="75"/> <!--columns in text output (applies only to reflown text)-->
43
44  <xsl:variable name="lb"><xsl:text>&br;</xsl:text></xsl:variable> <!--used to detect line-breaks in XML-->
45
46  <!-- =============== -->
47  <!--     warning     -->
48  <!-- =============== -->
49
50  <xsl:template name="error">
51    <xsl:param name="text" select="'Unknown error'"/>
52    <xsl:message terminate="yes"><xsl:value-of select="$text"/></xsl:message>
53  </xsl:template>
54
55  <!-- ============ -->
56  <!--    LINKs     -->
57  <!-- ============ -->
58
59  <!--insert-link-->
60  <xsl:template name="insert-link">
61    <xsl:param name="address"/>
62    <xsl:param name="linktext"/>
63
64    <xsl:copy-of select="$address"/>
65<!--    [see: <xsl:value-of select="$address"/><xsl:text>]</xsl:text>-->
66  </xsl:template>
67
68  <!--insert-email-link-->
69  <xsl:template name="insert-email-link">
70    <xsl:param  name="linktext"/>
71    <xsl:param  name="address" select="arb"/>
72    <xsl:param  name="subject"/>
73
74
75    <xsl:variable name="add">
76      <xsl:choose>
77        <xsl:when test="string-length(substring-before($address,'@'))>0"><xsl:value-of select="$address"/></xsl:when>
78        <xsl:otherwise><xsl:value-of select="$address"/>@<xsl:value-of select="$maildomain"/></xsl:otherwise>
79      </xsl:choose>
80    </xsl:variable>
81
82    <xsl:value-of select="$linktext"/> [mailto: <xsl:value-of select="$add"/>
83    <xsl:text>  subject: &acute;</xsl:text>
84    <xsl:value-of select="$subject"/>
85    <xsl:text>&acute;]</xsl:text>
86
87  </xsl:template>
88
89  <!-- ======================== -->
90  <!--     link-to-document     -->
91  <!-- ======================== -->
92  <xsl:template name="link-to-document">
93    <xsl:param name="doc"/>
94    <xsl:param name="missing"/>
95    <xsl:param name="type"/>
96
97    <xsl:choose>
98      <xsl:when test="$type='ps'">
99        <xsl:text>Postscript: </xsl:text>
100        <xsl:value-of select="$doc"/>
101      </xsl:when>
102      <xsl:when test="$type='pdf'">
103        <xsl:text>PDF: </xsl:text>
104        <xsl:value-of select="$doc"/>
105      </xsl:when>
106      <xsl:when test="$type='hlp'">
107        <xsl:variable name="docbase">
108          <xsl:value-of select="substring-before($doc,'.hlp')"/>
109        </xsl:variable>
110        <xsl:choose>
111          <xsl:when test="$missing='1'">
112            <xsl:value-of select="concat('Missing Link to ',$docbase,'.hlp')"/>
113          </xsl:when>
114          <xsl:otherwise>
115            <xsl:for-each select="document(concat($xml_location,'/',$docbase,'.xml'))">
116              <xsl:for-each select="PAGE/TITLE">TOPIC &acute;<xsl:copy-of select="normalize-space(text())"/>&acute;</xsl:for-each>
117            </xsl:for-each>
118          </xsl:otherwise>
119        </xsl:choose>
120      </xsl:when>
121      <xsl:otherwise>
122        <xsl:message terminate="yes">Illegal document type '<xsl:value-of select="$type"/>' in link-to-document</xsl:message>
123      </xsl:otherwise>
124    </xsl:choose>
125  </xsl:template>
126
127  <!-- =============== -->
128  <!--     uplinks     -->
129  <!-- =============== -->
130
131  <xsl:template name="help-link">
132    <xsl:param name="dest"/>
133
134    <xsl:value-of select="$dest"/>
135    <xsl:text>&br;</xsl:text>
136  </xsl:template>
137
138  <xsl:template match="UP" mode="uplinks">
139    <xsl:text>UP                  </xsl:text>
140    <xsl:call-template name="help-link">
141      <xsl:with-param name="dest" select="@dest"/>
142    </xsl:call-template>
143  </xsl:template>
144  <xsl:template match="*|text()" mode="uplinks"></xsl:template>
145
146  <!-- ================ -->
147  <!--     sublinks     -->
148  <!-- ================ -->
149
150  <xsl:template match="SUB" mode="sublinks">
151    <xsl:text>SUB                 </xsl:text>
152    <xsl:call-template name="help-link">
153      <xsl:with-param name="dest" select="@dest"/>
154    </xsl:call-template>
155  </xsl:template>
156  <xsl:template match="*|text()" mode="sublinks"></xsl:template>
157
158  <xsl:template match="ENTRY|P" mode="calc-indent">
159    <xsl:text>    </xsl:text><!--this defines the indentation per level-->
160    <xsl:apply-templates mode="calc-indent" select=".."/>
161  </xsl:template>
162  <xsl:template match="T|ENUM|LIST" mode="calc-indent">
163    <xsl:apply-templates mode="calc-indent" select=".."/>
164  </xsl:template>
165  <xsl:template match="SECTION" mode="calc-indent"></xsl:template>
166
167  <xsl:template name="find-last-space">
168    <xsl:param name="text"/>
169    <xsl:param name="len" select="string-length($text)"/>
170
171    <xsl:variable name="beforelen" select="string-length(substring-before($text,' '))"/>
172    <xsl:variable name="after" select="substring-after($text,' ')"/>
173    <xsl:variable name="afterlen" select="string-length($after)"/>
174
175    <xsl:choose>
176      <xsl:when test="number($afterlen)&gt;0">
177        <!--sth behind space-->
178        <xsl:variable name="next-space">
179          <xsl:call-template name="find-last-space">
180            <xsl:with-param name="text" select="$after"/>
181            <xsl:with-param name="len" select="$afterlen"/>
182          </xsl:call-template>
183        </xsl:variable>
184        <xsl:value-of select="number($beforelen)+1+number($next-space)"/>
185      </xsl:when>
186      <xsl:otherwise> <!--$afterlen=0-->
187        <xsl:choose>
188          <xsl:when test="number($beforelen)=0">
189            <!--no spaces found-->
190            <xsl:value-of select="'0'"/>
191          </xsl:when>
192          <xsl:otherwise>
193            <!--space at last position-->
194            <xsl:value-of select="number($beforelen)+1"/>
195          </xsl:otherwise>
196        </xsl:choose>
197      </xsl:otherwise>
198    </xsl:choose>
199  </xsl:template>
200
201  <xsl:template name="indent-preformatted">
202    <xsl:param name="indent" select="''"/>
203    <xsl:param name="text"/>
204    <xsl:param name="first" select="''"/>
205
206    <xsl:variable name="line1" select="substring-before($text,$lb)"/>
207    <xsl:variable name="line2" select="substring-after($text,$lb)"/>
208
209    <xsl:choose>
210      <xsl:when test="concat($line1,$line2)=''">
211        <xsl:value-of select="concat($indent,$text)"/>
212        <xsl:text>&br;</xsl:text>
213      </xsl:when>
214      <xsl:otherwise>
215        <xsl:if test="string-length($line1)&gt;0">
216<!--          <xsl:text>{</xsl:text>-->
217          <xsl:value-of select="concat($indent,$line1)"/>
218          <xsl:text>&br;</xsl:text>
219<!--          <xsl:text>}</xsl:text>-->
220        </xsl:if>
221
222        <xsl:if test="string-length($line2)&gt;0">
223          <xsl:call-template name="indent-preformatted">
224            <xsl:with-param name="indent" select="$indent"/>
225            <xsl:with-param name="text" select="$line2"/>
226          </xsl:call-template>
227        </xsl:if>
228      </xsl:otherwise>
229    </xsl:choose>
230
231  </xsl:template>
232
233  <xsl:template name="reflow-paragraph">
234    <xsl:param name="indent" select="''"/>
235    <xsl:param name="text"/>
236    <xsl:param name="prefix" select="''"/>
237
238<!--    <xsl:text>{</xsl:text><xsl:copy-of select="$text"/><xsl:text>}</xsl:text>-->
239
240    <xsl:variable name="printlen"><xsl:value-of select="$width - string-length($indent)"/></xsl:variable>
241    <xsl:variable name="textlen"><xsl:value-of select="string-length($text)"/></xsl:variable>
242
243    <xsl:variable name="this-indent">
244      <xsl:choose>
245        <xsl:when test="$prefix=''">
246          <xsl:value-of select="$indent"/>
247        </xsl:when>
248        <xsl:otherwise>
249          <xsl:value-of select="substring($indent,1,string-length($indent) - string-length($prefix))"/>
250          <xsl:value-of select="$prefix"/>
251        </xsl:otherwise>
252      </xsl:choose>
253    </xsl:variable>
254
255    <xsl:choose>
256      <xsl:when test="number($printlen) &gt;= number($textlen)">
257        <xsl:value-of select="concat($this-indent,$text)"/>
258        <xsl:text>&br;</xsl:text>
259      </xsl:when>
260      <xsl:otherwise>
261        <xsl:variable name="last-space">
262          <xsl:call-template name="find-last-space">
263            <xsl:with-param name="text" select="substring($text,1,$printlen+1)"/>
264            <xsl:with-param name="len" select="$printlen+1"/>
265          </xsl:call-template>
266        </xsl:variable>
267
268        <xsl:variable name="print">
269          <xsl:choose>
270            <xsl:when test="$last-space='0'"><xsl:value-of select="substring($text,1,$printlen)"/></xsl:when>
271            <xsl:otherwise><xsl:value-of select="substring($text,1,$last-space)"/></xsl:otherwise>
272          </xsl:choose>
273        </xsl:variable>
274        <xsl:variable name="rest">
275          <xsl:choose>
276            <xsl:when test="$last-space='0'"><xsl:value-of select="substring($text,$printlen+1)"/></xsl:when>
277            <xsl:otherwise><xsl:value-of select="substring($text,$last-space+1)"/></xsl:otherwise>
278          </xsl:choose>
279        </xsl:variable>
280
281        <xsl:variable name="restlen"><xsl:value-of select="string-length($rest)"/></xsl:variable>
282
283        <xsl:value-of select="concat($this-indent,$print)"/>
284        <xsl:text>&br;</xsl:text>
285
286        <xsl:if test="number($restlen)">
287          <xsl:call-template name="reflow-paragraph">
288            <xsl:with-param name="indent" select="$indent"/>
289            <xsl:with-param name="text" select="$rest"/>
290          </xsl:call-template>
291        </xsl:if>
292      </xsl:otherwise>
293    </xsl:choose>
294  </xsl:template>
295
296  <xsl:template match="ENTRY" mode="calc-prefix">
297    <xsl:choose>
298      <xsl:when test="name(..)='ENUM'">
299        <xsl:value-of select="position()"/>
300        <xsl:text>. </xsl:text>
301      </xsl:when>
302      <xsl:when test="name(..)='LIST'"><xsl:text>- </xsl:text></xsl:when>
303      <xsl:otherwise></xsl:otherwise>
304    </xsl:choose>
305  </xsl:template>
306
307  <xsl:template match="*|text()" mode="calc-prefix">
308  </xsl:template>
309
310  <xsl:template match="text()" mode="reflow">
311    <xsl:call-template name="error"><xsl:with-param name="text">Illegal text in reflow-mode</xsl:with-param></xsl:call-template>
312  </xsl:template>
313
314  <xsl:template match="text()" mode="preformatted">
315    <xsl:call-template name="error"><xsl:with-param name="text">Illegal text in preformatted-mode</xsl:with-param></xsl:call-template>
316  </xsl:template>
317
318  <xsl:template match="LINK" mode="expand-links">
319    <xsl:choose>
320      <xsl:when test="@type='hlp' or @type='ps' or @type='pdf'">
321        <xsl:call-template name="link-to-document">
322          <xsl:with-param name="doc" select="@dest"/>
323          <xsl:with-param name="missing" select="@missing"/>
324          <xsl:with-param name="type" select="@type"/>
325        </xsl:call-template>
326      </xsl:when>
327      <xsl:when test="@type='www'">
328        <xsl:call-template name="insert-link">
329          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
330          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
331        </xsl:call-template>
332      </xsl:when>
333      <xsl:when test="@type='email'">
334        <xsl:call-template name="insert-email-link">
335          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
336          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
337          <xsl:with-param name="subject" select="concat('Concerning helppage ',$myname)"/>
338        </xsl:call-template>
339      </xsl:when>
340      <xsl:otherwise>
341        <xsl:call-template name="error"><xsl:with-param name="text">Unknown type '<xsl:value-of select="@type"/>'</xsl:with-param></xsl:call-template>
342      </xsl:otherwise>
343    </xsl:choose>
344  </xsl:template>
345
346  <xsl:template match="text()" mode="expand-links">
347    <xsl:value-of select="."/>
348  </xsl:template>
349
350  <xsl:template match="*" mode="expand-links">
351    <xsl:call-template name="error"><xsl:with-param name="text">Illegal content for expand-links</xsl:with-param></xsl:call-template>
352  </xsl:template>
353
354  <xsl:template match="T">
355    <xsl:variable name="indent"><xsl:apply-templates mode="calc-indent" select=".."/></xsl:variable>
356    <xsl:variable name="prefix"><xsl:apply-templates mode="calc-prefix" select="../.."/></xsl:variable>
357    <xsl:variable name="text"><xsl:apply-templates mode="expand-links"/></xsl:variable>
358
359    <xsl:choose>
360      <xsl:when test="@reflow='1'">
361        <xsl:call-template name="reflow-paragraph">
362          <xsl:with-param name="indent" select="$indent"/>
363          <xsl:with-param name="text" select="normalize-space($text)"/>
364          <xsl:with-param name="prefix" select="$prefix"/>
365        </xsl:call-template>
366        <xsl:text>&br;</xsl:text>
367      </xsl:when>
368      <xsl:otherwise>
369        <xsl:call-template name="indent-preformatted">
370          <xsl:with-param name="indent" select="$indent"/>
371          <xsl:with-param name="text" select="$text"/>
372          <xsl:with-param name="prefix" select="$prefix"/>
373        </xsl:call-template>
374        <xsl:text>&br;</xsl:text>
375      </xsl:otherwise>
376    </xsl:choose>
377  </xsl:template>
378
379  <xsl:template match="T" mode="disabled">
380    <xsl:choose>
381      <xsl:when test="@reflow='1'"><xsl:apply-templates mode="reflow"/></xsl:when>
382      <xsl:otherwise><xsl:apply-templates mode="preformatted"/></xsl:otherwise>
383    </xsl:choose>
384    <xsl:text>&br;</xsl:text>
385  </xsl:template>
386
387  <xsl:template match="ENTRY"><xsl:apply-templates/></xsl:template>
388
389  <xsl:template match="P"><xsl:apply-templates/></xsl:template>
390
391  <xsl:template match="ENUM"><xsl:apply-templates/></xsl:template>
392  <xsl:template match="LIST"><xsl:apply-templates/></xsl:template>
393
394  <xsl:template match="SECTION" mode="main">
395    <xsl:text>&br;&br;</xsl:text>
396    <xsl:value-of select="@name"/>
397    <xsl:text>&br;&br;</xsl:text>
398    <xsl:apply-templates/>
399  </xsl:template>
400
401  <!-- ================================ -->
402  <!--     PAGE document wide layout    -->
403  <!-- ================================ -->
404
405  <!-- ============================== -->
406  <!--     insert document header     -->
407  <!-- ============================== -->
408  <xsl:template name="header">
409    <xsl:param name="title" select="'Untitled'"/>
410    <xsl:param name="for"/>
411    <xsl:text xml:space="preserve"># Generated from XML with Sablotron -- Stylesheet by Ralf Westram (ralf@arb-home.de)</xsl:text>
412    <xsl:choose>
413      <xsl:when test="$for='release'">
414        <xsl:text xml:space="preserve">
415#
416#  ****  You may edit this file, but the next ARB update will overwrite your changes  ****
417</xsl:text>
418      </xsl:when>
419      <xsl:when test="$for='devel'">
420        <xsl:text xml:space="preserve">
421#
422#  ****  DO NOT EDIT (edit in $(ARBHOME)/HELP_SOURCE/oldhelp instead)  ****
423</xsl:text>
424      </xsl:when>
425      <xsl:otherwise>
426        <xsl:call-template name="error"><xsl:with-param name="text">Illegal content in edit_warning</xsl:with-param></xsl:call-template>
427      </xsl:otherwise>
428    </xsl:choose>
429  </xsl:template>
430
431  <xsl:template match="PAGE">
432      <xsl:variable name="title">
433        <xsl:for-each select="TITLE">
434          <xsl:value-of select="text()"/>
435        </xsl:for-each>
436      </xsl:variable>
437      <xsl:call-template name="header">
438        <xsl:with-param name="title" select="$title"/>
439        <xsl:with-param name="for" select="@edit_warning"/>
440      </xsl:call-template>#
441# This page was converted by arb_help2xml and may look strange.
442# If you think it's really bad, please send a
443# <xsl:call-template name="insert-email-link">
444        <xsl:with-param name="linktext">mail</xsl:with-param>
445        <xsl:with-param name="address">helpfeedback</xsl:with-param>
446        <xsl:with-param name="subject" select="concat('Helppage ',$myname,' looks weird')"/>
447      </xsl:call-template>
448# to our help keeper.
449
450# UP references:
451<xsl:apply-templates mode="uplinks"/>
452# SUB references:
453<xsl:apply-templates mode="sublinks"/>
454# ------------------------------------------------------------
455# Start of real helpfile:
456TITLE&tab;<xsl:value-of select="normalize-space($title)"/>
457
458<xsl:apply-templates select="SECTION" mode="main"/>
459  </xsl:template>
460
461  <!-- ============ -->
462  <!--     text()   (should be last template)  -->
463  <!-- ============ -->
464  <xsl:template match="text()|*">
465   <xsl:choose>
466     <xsl:when test="string-length(name())>0">
467       <xsl:call-template name="error"><xsl:with-param name="text">Unknown TAG <xsl:value-of select="name()"/></xsl:with-param></xsl:call-template>
468      </xsl:when>
469      <xsl:otherwise>
470<!--        <xsl:value-of select="."/>-->
471<!--        <xsl:call-template name="error"><xsl:with-param name="text">Unexpected text</xsl:with-param></xsl:call-template>-->
472      </xsl:otherwise>
473    </xsl:choose>
474  </xsl:template>
475
476
477</xsl:transform>
478
Note: See TracBrowser for help on using the repository browser.