]> matita.cs.unibo.it Git - helm.git/blob - helm/style/html_reals.xsl
15071579ab569b2d05eff9fbd1880d62be78fbaf
[helm.git] / helm / style / html_reals.xsl
1 <?xml version="1.0"?>
2
3 <!-- Copyright (C) 2000, HELM Team                                     -->
4 <!--                                                                   -->
5 <!-- This file is part of HELM, an Hypertextual, Electronic            -->
6 <!-- Library of Mathematics, developed at the Computer Science         -->
7 <!-- Department, University of Bologna, Italy.                         -->
8 <!--                                                                   -->
9 <!-- HELM is free software; you can redistribute it and/or             -->
10 <!-- modify it under the terms of the GNU General Public License       -->
11 <!-- as published by the Free Software Foundation; either version 2    -->
12 <!-- of the License, or (at your option) any later version.            -->
13 <!--                                                                   -->
14 <!-- HELM is distributed in the hope that it will be useful,           -->
15 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of    -->
16 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     -->
17 <!-- GNU General Public License for more details.                      -->
18 <!--                                                                   -->
19 <!-- You should have received a copy of the GNU General Public License -->
20 <!-- along with HELM; if not, write to the Free Software               -->
21 <!-- Foundation, Inc., 59 Temple Place - Suite 330, Boston,            -->
22 <!-- MA  02111-1307, USA.                                              -->
23 <!--                                                                   -->
24 <!-- For details, see the HELM World-Wide-Web page,                    -->
25 <!-- http://cs.unibo.it/helm/.                                         -->
26
27 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
28                               xmlns:m="http://www.w3.org/1998/Math/MathML">
29
30 <!--***********************************************************************--> 
31 <!-- INIT style for HTML                                                   -->
32 <!-- HELM Group: Asperti, Padovani, Sacerdoti, Schena                      -->
33 <!--***********************************************************************--> 
34
35 <xsl:template name="mksymbol-reals">
36  <xsl:param name="symbol" select="''"/>
37   <xsl:choose>
38    <xsl:when test="$UNICODEvsSYMBOL = 'symbol'">
39     <xsl:variable name="fontsymbol">
40      <xsl:choose>
41       <xsl:when test="$symbol = 'leadsto'">
42        <xsl:value-of select="'&#174;'"/>
43       </xsl:when>
44       <xsl:otherwise>
45        <xsl:text>???</xsl:text>
46       </xsl:otherwise>
47      </xsl:choose>
48     </xsl:variable>
49     <FONT FACE="symbol" color="'blue'">
50      <xsl:value-of select="$fontsymbol"/>
51     </FONT>
52    </xsl:when>
53    <xsl:otherwise>
54     <xsl:variable name="unicodesymbol">
55      <xsl:choose>
56       <xsl:when test="$symbol = 'leadsto'">
57        <xsl:value-of select="'&#8594;'"/>
58       </xsl:when>
59       <xsl:otherwise>
60        <xsl:text>???</xsl:text>
61       </xsl:otherwise>
62      </xsl:choose>
63     </xsl:variable>
64     <FONT color="'blue'">
65      <xsl:value-of select="$unicodesymbol"/>
66     </FONT>
67    </xsl:otherwise>
68   </xsl:choose>
69 </xsl:template>
70
71 <!-- **************************************************************** -->
72 <!--                   INLINE MODE                                    -->
73 <!-- **************************************************************** -->
74
75 <!-- LIMIT -->
76
77
78 <xsl:template mode="inline" match="m:apply[m:limit]">
79      <xsl:variable name="uri"><xsl:value-of select="m:limit/@definitionURL"/></xsl:variable>
80      <xsl:choose>
81      <xsl:when test="$uri != ''">
82       <a href="{$uri}">
83        <xsl:text>lim</xsl:text>
84       </a>
85      </xsl:when>
86      <xsl:otherwise>
87       <xsl:text>lim</xsl:text>
88      </xsl:otherwise>
89      </xsl:choose>
90      <SUB>
91       <xsl:apply-templates select="m:bvar/m:ci"/>
92       <xsl:call-template name="mksymbol-reals">
93        <xsl:with-param name="symbol" select="'leadsto'"/>
94       </xsl:call-template>
95       <xsl:apply-templates mode="inline" select="m:lowlimit"/>
96      </SUB>
97      <xsl:apply-templates mode="inline" select="*[4]"/>
98  </xsl:template>
99
100 <!-- DIFFERENTIATION -->
101
102 <xsl:template mode="inline" match="m:apply[m:diff]">
103      <xsl:variable name="uri"><xsl:value-of select="m:diff/@definitionURL"/></xsl:variable>
104      <xsl:choose>
105      <xsl:when test="$uri != ''">
106       <a href="{$uri}">
107        <SUP>d</SUP>
108        <xsl:text>/</xsl:text>
109        <SUB>
110         <xsl:text>d</xsl:text>
111         <xsl:value-of select="m:bvar/m:ci"/>
112        </SUB>
113       </a>
114      </xsl:when>
115      <xsl:otherwise>
116       <SUP>d</SUP>
117        <xsl:text>/</xsl:text>
118        <SUB>
119         <xsl:text>d</xsl:text>
120         <xsl:value-of select="m:bvar/m:ci"/>
121        </SUB>
122      </xsl:otherwise>
123      </xsl:choose>
124      <xsl:apply-templates mode="inline" select="*[3]"/>
125  </xsl:template>
126
127 <!-- ABSOLUTE VALUE -->
128 <xsl:template mode="inline" match="m:apply[m:abs]">
129   <xsl:variable name="uri">
130    <xsl:value-of select="m:abs/@definitionURL"/>
131   </xsl:variable>
132   <xsl:text>|</xsl:text>
133   <xsl:apply-templates mode="inline" select="*[2]"/>
134   <xsl:text>|</xsl:text>
135 </xsl:template>
136
137 <!-- FACTORIAL -->
138
139 <xsl:template mode="inline" match="m:apply[m:fact]">
140   <xsl:variable name="uri">
141    <xsl:value-of select="m:abs/@definitionURL"/>
142   </xsl:variable>
143   <xsl:apply-templates mode="inline" select="*[2]"/>
144   <xsl:text>!</xsl:text>
145 </xsl:template>
146
147 <!-- SQUARE ROOT -->
148
149 <xsl:template match="m:apply[m:root]">
150   <xsl:variable name="uri">
151    <xsl:value-of select="m:abs/@definitionURL"/>
152   </xsl:variable>
153   <xsl:text>(sqr</xsl:text>
154   <xsl:apply-templates mode="inline" select="*[2]"/>
155   <xsl:text>)</xsl:text>
156 </xsl:template>
157
158 <!-- POWER -->
159
160 <xsl:template mode="inline" match="m:apply[m:power]">
161   <xsl:variable name="uri">
162    <xsl:value-of select="m:power/@definitionURL"/>
163   </xsl:variable>
164   <xsl:apply-templates mode="inline" select="*[2]"/>
165   <SUP>
166   <xsl:apply-templates mode="inline" select="*[3]"/>
167   </SUP>
168 </xsl:template>
169
170 <!-- MIN and MAX (binari: estendere) -->
171
172  <xsl:template mode="inline" match="m:apply[m:min|m:max]">
173   <xsl:variable name="uri"><xsl:value-of select="*[1]/@definitionURL"/></xsl:variable>
174   <xsl:variable name="symbol">
175    <xsl:choose>
176     <xsl:when test="m:min">
177      <xsl:value-of select="'min'"/>
178     </xsl:when>
179     <xsl:when test="m:max">
180      <xsl:value-of select="'max'"/>
181     </xsl:when>
182    </xsl:choose>
183   </xsl:variable>
184   <xsl:choose>
185   <xsl:when test="$uri != ''">
186    <a href="{$uri}">
187     <xsl:value-of select="$symbol"/>
188    </a>
189   </xsl:when>
190   <xsl:otherwise>
191    <xsl:value-of select="$symbol"/>
192   </xsl:otherwise>
193   </xsl:choose>
194   <xsl:text>{</xsl:text>
195   <xsl:apply-templates mode="inline" select="*[2]"/>
196   <xsl:text>, </xsl:text>
197   <xsl:apply-templates mode="inline" select="*[3]"/>
198   <xsl:text>}</xsl:text>
199 </xsl:template>
200
201 <!-- **************************************************************** -->
202 <!--                   COUNTING MODE                                    -->
203 <!-- **************************************************************** -->
204
205
206 <xsl:template match="m:apply[m:limit]">
207   <xsl:param name="current_indent" select="0"/> 
208   <xsl:param name="width" select="$framewidth"/>
209   <xsl:variable name="uri"><xsl:value-of select="m:limit/@definitionURL"/></xsl:variable>
210   <xsl:variable name="charlength">
211    <xsl:apply-templates select="m:limit" mode="charcount"/>
212   </xsl:variable>
213   <xsl:choose>
214     <xsl:when test="$charlength > $framewidth">
215      <xsl:choose>
216      <xsl:when test="$uri != ''">
217       <a href="{$uri}">
218        <xsl:text>lim</xsl:text>
219       </a>
220      </xsl:when>
221      <xsl:otherwise>
222       <xsl:text>lim</xsl:text>
223      </xsl:otherwise>
224      </xsl:choose>
225      <SUB>
226       <xsl:apply-templates select="m:bvar/m:ci"/>
227       <xsl:call-template name="mksymbol-reals">
228        <xsl:with-param name="symbol" select="'leadsto'"/>
229       </xsl:call-template>
230       <xsl:apply-templates select="m:lowlimit"/>
231      </SUB>
232      <BR/> 
233      <xsl:call-template name="make_indent">
234       <xsl:with-param name="current_indent" select="$current_indent + 5"/> 
235      </xsl:call-template>
236      <xsl:apply-templates select="*[4]">
237       <xsl:with-param name="current_indent" select="$current_indent + 5"/>
238      </xsl:apply-templates>
239     </xsl:when>
240     <xsl:otherwise>
241      <xsl:apply-templates mode="inline" select="."/>
242     </xsl:otherwise>
243    </xsl:choose>
244  </xsl:template>
245
246 <!-- DIFFERENTIATION -->
247 <xsl:template match="m:apply[m:diff]">
248   <xsl:param name="current_indent" select="0"/> 
249   <xsl:param name="width" select="$framewidth"/>
250   <xsl:variable name="uri"><xsl:value-of select="m:diff/@definitionURL"/></xsl:variable>
251      <xsl:choose>
252      <xsl:when test="$uri != ''">
253       <a href="{$uri}">
254        <SUP>d</SUP>
255        <xsl:text>/</xsl:text>
256        <SUB>
257         <xsl:text>d</xsl:text>
258         <xsl:value-of select="m:bvar/m:ci"/>
259        </SUB>
260       </a>
261      </xsl:when>
262      <xsl:otherwise>
263        <SUP>d</SUP>
264        <xsl:text>/</xsl:text>
265        <SUB>
266         <xsl:text>d</xsl:text>
267         <xsl:value-of select="m:bvar/m:ci"/>
268        </SUB>
269      </xsl:otherwise>
270      </xsl:choose>
271      <xsl:apply-templates select="*[3]">
272       <xsl:with-param name="current_indent" select="$current_indent + 5"/>
273      </xsl:apply-templates>
274  </xsl:template>
275
276
277 <!-- ABSOLUTE VALUE -->
278 <xsl:template match="m:apply[m:abs]">
279   <xsl:param name="current_indent" select="0"/> 
280   <xsl:param name="width" select="$framewidth"/>
281   <xsl:variable name="uri">
282    <xsl:value-of select="m:abs/@definitionURL"/>
283   </xsl:variable>
284   <xsl:text>|</xsl:text>
285   <xsl:apply-templates select="*[2]">
286    <xsl:with-param name="current_indent" select="$current_indent + 2"/>
287   </xsl:apply-templates>
288   <xsl:text>|</xsl:text>
289  </xsl:template>
290
291 <!-- FACTORIAL -->
292
293 <xsl:template match="m:apply[m:fact]">
294   <xsl:param name="current_indent" select="0"/> 
295   <xsl:param name="width" select="$framewidth"/>
296   <xsl:variable name="uri">
297    <xsl:value-of select="m:abs/@definitionURL"/>
298   </xsl:variable>
299   <xsl:apply-templates select="*[2]">
300    <xsl:with-param name="current_indent" select="$current_indent + 2"/>
301   </xsl:apply-templates>
302   <xsl:text>!</xsl:text>
303  </xsl:template>
304
305 <!-- SQUARE ROOT -->
306
307 <xsl:template match="m:apply[m:root]">
308   <xsl:param name="current_indent" select="0"/> 
309   <xsl:param name="width" select="$framewidth"/>
310   <xsl:variable name="uri">
311    <xsl:value-of select="m:abs/@definitionURL"/>
312   </xsl:variable>
313   <xsl:text>(sqr</xsl:text>
314   <xsl:apply-templates select="*[2]">
315    <xsl:with-param name="current_indent" select="$current_indent + 5"/>
316   </xsl:apply-templates>
317   <xsl:text>)</xsl:text>
318  </xsl:template>
319
320 <!-- POWER -->
321
322 <xsl:template match="m:apply[m:power]">
323   <xsl:param name="current_indent" select="0"/> 
324   <xsl:param name="width" select="$framewidth"/>
325   <xsl:variable name="uri">
326    <xsl:value-of select="m:power/@definitionURL"/>
327   </xsl:variable>
328   <xsl:apply-templates select="*[2]"/>
329   <SUP>
330   <xsl:apply-templates select="*[3]"/>
331   </SUP>
332  </xsl:template>
333
334 <!-- MIN and MAX (binari: estendere) -->
335
336  <xsl:template match="m:apply[m:min|m:max]">
337   <xsl:param name="current_indent" select="0"/> 
338   <xsl:param name="width" select="$framewidth"/>
339   <xsl:variable name="uri"><xsl:value-of select="*[1]/@definitionURL"/></xsl:variable>
340   <xsl:variable name="charlength">
341    <xsl:apply-templates select="*[1]" mode="charcount"/>
342   </xsl:variable>
343   <xsl:variable name="symbol">
344    <xsl:choose>
345     <xsl:when test="m:min">
346      <xsl:value-of select="'min'"/>
347     </xsl:when>
348     <xsl:when test="m:max">
349      <xsl:value-of select="'max'"/>
350     </xsl:when>
351    </xsl:choose>
352   </xsl:variable>
353   <xsl:choose>
354     <xsl:when test="$charlength > $framewidth">
355      <xsl:choose>
356      <xsl:when test="$uri != ''">
357       <a href="{$uri}">
358        <xsl:value-of select="$symbol"/>
359       </a>
360      </xsl:when>
361      <xsl:otherwise>
362       <xsl:value-of select="$symbol"/>
363      </xsl:otherwise>
364      </xsl:choose>
365      <xsl:text>{</xsl:text>
366      <xsl:apply-templates select="*[2]">
367       <xsl:with-param name="current_indent" select="$current_indent + 2"/>
368      </xsl:apply-templates>
369      <xsl:text>,</xsl:text>
370      <BR/> 
371      <xsl:call-template name="make_indent">
372       <xsl:with-param name="current_indent" select="$current_indent + 5"/> 
373      </xsl:call-template>
374      <xsl:apply-templates select="*[3]">
375       <xsl:with-param name="current_indent" select="$current_indent + 2"/>
376      </xsl:apply-templates>
377      <xsl:text>}</xsl:text>
378     </xsl:when>
379     <xsl:otherwise>
380      <xsl:apply-templates mode="inline" select="."/>
381     </xsl:otherwise>
382    </xsl:choose>
383  </xsl:template>
384
385 <!-- COUNTING -->
386
387 <xsl:template match="m:abs|m:fact|m:root
388            |m:limit|m:diff|m:min|m:max" mode="charcount">
389 <xsl:param name="incurrent_length" select="0"/> 
390     <xsl:choose>
391     <xsl:when test="$framewidth >= ($incurrent_length + string-length())">
392      <xsl:variable name="siblength"><xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length + string-length()"/></xsl:apply-templates></xsl:variable>
393      <xsl:choose>
394      <xsl:when test="string($siblength) = &quot;&quot;">
395       <xsl:value-of select="$incurrent_length + string-length()"/>
396      </xsl:when>
397      <xsl:otherwise>
398       <xsl:value-of select="number($siblength)"/>
399      </xsl:otherwise>
400      </xsl:choose>
401     </xsl:when>
402     <xsl:otherwise>
403      <xsl:value-of select="$incurrent_length + string-length()"/>
404     </xsl:otherwise>
405     </xsl:choose>
406 </xsl:template> 
407
408 </xsl:stylesheet>