]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mmlnotation.xsl
Bug fixed in binary standard MathML Content operators: the href/xref
[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="*[2]"/>
143       </m:mrow>
144      </m:mtd>
145     </m:mtr>
146     <m:mtr>
147      <m:mtd>
148       <m:mrow>
149        <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
150        <m:mo>
151         <xsl:if test="*[1]/@id">
152          <xsl:attribute name="xref">
153           <xsl:value-of select="*[1]/@id"/>
154          </xsl:attribute>
155         </xsl:if><xsl:value-of select="$symbol"/></m:mo>
156        <xsl:apply-templates select="*[3]"/>
157       </m:mrow>
158      </m:mtd>
159     </m:mtr>
160     <m:mtr>
161      <m:mtd>
162       <m:mrow>
163        <m:mo stretchy="false">)</m:mo>
164       </m:mrow>
165      </m:mtd>
166     </m:mtr>
167    </m:mtable>
168   </xsl:when>
169   <xsl:otherwise>
170    <xsl:apply-imports/>
171   </xsl:otherwise>
172  </xsl:choose>
173 </xsl:template>
174
175 <!-- apply-imports with parenthesis -->
176 <xsl:template match = "m:apply[m:and[1]|m:or[1]
177           |m:intesect[1]|m:union[1]|m:setdiff[1]]">
178  <xsl:variable name="symbol">
179   <xsl:choose>
180    <xsl:when test="m:and[1]">
181     <xsl:value-of select="'&#8743;'"/>
182    </xsl:when>
183    <xsl:when test="m:or[1]">
184     <xsl:value-of select="'&#8744;'"/>
185    </xsl:when>
186    <xsl:when test="m:intersect[1]">
187     <xsl:value-of select="'&#x022C2;'"/>
188    </xsl:when>
189    <xsl:when test="m:union[1]">
190     <xsl:value-of select="'&#x022C3;'"/>
191    </xsl:when>
192    <xsl:when test="m:setdiff[1]">
193     <xsl:value-of select="'&#x02216;'"/>
194    </xsl:when>
195   </xsl:choose>
196  </xsl:variable>
197  <xsl:variable name="charlength">
198   <xsl:apply-templates select="*[1]" mode="charcount"/>
199  </xsl:variable>
200  <xsl:choose>
201   <xsl:when test="$charlength >= $framewidth">
202    <m:mtable align="baseline 1" equalrows="false" columnalign="left">
203     <xsl:if test="@id">
204      <xsl:attribute name="xref">
205       <xsl:value-of select="@id"/>
206      </xsl:attribute>
207     </xsl:if>    
208     <m:mtr>
209      <m:mtd>
210       <m:mrow>
211        <m:mo stretchy="false">(</m:mo>
212        <xsl:apply-templates select="*[position()=2]"/>
213       </m:mrow>
214      </m:mtd>
215     </m:mtr>
216     <xsl:for-each select = "*[position()>2]">
217      <m:mtr>
218       <m:mtd>
219        <m:mrow>
220         <m:mphantom><m:mtext>__</m:mtext></m:mphantom>
221         <m:mo>
222          <xsl:if test="*[1]/@id">
223           <xsl:attribute name="xref">
224            <xsl:value-of select="*[1]/@id"/>
225           </xsl:attribute>
226          </xsl:if><xsl:value-of select="$symbol"/></m:mo>
227         <xsl:apply-templates select="."/>
228        </m:mrow>
229       </m:mtd>
230      </m:mtr>
231     </xsl:for-each>
232     <m:mtr>
233      <m:mtd>
234       <m:mrow>
235        <m:mo stretchy="false">)</m:mo>
236       </m:mrow>
237      </m:mtd>
238     </m:mtr>
239    </m:mtable>
240   </xsl:when>
241   <xsl:otherwise>
242 <!-- Added mfenced because apply-imports doesn't support with-param for 
243      precedence  (XSLT 2.0) -->
244    <m:mfenced separators=" ">
245     <xsl:apply-imports/>
246    </m:mfenced>
247   </xsl:otherwise>
248  </xsl:choose>
249 </xsl:template>
250
251 <xsl:template match = "m:set">
252  <xsl:choose>
253   <xsl:when test="count(child::*) = 0">
254    <m:mi>
255     <xsl:if test="@id">
256      <xsl:attribute name="xref">
257       <xsl:value-of select="@id"/>
258      </xsl:attribute>
259     </xsl:if>&#x02205;</m:mi>
260   </xsl:when>
261   <xsl:otherwise>
262    <xsl:variable name="charlength">
263     <xsl:apply-templates select="*[1]" mode="charcount"/>
264    </xsl:variable>
265    <xsl:choose>
266     <xsl:when test="$charlength >= $framewidth">
267      <xsl:choose>
268       <xsl:when test="name(*[1]) = 'm:bvar'">
269        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
270         <m:mtr>
271          <m:mtd>
272           <m:mrow>
273            <m:mo stretchy="false">
274             <xsl:if test="@id">
275              <xsl:attribute name="xref">
276               <xsl:value-of select="@id"/>
277              </xsl:attribute>
278             </xsl:if>{</m:mo>
279            <xsl:apply-templates select="*[position()=1]"/>
280           </m:mrow>
281          </m:mtd>
282         </m:mtr>
283         <m:mtr>
284          <m:mtd>
285           <m:mrow>
286            <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
287            <m:mo stretchy="false">|</m:mo>
288            <xsl:apply-templates select="m:condition/*[1]"/>
289           </m:mrow>
290          </m:mtd>
291         </m:mtr>
292         <m:mtr>
293          <m:mtd>
294           <m:mrow>
295            <m:mo stretchy="false">
296             <xsl:if test="@id">
297              <xsl:attribute name="xref">
298               <xsl:value-of select="@id"/>
299              </xsl:attribute>
300             </xsl:if>}</m:mo>
301           </m:mrow>
302          </m:mtd>
303         </m:mtr>
304        </m:mtable>
305       </xsl:when>
306       <xsl:otherwise>
307        <m:mtable align="baseline 1" equalrows="false" columnalign="left">
308         <m:mtr>
309          <m:mtd>
310           <m:mrow>
311            <m:mo stretchy="false">
312             <xsl:if test="@id">
313              <xsl:attribute name="xref">
314               <xsl:value-of select="@id"/>
315              </xsl:attribute>
316             </xsl:if>{</m:mo>
317            <xsl:apply-templates select="*[position()=1]"/>
318            <xsl:if test="position() != last()">
319             <mo>,</mo>
320            </xsl:if>
321           </m:mrow>
322          </m:mtd>
323         </m:mtr>
324         <xsl:for-each select = "*[position()>2]">
325          <m:mtr>
326           <m:mtd>
327            <m:mrow>
328             <m:mphantom><m:mtext>{</m:mtext></m:mphantom>
329             <xsl:apply-templates select="."/>
330             <xsl:if test="position() != last()">
331              <mo>,</mo>
332             </xsl:if>
333            </m:mrow>
334           </m:mtd>
335          </m:mtr>
336         </xsl:for-each>
337         <m:mtr>
338          <m:mtd>
339           <m:mrow>
340            <m:mo stretchy="false">
341             <xsl:if test="@id">
342              <xsl:attribute name="xref">
343               <xsl:value-of select="@id"/>
344              </xsl:attribute>
345             </xsl:if>}</m:mo>
346           </m:mrow>
347          </m:mtd>
348         </m:mtr>
349        </m:mtable>
350       </xsl:otherwise>
351      </xsl:choose>
352     </xsl:when>
353     <xsl:otherwise>
354      <xsl:apply-imports/>
355     </xsl:otherwise>
356    </xsl:choose>
357   </xsl:otherwise>
358  </xsl:choose>
359 </xsl:template>      
360
361 <xsl:template match = "m:apply[m:card[1]]">
362   <m:mfenced open="|" close="|" stretchy="false">
363     <xsl:if test="($SEM_SW=$SEM_XREF or $SEM_SW=$SEM_XREF_EXT) and @id">
364       <xsl:attribute name="xref">
365         <xsl:value-of select="@id"/>
366       </xsl:attribute>
367     </xsl:if>
368   <xsl:apply-templates select="*[2]"/>
369   </m:mfenced>
370 </xsl:template>
371
372
373 <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'))]">
374   <xsl:choose>
375   <xsl:when test="local-name(.) = 'neq'">
376    <xsl:value-of select="'&#8800;'"/>
377   </xsl:when>
378   <xsl:when test="local-name(.) = 'lt'">
379    <xsl:value-of select="'&#60;&#32;'"/>
380   </xsl:when>
381   <xsl:when test="local-name(.) = 'gt'">
382    <xsl:value-of select="'&#62;'"/>
383   </xsl:when>
384   <xsl:when test="local-name(.) = 'leq'">
385    <xsl:value-of select="'&#8804;'"/>
386   </xsl:when>
387   <xsl:when test="local-name(.) = 'geq'">
388    <xsl:value-of select="'&#8805;'"/>
389   </xsl:when>
390   <xsl:otherwise>
391    <xsl:value-of select="'&#61;'"/>
392   </xsl:otherwise>
393   </xsl:choose>       
394 </xsl:template>
395
396
397 </xsl:stylesheet>