]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mmlnotation.xsl
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / style / mmlnotation.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 <!--***********************************************************************--> 
28 <!-- Notational extensions to the XSLT version 0.07 of MathML content      -->
29 <!-- to presentation:                                                      -->
30 <!-- First draft: February 19 2000, Andrea Asperti, Irene Schena           -->
31 <!-- Revised: March 3 2000, Irene Schena                                   -->
32 <!-- Revised: March 15 2000, Claudio Sacerdoti Coen, Irene Schena          -->
33 <!-- Revised: March 21 2000, Irene Schena                                  -->
34 <!--***********************************************************************--> 
35
36 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37                               xmlns:m="http://www.w3.org/1998/Math/MathML">
38
39 <xsl:import href="mmlctop.xsl"/>
40
41
42 <!-- *********************************** -->
43 <!-- BASE SET OF MATHML CONTENT ELEMENTS -->
44 <!-- *********************************** -->
45
46 <!-- Logic -->
47
48 <xsl:template match = "m:apply[m:eq[1]]">
49  <xsl:variable name="charlength">
50   <xsl:apply-templates select="*[1]" mode="charcount"/>
51  </xsl:variable>
52  <xsl:choose>
53   <xsl:when test="$charlength >= $framewidth">
54    <m:mtable align="baseline 1" equalrows="false" columnalign="left">
55     <xsl:if test="@id">
56      <xsl:attribute name="xref">
57       <xsl:value-of select="@id"/>
58      </xsl:attribute>
59     </xsl:if>    
60     <m:mtr>
61      <m:mtd>
62       <m:mrow>
63        <m:mo stretchy="false">(</m:mo>
64        <xsl:apply-templates select="*[position()=2]"/>
65       </m:mrow>
66      </m:mtd>
67     </m:mtr>
68     <xsl:for-each select = "*[position()>2]">
69      <m:mtr>
70       <m:mtd>
71        <m:mrow>
72         <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
73         <m:mo>
74          <xsl:if test="m:in/@id">
75           <xsl:attribute name="xref">
76            <xsl:value-of select="m:in/@id"/>
77           </xsl:attribute>
78          </xsl:if>=</m:mo>
79         <xsl:apply-templates select="."/>
80        </m:mrow>
81       </m:mtd>
82      </m:mtr>
83     </xsl:for-each>
84     <m:mtr>
85      <m:mtd>
86       <m:mrow>
87        <m:mo stretchy="false">)</m:mo>
88       </m:mrow>
89      </m:mtd>
90     </m:mtr>
91    </m:mtable>
92   </xsl:when>
93   <xsl:otherwise>
94    <xsl:apply-imports/>
95   </xsl:otherwise>
96  </xsl:choose>
97 </xsl:template>
98
99 <!-- apply-imports without parenthesis -->
100 <xsl:template match = "m:apply[m:geq[1]|m:leq[1]|m:gt[1]|m:lt[1]|m:in[1]|
101                                m:subset[1]|m:prsubset[1]]">
102  <xsl:variable name="symbol">
103   <xsl:choose>
104    <xsl:when test="m:geq[1]">
105     <xsl:value-of select="'&#8805;'"/>
106    </xsl:when>
107    <xsl:when test="m:leq[1]">
108     <xsl:value-of select="'&#8804;'"/>
109    </xsl:when>
110    <xsl:when test="m:gt[1]">
111     <xsl:value-of select="'&#62;'"/>
112    </xsl:when>
113    <xsl:when test="m:lt[1]">
114     <xsl:value-of select="'&#60;&#32;'"/>
115    </xsl:when>
116    <xsl:when test="m:in[1]">
117     <xsl:value-of select="'&#x02208;'"/>
118    </xsl:when>
119    <xsl:when test="m:subset[1]">
120     <xsl:value-of select="'&#x02286;'"/>
121    </xsl:when>
122    <xsl:when test="m:prsubset[1]">
123     <xsl:value-of select="'&#x02282;'"/>
124    </xsl:when>
125   </xsl:choose>
126  </xsl:variable>
127  <xsl:variable name="charlength">
128   <xsl:apply-templates select="*[1]" mode="charcount"/>
129  </xsl:variable>
130  <xsl:choose>
131   <xsl:when test="$charlength >= $framewidth">
132    <m:mtable align="baseline 1" equalrows="false" columnalign="left">
133     <xsl:if test="@id">
134      <xsl:attribute name="xref">
135       <xsl:value-of select="@id"/>
136      </xsl:attribute>
137     </xsl:if>    
138     <m:mtr>
139      <m:mtd>
140       <m:mrow>
141        <m:mo stretchy="false">(</m:mo>
142        <xsl:apply-templates select="*[position()=2]"/>
143       </m:mrow>
144      </m:mtd>
145     </m:mtr>
146     <xsl:for-each select = "*[position()>2]">
147      <m:mtr>
148       <m:mtd>
149        <m:mrow>
150         <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
151         <m:mo>
152          <xsl:if test="*[1]/@id">
153           <xsl:attribute name="xref">
154            <xsl:value-of select="*[1]/@id"/>
155           </xsl:attribute>
156          </xsl:if><xsl:value-of select="$symbol"/></m:mo>
157         <xsl:apply-templates select="."/>
158        </m:mrow>
159       </m:mtd>
160      </m:mtr>
161     </xsl:for-each>
162     <m:mtr>
163      <m:mtd>
164       <m:mrow>
165        <m:mo stretchy="false">)</m:mo>
166       </m:mrow>
167      </m:mtd>
168     </m:mtr>
169    </m:mtable>
170   </xsl:when>
171   <xsl:otherwise>
172    <xsl:apply-imports/>
173   </xsl:otherwise>
174  </xsl:choose>
175 </xsl:template>
176
177 <!-- apply-imports with parenthesis -->
178 <xsl:template match = "m:apply[m:and[1]|m:or[1]
179           |m:intesect[1]|m:union[1]|m:setdiff[1]]">
180  <xsl:variable name="symbol">
181   <xsl:choose>
182    <xsl:when test="m:and[1]">
183     <xsl:value-of select="'&#8743;'"/>
184    </xsl:when>
185    <xsl:when test="m:or[1]">
186     <xsl:value-of select="'&#8744;'"/>
187    </xsl:when>
188    <xsl:when test="m:intersect[1]">
189     <xsl:value-of select="'&#x022C2;'"/>
190    </xsl:when>
191    <xsl:when test="m:union[1]">
192     <xsl:value-of select="'&#x022C3;'"/>
193    </xsl:when>
194    <xsl:when test="m:setdiff[1]">
195     <xsl:value-of select="'&#x02216;'"/>
196    </xsl:when>
197   </xsl:choose>
198  </xsl:variable>
199  <xsl:variable name="charlength">
200   <xsl:apply-templates select="*[1]" mode="charcount"/>
201  </xsl:variable>
202  <xsl:choose>
203   <xsl:when test="$charlength >= $framewidth">
204    <m:mtable align="baseline 1" equalrows="false" columnalign="left">
205     <xsl:if test="@id">
206      <xsl:attribute name="xref">
207       <xsl:value-of select="@id"/>
208      </xsl:attribute>
209     </xsl:if>    
210     <m:mtr>
211      <m:mtd>
212       <m:mrow>
213        <m:mo stretchy="false">(</m:mo>
214        <xsl:apply-templates select="*[position()=2]"/>
215       </m:mrow>
216      </m:mtd>
217     </m:mtr>
218     <xsl:for-each select = "*[position()>2]">
219      <m:mtr>
220       <m:mtd>
221        <m:mrow>
222         <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
223         <m:mo>
224          <xsl:if test="*[1]/@id">
225           <xsl:attribute name="xref">
226            <xsl:value-of select="*[1]/@id"/>
227           </xsl:attribute>
228          </xsl:if><xsl:value-of select="$symbol"/></m:mo>
229         <xsl:apply-templates select="."/>
230        </m:mrow>
231       </m:mtd>
232      </m:mtr>
233     </xsl:for-each>
234     <m:mtr>
235      <m:mtd>
236       <m:mrow>
237        <m:mo stretchy="false">)</m:mo>
238       </m:mrow>
239      </m:mtd>
240     </m:mtr>
241    </m:mtable>
242   </xsl:when>
243   <xsl:otherwise>
244 <!-- Added mfenced because apply-imports doesn't support with-param for 
245      precedence  (XSLT 2.0) -->
246    <m:mfenced separators=" ">
247     <xsl:apply-imports/>
248    </m:mfenced>
249   </xsl:otherwise>
250  </xsl:choose>
251 </xsl:template>
252
253 <xsl:template match = "m:set">
254  <xsl:choose>
255   <xsl:when test="count(child::*) = 0">
256    <m:mi>
257     <xsl:if test="@id">
258      <xsl:attribute name="xref">
259       <xsl:value-of select="@id"/>
260      </xsl:attribute>
261     </xsl:if>&#x02205;</m:mi>
262   </xsl:when>
263   <xsl:otherwise>
264    <xsl:variable name="charlength">
265     <xsl:apply-templates select="*[1]" mode="charcount"/>
266    </xsl:variable>
267    <xsl:choose>
268     <xsl:when test="$charlength >= $framewidth">
269      <xsl:choose>
270       <xsl:when test="name(*[1]) = 'm:bvar'">
271        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
272         <m:mtr>
273          <m:mtd>
274           <m:mrow>
275            <m:mo stretchy="false">
276             <xsl:if test="@id">
277              <xsl:attribute name="xref">
278               <xsl:value-of select="@id"/>
279              </xsl:attribute>
280             </xsl:if>{</m:mo>
281            <xsl:apply-templates select="*[position()=1]"/>
282           </m:mrow>
283          </m:mtd>
284         </m:mtr>
285         <m:mtr>
286          <m:mtd>
287           <m:mrow>
288            <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
289            <m:mo stretchy="false">|</m:mo>
290            <xsl:apply-templates select="m:condition/*[1]"/>
291           </m:mrow>
292          </m:mtd>
293         </m:mtr>
294         <m:mtr>
295          <m:mtd>
296           <m:mrow>
297            <m:mo stretchy="false">
298             <xsl:if test="@id">
299              <xsl:attribute name="xref">
300               <xsl:value-of select="@id"/>
301              </xsl:attribute>
302             </xsl:if>}</m:mo>
303           </m:mrow>
304          </m:mtd>
305         </m:mtr>
306        </m:mtable>
307       </xsl:when>
308       <xsl:otherwise>
309        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
310         <m:mtr>
311          <m:mtd>
312           <m:mrow>
313            <m:mo stretchy="false">
314             <xsl:if test="@id">
315              <xsl:attribute name="xref">
316               <xsl:value-of select="@id"/>
317              </xsl:attribute>
318             </xsl:if>{</m:mo>
319            <xsl:apply-templates select="*[position()=1]"/>
320            <xsl:if test="position() != last()">
321             <mo>,</mo>
322            </xsl:if>
323           </m:mrow>
324          </m:mtd>
325         </m:mtr>
326         <xsl:for-each select = "*[position()>2]">
327          <m:mtr>
328           <m:mtd>
329            <m:mrow>
330             <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
331             <xsl:apply-templates select="."/>
332             <xsl:if test="position() != last()">
333              <mo>,</mo>
334             </xsl:if>
335            </m:mrow>
336           </m:mtd>
337          </m:mtr>
338         </xsl:for-each>
339         <m:mtr>
340          <m:mtd>
341           <m:mrow>
342            <m:mo stretchy="false">
343             <xsl:if test="@id">
344              <xsl:attribute name="xref">
345               <xsl:value-of select="@id"/>
346              </xsl:attribute>
347             </xsl:if>}</m:mo>
348           </m:mrow>
349          </m:mtd>
350         </m:mtr>
351        </m:mtable>
352       </xsl:otherwise>
353      </xsl:choose>
354     </xsl:when>
355     <xsl:otherwise>
356      <xsl:apply-imports/>
357     </xsl:otherwise>
358    </xsl:choose>
359   </xsl:otherwise>
360  </xsl:choose>
361 </xsl:template>      
362
363 <xsl:template match = "m:apply[m:card[1]]">
364   <m:mfenced open="|" close="|" stretchy="false">
365     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
366       <xsl:attribute name="xref">
367         <xsl:value-of select="@id"/>
368       </xsl:attribute>
369     </xsl:if>
370   <xsl:apply-templates select="*[2]"/>
371   </m:mfenced>
372 </xsl:template>
373
374
375 <xsl:template match = "m:eq[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))] | m:neq[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))] | m:lt[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))] | m:gt[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))] | m:leq[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))] | m:geq[((preceding-sibling::*/text()='eq_chain') or (preceding-sibling::*/text()='diseq_chain'))]">
376   <xsl:choose>
377   <xsl:when test="local-name(.) = 'neq'">
378    <xsl:value-of select="'&#8800;'"/>
379   </xsl:when>
380   <xsl:when test="local-name(.) = 'lt'">
381    <xsl:value-of select="'&#60;&#32;'"/>
382   </xsl:when>
383   <xsl:when test="local-name(.) = 'gt'">
384    <xsl:value-of select="'&#62;'"/>
385   </xsl:when>
386   <xsl:when test="local-name(.) = 'leq'">
387    <xsl:value-of select="'&#8804;'"/>
388   </xsl:when>
389   <xsl:when test="local-name(.) = 'geq'">
390    <xsl:value-of select="'&#8805;'"/>
391   </xsl:when>
392   <xsl:otherwise>
393    <xsl:value-of select="'&#61;'"/>
394   </xsl:otherwise>
395   </xsl:choose>       
396 </xsl:template>
397
398
399 </xsl:stylesheet>