source: branches/stable/HELP_SOURCE/to_help.xsl

Last change on this file was 13625, checked in by westram, 9 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.4 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">&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="prefix" select="''"/>
205
206    <xsl:variable name="indent-length"><xsl:value-of select="string-length($indent) + string-length($prefix)"/></xsl:variable>
207    <xsl:variable name="printlen"><xsl:value-of select="$width - $indent-length"/></xsl:variable>
208    <xsl:variable name="textlen"><xsl:value-of select="string-length($text)"/></xsl:variable>
209
210    <xsl:variable name="line1" select="substring-before($text,$lb)"/>
211    <xsl:variable name="line2" select="substring-after($text,$lb)"/>
212
213    <xsl:choose>
214      <xsl:when test="concat($line1,$line2)=''">
215        <xsl:value-of select="concat($indent,$prefix,$text)"/>
216        <xsl:text>&br;</xsl:text>
217      </xsl:when>
218      <xsl:when test="string-length($line1)=0">
219        <xsl:call-template name="indent-preformatted">
220          <xsl:with-param name="indent" select="$indent"/>
221          <xsl:with-param name="text" select="$line2"/>
222          <xsl:with-param name="prefix" select="$prefix"/>
223        </xsl:call-template>
224      </xsl:when>
225      <xsl:otherwise>
226        <xsl:value-of select="concat($indent,$prefix,$line1)"/>
227        <xsl:text>&br;</xsl:text>
228
229        <xsl:if test="string-length($line2)&gt;0">
230          <xsl:variable name="next-indent">
231            <xsl:choose>
232              <xsl:when test="$prefix=''">
233                <xsl:value-of select="$indent"/>
234              </xsl:when>
235              <xsl:otherwise>
236                <xsl:variable name="enough-spaces">
237                  <xsl:value-of select="$indent"/>
238                  <xsl:text>                    </xsl:text>
239                </xsl:variable>
240                <xsl:value-of select="substring($enough-spaces, 1, $indent-length)"/>
241              </xsl:otherwise>
242            </xsl:choose>
243          </xsl:variable>
244
245          <xsl:call-template name="indent-preformatted">
246            <xsl:with-param name="indent" select="$next-indent"/>
247            <xsl:with-param name="text" select="$line2"/>
248          </xsl:call-template>
249        </xsl:if>
250      </xsl:otherwise>
251    </xsl:choose>
252  </xsl:template>
253
254  <xsl:template name="reflow-paragraph">
255    <xsl:param name="indent" select="''"/>
256    <xsl:param name="text"/>
257    <xsl:param name="prefix" select="''"/>
258
259    <xsl:variable name="indent-length"><xsl:value-of select="string-length($indent) + string-length($prefix)"/></xsl:variable>
260    <xsl:variable name="printlen"><xsl:value-of select="$width - $indent-length"/></xsl:variable>
261    <xsl:variable name="textlen"><xsl:value-of select="string-length($text)"/></xsl:variable>
262
263    <xsl:variable name="this-indent">
264      <xsl:choose>
265        <xsl:when test="$prefix=''">
266          <xsl:value-of select="$indent"/>
267        </xsl:when>
268        <xsl:otherwise>
269          <xsl:value-of select="$indent"/>
270          <xsl:value-of select="$prefix"/>
271        </xsl:otherwise>
272      </xsl:choose>
273    </xsl:variable>
274
275    <xsl:choose>
276      <xsl:when test="number($printlen) &gt;= number($textlen)">
277        <xsl:value-of select="concat($this-indent,$text)"/>
278        <xsl:text>&br;</xsl:text>
279      </xsl:when>
280      <xsl:otherwise>
281        <xsl:variable name="last-space">
282          <xsl:call-template name="find-last-space">
283            <xsl:with-param name="text" select="substring($text,1,$printlen+1)"/>
284            <xsl:with-param name="len" select="$printlen+1"/>
285          </xsl:call-template>
286        </xsl:variable>
287
288        <xsl:variable name="print">
289          <xsl:choose>
290            <xsl:when test="$last-space='0'"><xsl:value-of select="substring($text,1,$printlen)"/></xsl:when>
291            <xsl:otherwise><xsl:value-of select="substring($text,1,$last-space - 1)"/></xsl:otherwise>
292          </xsl:choose>
293        </xsl:variable>
294        <xsl:variable name="rest">
295          <xsl:choose>
296            <xsl:when test="$last-space='0'"><xsl:value-of select="substring($text,$printlen+1)"/></xsl:when>
297            <xsl:otherwise><xsl:value-of select="substring($text,$last-space+1)"/></xsl:otherwise>
298          </xsl:choose>
299        </xsl:variable>
300
301        <xsl:variable name="restlen"><xsl:value-of select="string-length($rest)"/></xsl:variable>
302
303        <xsl:value-of select="concat($this-indent,$print)"/>
304        <xsl:text>&br;</xsl:text>
305
306        <xsl:if test="number($restlen)">
307
308          <xsl:variable name="next-indent">
309            <xsl:choose>
310              <xsl:when test="$prefix=''">
311                <xsl:value-of select="$indent"/>
312              </xsl:when>
313              <xsl:otherwise>
314                <xsl:variable name="enough-spaces">
315                  <xsl:value-of select="$indent"/>
316                  <xsl:text>                    </xsl:text>
317                </xsl:variable>
318                <xsl:value-of select="substring($enough-spaces, 1, $indent-length)"/>
319              </xsl:otherwise>
320            </xsl:choose>
321          </xsl:variable>
322
323          <xsl:call-template name="reflow-paragraph">
324            <xsl:with-param name="indent" select="$next-indent"/>
325            <xsl:with-param name="text" select="$rest"/>
326          </xsl:call-template>
327        </xsl:if>
328      </xsl:otherwise>
329    </xsl:choose>
330  </xsl:template>
331
332  <xsl:template match="ENTRY" mode="calc-prefix">
333    <xsl:choose>
334      <xsl:when test="name(..)='ENUM'">
335        <xsl:value-of select="@enumerated"/>
336        <xsl:text>. </xsl:text>
337      </xsl:when>
338      <xsl:when test="name(..)='LIST'"><xsl:text>* </xsl:text></xsl:when>
339      <xsl:otherwise></xsl:otherwise>
340    </xsl:choose>
341  </xsl:template>
342
343  <xsl:template match="ENUM|LIST" mode="calc-prefix">
344    <xsl:call-template name="error"><xsl:with-param name="text">Illegal ENUM or LIST in calc-prefix-mode</xsl:with-param></xsl:call-template>
345  </xsl:template>
346  <xsl:template match="*|text()" mode="calc-prefix">
347  </xsl:template>
348
349  <xsl:template match="text()" mode="reflow">
350    <xsl:call-template name="error"><xsl:with-param name="text">Illegal text in reflow-mode</xsl:with-param></xsl:call-template>
351  </xsl:template>
352
353  <xsl:template match="text()" mode="preformatted">
354    <xsl:call-template name="error"><xsl:with-param name="text">Illegal text in preformatted-mode</xsl:with-param></xsl:call-template>
355  </xsl:template>
356
357  <xsl:template match="LINK" mode="expand-links">
358    <xsl:choose>
359      <xsl:when test="@type='hlp' or @type='ps' or @type='pdf'">
360        <xsl:call-template name="link-to-document">
361          <xsl:with-param name="doc" select="@dest"/>
362          <xsl:with-param name="missing" select="@missing"/>
363          <xsl:with-param name="type" select="@type"/>
364        </xsl:call-template>
365      </xsl:when>
366      <xsl:when test="@type='www'">
367        <xsl:call-template name="insert-link">
368          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
369          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
370        </xsl:call-template>
371      </xsl:when>
372      <xsl:when test="@type='email'">
373        <xsl:call-template name="insert-email-link">
374          <xsl:with-param name="linktext"><xsl:value-of select="@dest"/></xsl:with-param>
375          <xsl:with-param name="address"><xsl:value-of select="@dest"/></xsl:with-param>
376          <xsl:with-param name="subject" select="concat('Concerning helppage ',$myname)"/>
377        </xsl:call-template>
378      </xsl:when>
379      <xsl:otherwise>
380        <xsl:call-template name="error"><xsl:with-param name="text">Unknown type '<xsl:value-of select="@type"/>'</xsl:with-param></xsl:call-template>
381      </xsl:otherwise>
382    </xsl:choose>
383  </xsl:template>
384
385  <xsl:template match="text()" mode="expand-links">
386    <xsl:value-of select="."/>
387  </xsl:template>
388
389  <xsl:template match="*" mode="expand-links">
390    <xsl:call-template name="error"><xsl:with-param name="text">Illegal content for expand-links</xsl:with-param></xsl:call-template>
391  </xsl:template>
392
393  <xsl:template match="T">
394    <xsl:variable name="indent"><xsl:apply-templates mode="calc-indent" select=".."/></xsl:variable>
395    <xsl:variable name="prefix"><xsl:apply-templates mode="calc-prefix" select=".."/></xsl:variable>
396    <xsl:variable name="text"><xsl:apply-templates mode="expand-links"/></xsl:variable>
397
398    <xsl:choose>
399      <xsl:when test="@reflow='1'">
400        <xsl:call-template name="reflow-paragraph">
401          <xsl:with-param name="indent" select="$indent"/>
402          <xsl:with-param name="text" select="normalize-space($text)"/>
403          <xsl:with-param name="prefix" select="$prefix"/>
404        </xsl:call-template>
405        <xsl:text>&br;</xsl:text>
406      </xsl:when>
407      <xsl:otherwise>
408        <xsl:call-template name="indent-preformatted">
409          <xsl:with-param name="indent" select="$indent"/>
410          <xsl:with-param name="text" select="$text"/>
411          <xsl:with-param name="prefix" select="$prefix"/>
412        </xsl:call-template>
413        <xsl:text>&br;</xsl:text>
414      </xsl:otherwise>
415    </xsl:choose>
416  </xsl:template>
417
418  <xsl:template match="ENTRY"><xsl:apply-templates/></xsl:template>
419
420  <xsl:template match="P"><xsl:apply-templates/></xsl:template>
421
422  <xsl:template match="ENUM"><xsl:apply-templates/></xsl:template>
423  <xsl:template match="LIST"><xsl:apply-templates/></xsl:template>
424
425  <xsl:template match="SECTION" mode="main">
426    <xsl:text>&br;&br;</xsl:text>
427    <xsl:value-of select="@name"/>
428    <xsl:text>&br;&br;</xsl:text>
429    <xsl:apply-templates/>
430  </xsl:template>
431
432  <!-- ================================ -->
433  <!--     PAGE document wide layout    -->
434  <!-- ================================ -->
435
436  <!-- ============================== -->
437  <!--     insert document header     -->
438  <!-- ============================== -->
439  <xsl:template name="header">
440    <xsl:param name="title" select="'Untitled'"/>
441    <xsl:param name="for"/>
442    <xsl:text xml:space="preserve"># Generated from XML with Sablotron -- Stylesheet by Ralf Westram (ralf@arb-home.de)</xsl:text>
443    <xsl:choose>
444      <xsl:when test="$for='release'">
445        <xsl:text xml:space="preserve">
446#
447#  ****  You may edit this file, but the next ARB update will overwrite your changes  ****
448</xsl:text>
449      </xsl:when>
450      <xsl:when test="$for='devel'">
451        <xsl:text xml:space="preserve">
452#
453#  ****  DO NOT EDIT (edit in $(ARBHOME)/HELP_SOURCE/oldhelp instead)  ****
454</xsl:text>
455      </xsl:when>
456      <xsl:otherwise>
457        <xsl:call-template name="error"><xsl:with-param name="text">Illegal content in edit_warning</xsl:with-param></xsl:call-template>
458      </xsl:otherwise>
459    </xsl:choose>
460  </xsl:template>
461
462  <xsl:template match="PAGE">
463      <xsl:variable name="title">
464        <xsl:for-each select="TITLE">
465          <xsl:value-of select="text()"/>
466        </xsl:for-each>
467      </xsl:variable>
468      <xsl:call-template name="header">
469        <xsl:with-param name="title" select="$title"/>
470        <xsl:with-param name="for" select="@edit_warning"/>
471      </xsl:call-template>#
472# This page was converted by arb_help2xml and may look strange.
473# If you think it's really bad, please send a
474# <xsl:call-template name="insert-email-link">
475        <xsl:with-param name="linktext">mail</xsl:with-param>
476        <xsl:with-param name="address">helpfeedback</xsl:with-param>
477        <xsl:with-param name="subject" select="concat('Helppage ',$myname,' looks weird')"/>
478      </xsl:call-template>
479# to our help keeper.
480
481# UP references:
482<xsl:apply-templates mode="uplinks"/>
483# SUB references:
484<xsl:apply-templates mode="sublinks"/>
485# ------------------------------------------------------------
486# Start of real helpfile:
487TITLE&tab;<xsl:value-of select="normalize-space($title)"/>
488
489<xsl:apply-templates select="SECTION" mode="main"/>
490  </xsl:template>
491
492  <!-- ============ -->
493  <!--     text()   (should be last template)  -->
494  <!-- ============ -->
495  <xsl:template match="text()|*">
496   <xsl:choose>
497     <xsl:when test="string-length(name())>0">
498       <xsl:call-template name="error"><xsl:with-param name="text">Unknown TAG <xsl:value-of select="name()"/></xsl:with-param></xsl:call-template>
499      </xsl:when>
500      <xsl:otherwise>
501<!--        <xsl:value-of select="."/>-->
502<!--        <xsl:call-template name="error"><xsl:with-param name="text">Unexpected text</xsl:with-param></xsl:call-template>-->
503      </xsl:otherwise>
504    </xsl:choose>
505  </xsl:template>
506
507
508</xsl:transform>
509
Note: See TracBrowser for help on using the repository browser.