]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mmlnotation.xsl
3ebf23ba7d41069148733fde635a124e6054ea95
[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-0.14"/>
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
100 <xsl:template match = "m:apply[m:and[1]|m:or[1]
101           |m:geq[1]|m:leq[1]|m:gt[1]|m:lt[1]
102           |m:in[1]|m:intesect[1]|m:union[1]|m:subset[1]
103           |m:prsubset|m:setdiff[1]]">
104  <xsl:variable name="symbol">
105   <xsl:choose>
106    <xsl:when test="m:and[1]">
107     <xsl:value-of select="'&#8743;'"/>
108    </xsl:when>
109    <xsl:when test="m:or[1]">
110     <xsl:value-of select="'&#8744;'"/>
111    </xsl:when>
112    <xsl:when test="m:geq[1]">
113     <xsl:value-of select="'&#8805;'"/>
114    </xsl:when>
115    <xsl:when test="m:leq[1]">
116     <xsl:value-of select="'&#8804;'"/>
117    </xsl:when>
118    <xsl:when test="m:gt[1]">
119     <xsl:value-of select="'&#62;'"/>
120    </xsl:when>
121    <xsl:when test="m:lt[1]">
122     <xsl:value-of select="'&#60;&#32;'"/>
123    </xsl:when>
124    <xsl:when test="m:eq[1]">
125     <xsl:value-of select="'&#61;'"/>
126    </xsl:when>
127    <xsl:when test="m:in[1]">
128     <xsl:value-of select="'&#x02208;'"/>
129    </xsl:when>
130    <xsl:when test="m:subset[1]">
131     <xsl:value-of select="'&#x02286;'"/>
132    </xsl:when>
133    <xsl:when test="m:prsubset[1]">
134     <xsl:value-of select="'&#x02282;'"/>
135    </xsl:when>
136    <xsl:when test="m:intersect[1]">
137     <xsl:value-of select="'&#x022C2;'"/>
138    </xsl:when>
139    <xsl:when test="m:union[1]">
140     <xsl:value-of select="'&#x022C3;'"/>
141    </xsl:when>
142    <xsl:when test="m:setdiff[1]">
143     <xsl:value-of select="'&#x02216;'"/>
144    </xsl:when>
145   </xsl:choose>
146  </xsl:variable>
147  <xsl:variable name="charlength">
148   <xsl:apply-templates select="*[1]" mode="charcount"/>
149  </xsl:variable>
150  <xsl:choose>
151   <xsl:when test="$charlength >= $framewidth">
152    <m:mtable align="baseline 1" equalrows="false" columnalign="left">
153     <xsl:if test="@id">
154      <xsl:attribute name="xref">
155       <xsl:value-of select="@id"/>
156      </xsl:attribute>
157     </xsl:if>    
158     <m:mtr>
159      <m:mtd>
160       <m:mrow>
161        <m:mo stretchy="false">(</m:mo>
162        <xsl:apply-templates select="*[position()=2]"/>
163       </m:mrow>
164      </m:mtd>
165     </m:mtr>
166     <xsl:for-each select = "*[position()>2]">
167      <m:mtr>
168       <m:mtd>
169        <m:mrow>
170         <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
171         <m:mo>
172          <xsl:if test="*[1]/@id">
173           <xsl:attribute name="xref">
174            <xsl:value-of select="*[1]/@id"/>
175           </xsl:attribute>
176          </xsl:if><xsl:value-of select="$symbol"/></m:mo>
177         <xsl:apply-templates select="."/>
178        </m:mrow>
179       </m:mtd>
180      </m:mtr>
181     </xsl:for-each>
182     <m:mtr>
183      <m:mtd>
184       <m:mrow>
185        <m:mo stretchy="false">)</m:mo>
186       </m:mrow>
187      </m:mtd>
188     </m:mtr>
189    </m:mtable>
190   </xsl:when>
191   <xsl:otherwise>
192    <xsl:apply-imports/>
193   </xsl:otherwise>
194  </xsl:choose>
195 </xsl:template>
196
197 <xsl:template match = "m:set">
198  <xsl:choose>
199   <xsl:when test="count(child::*) = 0">
200    <m:mi>
201     <xsl:if test="@id">
202      <xsl:attribute name="xref">
203       <xsl:value-of select="@id"/>
204      </xsl:attribute>
205     </xsl:if>&#x02205;</m:mi>
206   </xsl:when>
207   <xsl:otherwise>
208    <xsl:variable name="charlength">
209     <xsl:apply-templates select="*[1]" mode="charcount"/>
210    </xsl:variable>
211    <xsl:choose>
212     <xsl:when test="$charlength >= $framewidth">
213      <xsl:choose>
214       <xsl:when test="name(*[1]) = 'm:bvar'">
215        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
216         <m:mtr>
217          <m:mtd>
218           <m:mrow>
219            <m:mo stretchy="false">
220             <xsl:if test="@id">
221              <xsl:attribute name="xref">
222               <xsl:value-of select="@id"/>
223              </xsl:attribute>
224             </xsl:if>{</m:mo>
225            <xsl:apply-templates select="*[position()=1]"/>
226           </m:mrow>
227          </m:mtd>
228         </m:mtr>
229         <m:mtr>
230          <m:mtd>
231           <m:mrow>
232            <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
233            <m:mo stretchy="false">|</m:mo>
234            <xsl:apply-templates select="m:condition/*[1]"/>
235           </m:mrow>
236          </m:mtd>
237         </m:mtr>
238         <m:mtr>
239          <m:mtd>
240           <m:mrow>
241            <m:mo stretchy="false">
242             <xsl:if test="@id">
243              <xsl:attribute name="xref">
244               <xsl:value-of select="@id"/>
245              </xsl:attribute>
246             </xsl:if>}</m:mo>
247           </m:mrow>
248          </m:mtd>
249         </m:mtr>
250        </m:mtable>
251       </xsl:when>
252       <xsl:otherwise>
253        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
254         <m:mtr>
255          <m:mtd>
256           <m:mrow>
257            <m:mo stretchy="false">
258             <xsl:if test="@id">
259              <xsl:attribute name="xref">
260               <xsl:value-of select="@id"/>
261              </xsl:attribute>
262             </xsl:if>{</m:mo>
263            <xsl:apply-templates select="*[position()=1]"/>
264            <xsl:if test="position() != last()">
265             <mo>,</mo>
266            </xsl:if>
267           </m:mrow>
268          </m:mtd>
269         </m:mtr>
270         <xsl:for-each select = "*[position()>2]">
271          <m:mtr>
272           <m:mtd>
273            <m:mrow>
274             <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
275             <xsl:apply-templates select="."/>
276             <xsl:if test="position() != last()">
277              <mo>,</mo>
278             </xsl:if>
279            </m:mrow>
280           </m:mtd>
281          </m:mtr>
282         </xsl:for-each>
283         <m:mtr>
284          <m:mtd>
285           <m:mrow>
286            <m:mo stretchy="false">
287             <xsl:if test="@id">
288              <xsl:attribute name="xref">
289               <xsl:value-of select="@id"/>
290              </xsl:attribute>
291             </xsl:if>}</m:mo>
292           </m:mrow>
293          </m:mtd>
294         </m:mtr>
295        </m:mtable>
296       </xsl:otherwise>
297      </xsl:choose>
298     </xsl:when>
299     <xsl:otherwise>
300      <xsl:apply-imports/>
301     </xsl:otherwise>
302    </xsl:choose>
303   </xsl:otherwise>
304  </xsl:choose>
305 </xsl:template>      
306
307 <xsl:template match = "m:apply[m:card[1]]">
308   <m:mfenced open="|" close="|" stretchy="false">
309     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
310       <xsl:attribute name="xref">
311         <xsl:value-of select="@id"/>
312       </xsl:attribute>
313     </xsl:if>
314   <xsl:apply-templates select="*[2]"/>
315   </m:mfenced>
316 </xsl:template>
317
318
319 <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'))]">
320   <xsl:choose>
321   <xsl:when test="local-name(.) = 'neq'">
322    <xsl:value-of select="'&#8800;'"/>
323   </xsl:when>
324   <xsl:when test="local-name(.) = 'lt'">
325    <xsl:value-of select="'&#60;&#32;'"/>
326   </xsl:when>
327   <xsl:when test="local-name(.) = 'gt'">
328    <xsl:value-of select="'&#62;'"/>
329   </xsl:when>
330   <xsl:when test="local-name(.) = 'leq'">
331    <xsl:value-of select="'&#8804;'"/>
332   </xsl:when>
333   <xsl:when test="local-name(.) = 'geq'">
334    <xsl:value-of select="'&#8805;'"/>
335   </xsl:when>
336   <xsl:otherwise>
337    <xsl:value-of select="'&#61;'"/>
338   </xsl:otherwise>
339   </xsl:choose>       
340 </xsl:template>
341
342
343 </xsl:stylesheet>