source: trunk/adm/guides/tracwiki.xsl @ 5

Last change on this file since 5 was 5, checked in by pinsard, 15 years ago

bug fix for wiki

  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1<?xml version='1.0' encoding='ISO-8859-1'?> 
2<xsl:stylesheet 
3xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4xmlns:xl="http://www.w3.org/1999/xlink"
5xmlns:d="http://docbook.org/ns/docbook"
6exclude-result-prefixes="d"
7version="1.0">
8<!--
9module :
10transformation docbook en un tracwiki
11
12original location :
13/usr/home/fplod/incas/ircaam/ircaam_ws/adm/guides/tracwiki.xsl sur aedon.locean-ipsl.upmc.fr
14
15must be followed by awk -f trackwiki.awk
16because I did not yet correctly handle "* text" (with no linefeed)
17
18update :
19$Id$
20fplod 2008-10-13T09:15:46Z aedon.locean-ipsl.upmc.fr (Darwin)
21creation from SAXO project
22cf http://forge.ipsl.jussieu.fr/superbib/wiki/WikiFormatting
23et http://www.sagehill.net/docbookxsl/CustomDb5Xsl.html
24car 1re xsl pour db5
25-->
26
27
28<!--
29xml output with no xml declaration : this is the only way to make xsl:copy-of copy
30nodes instead of contents of nodes
31-->
32<xsl:output method="xml" 
33indent="no" 
34omit-xml-declaration="yes"/>
35
36<xsl:strip-space elements="d:article d:sect1 d:sect2 d:sect3 d:sect4 d:variablellist d:itemizedlist d:listitem d:varlistentry d:term d:para d:simpara"/>
37
38<xsl:template match="/">
39 <xsl:apply-templates/>
40</xsl:template>
41
42<xsl:template match="d:article/d:title">
43<!-- pour ajouter une table des matières
44d'après
45http://groups.google.com/group/trac-users/browse_thread/thread/2c2cf9830c190a7d#e0a71ce3da67fb53
46-->
47 <xsl:text>= </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> =</xsl:text>
48 <xsl:text>&#xA;</xsl:text>
49 <xsl:text>[[PageOutline]]</xsl:text>
50 <xsl:text>&#xA;</xsl:text>
51</xsl:template>
52
53<xsl:template match="d:sect1/d:title">
54 <xsl:text>&#xA;</xsl:text>
55 <xsl:text>== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> ==</xsl:text>
56 <xsl:text>&#xA;</xsl:text>
57</xsl:template>
58
59<xsl:template match="d:qandadiv/d:title">
60 <xsl:text>&#xA;</xsl:text>
61 <xsl:text>== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> ==</xsl:text>
62 <xsl:text>&#xA;</xsl:text>
63</xsl:template>
64
65<xsl:template match="d:sect2/d:title">
66 <xsl:text>&#xA;</xsl:text>
67 <xsl:variable name="newtitle">
68  <xsl:call-template name="replace-string">
69   <xsl:with-param name="text" select="normalize-space(.)"/>
70   <xsl:with-param name="replace" select="'&gt;'"/>
71<!-- do not how to write > instead of &gt; ++. need sed features --> 
72   <xsl:with-param name="with" select="'&gt;'"/>
73  </xsl:call-template>
74 </xsl:variable>
75 <xsl:text>=== </xsl:text><xsl:value-of select="$newtitle"/><xsl:text> ===</xsl:text>
76 <xsl:text>&#xA;</xsl:text>
77</xsl:template>
78
79<xsl:template match="d:qandaentry/d:question/d:para">
80 <xsl:text>&#xA;</xsl:text>
81 <xsl:variable name="newtitle">
82  <xsl:call-template name="replace-string">
83   <xsl:with-param name="text" select="normalize-space(.)"/>
84   <xsl:with-param name="replace" select="'&gt;'"/>
85<!-- do not how to write > instead of &gt; ++. need sed features --> 
86   <xsl:with-param name="with" select="'&gt;'"/>
87  </xsl:call-template>
88 </xsl:variable>
89 <xsl:text>=== </xsl:text><xsl:value-of select="$newtitle"/><xsl:text> ===</xsl:text>
90 <xsl:text>&#xA;</xsl:text>
91</xsl:template>
92
93<xsl:template match="d:sect3/d:title">
94 <xsl:text>&#xA;</xsl:text>
95 <xsl:text>==== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> ====</xsl:text>
96 <xsl:text>&#xA;</xsl:text>
97</xsl:template>
98
99<xsl:template match="d:sect4/d:title">
100 <xsl:text>&#xA;</xsl:text>
101 <xsl:text>===== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> =====</xsl:text>
102 <xsl:text>&#xA;</xsl:text>
103</xsl:template>
104
105<xsl:template match="d:sect5/title">
106 <xsl:text>&#xA;</xsl:text>
107 <xsl:text>====== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> ======</xsl:text>
108 <xsl:text>&#xA;</xsl:text>
109</xsl:template>
110
111<xsl:template match="d:sect2/d:simplesect/d:title">
112 <xsl:text>&#xA;</xsl:text>
113 <xsl:text>==== </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text> ====</xsl:text>
114 <xsl:text>&#xA;</xsl:text>
115</xsl:template>
116
117<xsl:template match="d:systemitem">
118 <xsl:text>{{{</xsl:text><xsl:value-of select="."/><xsl:text>}}}</xsl:text>
119</xsl:template>
120
121<xsl:template match="d:para/d:command">
122 <xsl:text>{{{</xsl:text><xsl:value-of select="."/><xsl:text>}}}</xsl:text>
123</xsl:template>
124
125<xsl:template match="d:filename">
126 <xsl:choose>
127  <xsl:when test="local-name(..)='userinput'">
128   <xsl:value-of select="."/>
129  </xsl:when>
130  <xsl:when test="local-name(..)='lineannotation'">
131   <xsl:value-of select="."/>
132  </xsl:when>
133  <xsl:otherwise>
134   <xsl:text>{{{</xsl:text><xsl:value-of select="."/><xsl:text>}}}</xsl:text>
135  </xsl:otherwise>
136 </xsl:choose>
137</xsl:template>
138
139<xsl:template match="d:varname">
140 <xsl:text>{{{</xsl:text><xsl:value-of select="."/><xsl:text>}}}</xsl:text>
141</xsl:template>
142
143<xsl:template match="d:literallayout">
144 <xsl:text>{{{</xsl:text><xsl:apply-templates/><xsl:text>}}}</xsl:text>
145</xsl:template>
146<xsl:template match="d:literal">
147 <xsl:text>{{{</xsl:text><xsl:apply-templates/><xsl:text>}}}</xsl:text>
148</xsl:template>
149
150<xsl:template match="d:screen">
151 <!--
152we open an HTML block because it is not possible to have font effect (bold, italic) using TracWiki
153 -->
154 <xsl:text>&#xA;</xsl:text>
155 <xsl:text>{{{</xsl:text>
156 <xsl:text>&#xA;</xsl:text>
157 <xsl:text>#!html</xsl:text>
158 <xsl:text>&#xA;</xsl:text>
159 <pre class="screen">
160 <xsl:apply-templates/>
161 </pre>
162 <xsl:text>&#xA;</xsl:text>
163 <xsl:text>}}}</xsl:text>
164 <xsl:text>&#xA;</xsl:text>
165</xsl:template>
166
167<xsl:template match="d:programlisting">
168 <!--
169we open an HTML block because it is not possible to have font effect (bold, italic) using TracWiki
170 -->
171 <xsl:text>&#xA;</xsl:text>
172 <xsl:text>{{{</xsl:text>
173 <xsl:text>&#xA;</xsl:text>
174 <xsl:text>#!html</xsl:text>
175 <xsl:text>&#xA;</xsl:text>
176 <pre class="screen">
177 <xsl:apply-templates/>
178 </pre>
179 <xsl:text>&#xA;</xsl:text>
180 <xsl:text>}}}</xsl:text>
181 <xsl:text>&#xA;</xsl:text>
182</xsl:template>
183
184<xsl:template match="d:screen/d:prompt">
185<code class="prompt"><xsl:value-of select="."/></code>
186</xsl:template>
187
188<xsl:template match="d:screen/d:userinput">
189<strong class="userinput"><code><xsl:apply-templates/></code></strong>
190</xsl:template>
191
192<xsl:template match="d:screen/d:userinput/d:command">
193<span><strong class="command"><xsl:value-of select="."/></strong></span>
194</xsl:template>
195
196<xsl:template match="d:screen/d:userinput/d:option">
197<code class="option"><xsl:value-of select="."/></code>
198</xsl:template>
199
200<xsl:template match="d:screen/d:computeroutput">
201<code class="computeroutput"><xsl:value-of select="."/></code>
202</xsl:template>
203
204<xsl:template match="d:screen/d:userinput/d:parameter">
205<em class="parameter"><code><xsl:apply-templates/></code></em>
206</xsl:template>
207
208<xsl:template match="d:blockquote">
209  <xsl:text>  </xsl:text><xsl:apply-templates/>
210</xsl:template>
211
212<xsl:template match="d:itemizedlist/d:listitem/d:simpara/d:link[@xl:href]">
213 <xsl:text>&#xA;</xsl:text>
214 <xsl:text> [</xsl:text><xsl:value-of select="@xl:href"/> <xsl:text> </xsl:text><xsl:value-of select="."/> <xsl:text>]</xsl:text>
215</xsl:template>
216
217<xsl:template match="d:variablelist/">
218 <xsl:text>&#xA;</xsl:text>
219 <xsl:apply-templates/>
220</xsl:template>
221
222<xsl:template match="d:variablelist/d:varlistentry/d:listitem/d:simpara/d:link[@xl:href]">
223 <xsl:text>&#xA;</xsl:text>
224 <xsl:text> [</xsl:text><xsl:value-of select="@xl:href"/> <xsl:text> </xsl:text><xsl:value-of select="."/> <xsl:text>]</xsl:text>
225</xsl:template>
226
227<xsl:template match="d:quote">
228  <xsl:text>"</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>
229</xsl:template>
230
231<xsl:template match="d:itemizedlist/d:listitem">
232 <xsl:text>&#xA;</xsl:text>
233 <xsl:text> @star@ </xsl:text><xsl:apply-templates/>
234</xsl:template>
235
236<xsl:template match="d:imagedata[@fileref]">
237<!--
238ex : [[Image(source:/trunk/SRC/Documentation/xmldoc/images/showfig.png)]]
239-->
240<xsl:text>[[Image(source:/trunk/SRC/Documentation/xmldoc/</xsl:text><xsl:value-of select="@fileref"/><xsl:text>)]]</xsl:text>
241</xsl:template>
242
243<xsl:template match="d:link[@xl:href]">
244<xsl:variable name="link">
245 <xsl:choose>
246  <xsl:when test="contains(@xl:href,'firststeps.html')">
247   <xsl:text>wiki:FirstSteps</xsl:text>
248  </xsl:when>
249  <xsl:when test="contains(@xl:href,'faq.html')">
250   <xsl:text>wiki:Faq</xsl:text>
251  </xsl:when>
252  <xsl:when test="contains(@xl:href,'get.html')">
253   <xsl:text>wiki:Get</xsl:text>
254  </xsl:when>
255  <xsl:when test="contains(@xl:href,'mailing.html')">
256   <xsl:text>wiki:Mailing</xsl:text>
257  </xsl:when>
258  <xsl:when test="contains(@xl:href,'tiplink.html')">
259   <xsl:text>wiki:TipLink</xsl:text>
260  </xsl:when>
261  <xsl:when test="contains(@xl:href,'update.html')">
262   <xsl:text>wiki:Update</xsl:text>
263  </xsl:when>
264  <xsl:when test="contains(@xl:href,'whatis.html')">
265   <xsl:text>wiki:Whatis</xsl:text>
266  </xsl:when>
267  <xsl:when test="contains(@xl:href,'whatsnew.html')">
268   <xsl:text>wiki:WhatsNew</xsl:text>
269  </xsl:when>
270  <xsl:when test="contains(@xl:href,'index.html')">
271   <xsl:text>wiki:WikiStart</xsl:text>
272  </xsl:when>
273  <xsl:when test="contains(@xl:href,'../../')">
274   <xsl:text>source:/trunk/SRC/</xsl:text><xsl:value-of select="substring-after(@xl:href,'../../')"/>
275  </xsl:when>
276  <xsl:when test="contains(@xl:href,'figpng/')">
277   <xsl:text>source:/trunk/SRC/Documentation/xmldoc/figpng/</xsl:text><xsl:value-of select="substring-after(@xl:href,'figpng/')"/>
278  </xsl:when>
279  <xsl:otherwise>
280   <xsl:value-of select="@xl:href"/>
281  </xsl:otherwise>
282 </xsl:choose>
283</xsl:variable>
284<xsl:text>[</xsl:text><xsl:value-of select="$link"/> <xsl:text> </xsl:text><xsl:value-of select="."/> <xsl:text>]</xsl:text>
285</xsl:template>
286
287<xsl:template match="d:quote">
288  <xsl:text>"</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>
289</xsl:template>
290
291<xsl:template match="d:email">
292<xsl:text>[mailto:</xsl:text><xsl:value-of select="."/> <xsl:text> </xsl:text><xsl:value-of select="."/> <xsl:text>]</xsl:text>
293</xsl:template>
294
295<xsl:template match="d:variablelist/d:varlistentry/d:term">
296 <xsl:text>'''</xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>'''</xsl:text>
297</xsl:template>
298
299<xsl:template match="d:emphasis">
300  <xsl:text>''</xsl:text><xsl:value-of select="."/><xsl:text>''</xsl:text>
301</xsl:template>
302
303<xsl:template match="d:emphasis[@role='bold']">
304 <xsl:text>'''</xsl:text><xsl:value-of select="."/><xsl:text>'''</xsl:text>
305</xsl:template>
306
307<xsl:template match="d:caution">
308 <xsl:text>&#xA;</xsl:text>
309 <xsl:text>&#xA;</xsl:text>
310 <xsl:text>'''Caution'''</xsl:text>
311 <xsl:text>&#xA;</xsl:text>
312 <xsl:text>&#xA;</xsl:text>
313 <xsl:apply-templates/>
314</xsl:template>
315
316<xsl:template match="d:note">
317 <xsl:text>&#xA;</xsl:text>
318 <xsl:text>&#xA;</xsl:text>
319 <xsl:text>'''Note'''</xsl:text>
320 <xsl:text>&#xA;</xsl:text>
321 <xsl:text>&#xA;</xsl:text>
322 <xsl:apply-templates/>
323</xsl:template>
324
325<xsl:template match="d:replaceable">
326 <xsl:choose>
327  <xsl:when test="local-name(..)='userinput'">
328   <code class="replaceable"><xsl:value-of select="."/></code>
329  </xsl:when>
330  <xsl:when test="local-name(..)='parameter'">
331   <code class="replaceable"><xsl:value-of select="."/></code>
332  </xsl:when>
333  <xsl:otherwise>
334   <xsl:text>'''''</xsl:text><xsl:value-of select="."/><xsl:text>'''''</xsl:text>
335  </xsl:otherwise>
336 </xsl:choose>
337</xsl:template>
338
339<xsl:template match="d:superscript">
340  <xsl:text>^</xsl:text><xsl:value-of select="."/><xsl:text>^</xsl:text>
341</xsl:template>
342
343<xsl:template match="d:subscript">
344  <xsl:text>,,</xsl:text><xsl:value-of select="."/><xsl:text>,,</xsl:text>
345</xsl:template>
346
347<xsl:template match="d:simplelist">
348<!-- but beware of links inside -->
349 <xsl:text>&#xA;</xsl:text>
350 <xsl:text>{{{</xsl:text>
351 <xsl:text>&#xA;</xsl:text>
352 <xsl:text>#!docbook</xsl:text>
353 <xsl:text>&#xA;</xsl:text>
354 <xsl:copy-of select="."/>
355 <xsl:text>&#xA;</xsl:text>
356 <xsl:text>}}}</xsl:text>
357 <xsl:text>&#xA;</xsl:text>
358</xsl:template>
359
360<xsl:template match="d:informaltable">
361<!-- but beware of links inside -->
362 <xsl:text>&#xA;</xsl:text>
363 <xsl:text>{{{</xsl:text>
364 <xsl:text>&#xA;</xsl:text>
365 <xsl:text>#!docbook</xsl:text>
366 <xsl:text>&#xA;</xsl:text>
367 <xsl:copy-of select="."/>
368 <xsl:text>&#xA;</xsl:text>
369 <xsl:text>}}}</xsl:text>
370 <xsl:text>&#xA;</xsl:text>
371</xsl:template>
372
373<!-- ++ pb when in listitem/para
374<xsl:template match="d:menuchoice|d:guimenu|d:guisubmenu">
375 <xsl:text>&#xA;</xsl:text>
376 <xsl:text>{{{</xsl:text>
377 <xsl:text>&#xA;</xsl:text>
378 <xsl:text>#!docbook</xsl:text>
379 <xsl:text>&#xA;</xsl:text>
380 <xsl:copy-of select="."/>
381 <xsl:text>&#xA;</xsl:text>
382 <xsl:text>}}}</xsl:text>
383 <xsl:text>&#xA;</xsl:text>
384</xsl:template>
385-->
386
387<xsl:template match="d:informaltable">
388<!-- but beware of links inside -->
389 <xsl:text>&#xA;</xsl:text>
390 <xsl:text>{{{</xsl:text>
391 <xsl:text>&#xA;</xsl:text>
392 <xsl:text>#!docbook</xsl:text>
393 <xsl:text>&#xA;</xsl:text>
394 <xsl:copy-of select="."/>
395 <xsl:text>&#xA;</xsl:text>
396 <xsl:text>}}}</xsl:text>
397 <xsl:text>&#xA;</xsl:text>
398</xsl:template>
399
400<xsl:template match="d:link[@linkend]"> 
401 <xsl:variable name="target" select="key('id',@linkend)[1]"/>
402 <xsl:text>[#</xsl:text><xsl:value-of select="translate(normalize-space(//*[normalize-space(@xml:id='$target')]/d:title),' ','')"/><xsl:text>]</xsl:text>
403</xsl:template>
404
405<xsl:template match="d:xref"> 
406  <xsl:variable name="target" select="key('id',@linkend)[1]"/>
407  <xsl:text>[#</xsl:text><xsl:value-of select="translate(normalize-space(//d:sect1[normalize-space(@xml:id='$target')]/d:title),' ','')"/><xsl:text> </xsl:text> <xsl:value-of select="normalize-space(//d:sect1[normalize-space(@xml:id='$target')]/d:title)"/><xsl:text>]</xsl:text>
408</xsl:template>
409
410<xsl:template match="d:callout"> 
411 <xsl:text>[[Image(source:/trunk/SRC/Documentation/xmldoc/images/callouts/</xsl:text><xsl:value-of select="position() div 2"/><xsl:text>.png)]]</xsl:text><xsl:apply-templates/>
412</xsl:template>
413
414<xsl:template name="replace-string">
415<!-- from http://www.dpawson.co.uk/xsl/sect2/replace.html -->
416    <xsl:param name="text"/>
417    <xsl:param name="replace"/>
418    <xsl:param name="with"/>
419    <xsl:choose>
420      <xsl:when test="contains($text,$replace)">
421        <xsl:value-of select="substring-before($text,$replace)"/>
422        <xsl:value-of select="$with"/>
423        <xsl:call-template name="replace-string">
424          <xsl:with-param name="text"
425select="substring-after($text,$replace)"/>
426          <xsl:with-param name="replace" select="$replace"/>
427          <xsl:with-param name="with" select="$with"/>
428        </xsl:call-template>
429      </xsl:when>
430      <xsl:otherwise>
431        <xsl:value-of select="$text"/>
432      </xsl:otherwise>
433    </xsl:choose>
434  </xsl:template>
435
436<!-- do not reproduce the followings elements -->
437<xsl:template match="d:mediaobject/d:textobject"/>
438<xsl:template match="d:info/d:authorgroup"/>
439<xsl:template match="d:info/d:revhistory"/>
440<xsl:template match="d:info/d:pubdate"/>
441<xsl:template match="d:keywordset"/>
442
443</xsl:stylesheet> 
Note: See TracBrowser for help on using the repository browser.