]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl
* added license and copyright to every source file
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-mmlp.xsl
1 <?xml version="1.0"?>
2 <!--
3  Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
4                     2003, Paolo Marinelli <pmarinel@cs.unibo.it>.
5
6  This file is part of EdiTeX, an editor of mathematical
7  expressions based on TeX syntax
8  
9  EdiTeX 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  EdiTeX 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 EdiTeX; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  
23  For details, see the EdiTeX World-Wide-Web page,
24  http://helm.cs.unibo.it/editex, or send a mail to
25  <luca.padovani@cs.unibo.it>
26 -->
27 <xsl:stylesheet
28      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
29      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
30      xmlns:m="http://www.w3.org/1998/Math/MathML"
31      exclude-result-prefixes="tml"
32      version="1.0">
33
34   <xsl:output indent="yes"/>
35
36   <xsl:param name="id" select="/.."/>
37
38   <xsl:template match="/">
39     <xsl:choose>
40       <xsl:when test="$id">
41         <xsl:apply-templates select="descendant::*[@id=$id]"/>
42       </xsl:when>
43       <xsl:otherwise>
44         <xsl:apply-templates/>
45       </xsl:otherwise>
46     </xsl:choose>
47   </xsl:template>
48
49   <xsl:template match="tml:math">
50     <m:math>
51       <xsl:if test="@id">
52         <xsl:attribute name="xref">
53           <xsl:value-of select="@id"/>
54         </xsl:attribute>
55       </xsl:if>
56        <xsl:if test="@display='1'">
57         <xsl:attribute name="display">block</xsl:attribute>
58       </xsl:if>
59       <xsl:attribute name="display">block</xsl:attribute>
60       <xsl:apply-templates select="*"/>
61     </m:math>
62   </xsl:template>
63
64   <xsl:template match="tml:i">
65     <m:mi>
66       <xsl:if test="@id">
67         <xsl:attribute name="xref">
68           <xsl:value-of select="@id"/>
69         </xsl:attribute>
70       </xsl:if>
71       <xsl:value-of select="@val"/>
72     </m:mi>
73   </xsl:template>
74
75   <xsl:template match="tml:n">
76     <m:mn>
77       <xsl:if test="@id">
78         <xsl:attribute name="xref">
79           <xsl:value-of select="@id"/>
80         </xsl:attribute>
81       </xsl:if>
82       <xsl:value-of select="@val"/>
83     </m:mn>
84   </xsl:template>
85
86   <xsl:template match="tml:o">
87     <m:mo>
88       <xsl:if test="@id">
89         <xsl:attribute name="xref">
90           <xsl:value-of select="@id"/>
91         </xsl:attribute>
92       </xsl:if>
93       <xsl:value-of select="@val"/>
94     </m:mo>
95   </xsl:template>
96
97   <xsl:template match="tml:o[@val='-']">
98     <m:mo>
99       <xsl:if test="@id">
100         <xsl:attribute name="xref">
101           <xsl:value-of select="@id"/>
102         </xsl:attribute>
103       </xsl:if>
104       &#x2212;
105     </m:mo>
106   </xsl:template>
107
108   <xsl:template match="tml:cursor[@visible='1']">
109     <xsl:choose>
110       <xsl:when test="substring(@val,1,1)='\'">
111         <m:mrow>
112           <xsl:if test="@id">
113             <xsl:attribute name="xref">
114               <xsl:value-of select="@id"/>
115             </xsl:attribute>
116           </xsl:if>
117           <m:mo stretchy="false">&#x2329;</m:mo>
118           <m:mtext mathcolor="blue"><xsl:value-of select="@val"/></m:mtext>
119           <m:mo stretchy="false">&#x232a;</m:mo>
120         </m:mrow>
121       </xsl:when>
122       <xsl:otherwise>
123         <m:mtext mathcolor="blue">
124          <xsl:if test="@id">
125            <xsl:attribute name="xref">
126              <xsl:value-of select="@id"/>
127            </xsl:attribute>
128          </xsl:if><xsl:value-of select="@val"/>I</m:mtext>
129       </xsl:otherwise>
130     </xsl:choose>
131   </xsl:template>
132
133   <xsl:template match="tml:cursor[not(@visible) or @visible='0']">
134   </xsl:template>
135
136   <xsl:template match="tml:sb[@under='1'][*[1]/tml:sp[@over='1']]">
137     <m:munderover>
138       <xsl:if test="@id">
139         <xsl:attribute name="xref">
140           <xsl:value-of select="@id"/>
141         </xsl:attribute>
142       </xsl:if>
143       <xsl:apply-templates select="*[1]/*[1]"/>
144       <xsl:apply-templates select="*[2]"/>
145       <xsl:apply-templates select="*[1]/*[2]"/>
146     </m:munderover>
147   </xsl:template>
148
149   <xsl:template match="tml:sb[@under='1']">
150     <m:munder>
151       <xsl:if test="@id">
152         <xsl:attribute name="xref">
153           <xsl:value-of select="@id"/>
154         </xsl:attribute>
155       </xsl:if>
156       <xsl:apply-templates select="*[1]"/>
157       <xsl:apply-templates select="*[2]"/>
158     </m:munder>
159   </xsl:template>
160
161   <xsl:template match="tml:sb[*[1][self::tml:sp[not(@over) or @over='0']]]">
162     <m:msubsup>
163       <xsl:if test="@id">
164         <xsl:attribute name="xref">
165           <xsl:value-of select="@id"/>
166         </xsl:attribute>
167       </xsl:if>
168       <xsl:apply-templates select="*[1]/*[1]"/>
169       <xsl:apply-templates select="*[2]"/>
170       <xsl:apply-templates select="*[1]/*[2]"/>
171     </m:msubsup>
172   </xsl:template>
173
174   <xsl:template match="tml:sb">
175     <m:msub>
176       <xsl:if test="@id">
177         <xsl:attribute name="xref">
178           <xsl:value-of select="@id"/>
179         </xsl:attribute>
180       </xsl:if>
181       <xsl:apply-templates select="*[1]"/>
182       <xsl:apply-templates select="*[2]"/>
183     </m:msub>
184   </xsl:template>
185
186   <xsl:template match="tml:sp[@over='1'][*[1]/tml:sb[@under='1']]">
187     <m:munderover>
188       <xsl:if test="@id">
189         <xsl:attribute name="xref">
190           <xsl:value-of select="@id"/>
191         </xsl:attribute>
192       </xsl:if>
193       <xsl:apply-templates select="*[1]/*[1]"/>
194       <xsl:apply-templates select="*[1]/*[2]"/>
195       <xsl:apply-templates select="*[2]"/>
196     </m:munderover>
197   </xsl:template>
198
199   <xsl:template match="tml:sp[@over='1']">
200     <m:mover>
201       <xsl:if test="@id">
202         <xsl:attribute name="xref">
203           <xsl:value-of select="@id"/>
204         </xsl:attribute>
205       </xsl:if>
206       <xsl:apply-templates select="*[1]"/>
207       <xsl:apply-templates select="*[2]"/>
208     </m:mover>
209   </xsl:template>
210
211   <xsl:template match="tml:sp[*[1][self::tml:sb[not(@over) or @over='0']]]">
212     <m:msubsup>
213       <xsl:if test="@id">
214         <xsl:attribute name="xref">
215           <xsl:value-of select="@id"/>
216         </xsl:attribute>
217       </xsl:if>
218       <xsl:apply-templates select="*[1]/*[1]"/>
219       <xsl:apply-templates select="*[1]/*[2]"/>
220       <xsl:apply-templates select="*[2]"/>
221     </m:msubsup>
222   </xsl:template>
223
224   <xsl:template match="tml:sp">
225     <m:msup>
226       <xsl:if test="@id">
227         <xsl:attribute name="xref">
228           <xsl:value-of select="@id"/>
229         </xsl:attribute>
230       </xsl:if>
231       <xsl:apply-templates select="*[1]"/>
232       <xsl:apply-templates select="*[2]"/>
233     </m:msup>
234   </xsl:template>
235
236   <xsl:template match="tml:g">
237     <xsl:choose>
238       <xsl:when test="not(@id) and count(*) = 1">
239         <xsl:apply-templates select="*[1]"/>
240       </xsl:when>
241       <xsl:when test="tml:cursor">
242         <m:mstyle mathbackground="#e0e0e0">
243           <xsl:if test="@id">
244             <xsl:attribute name="xref">
245               <xsl:value-of select="@id"/>
246             </xsl:attribute>
247           </xsl:if>
248           <m:mrow>
249             <xsl:apply-templates select="*"/>
250           </m:mrow>
251         </m:mstyle>
252       </xsl:when>
253        <xsl:otherwise>
254         <m:mrow>
255           <xsl:if test="@id">
256             <xsl:attribute name="xref">
257               <xsl:value-of select="@id"/>
258             </xsl:attribute>
259           </xsl:if>
260           <xsl:apply-templates select="*"/>
261         </m:mrow>
262       </xsl:otherwise>
263     </xsl:choose>
264   </xsl:template>
265
266   <xsl:template match="tml:row">
267     <m:mtr>
268       <xsl:apply-templates select="cell"/>
269     </m:mtr>
270   </xsl:template>
271
272   <xsl:template match="tml:cell">
273     <m:mtd>
274       <xsl:apply-templates select="*"/>
275     </m:mtd>
276   </xsl:template>
277
278 <!--/// CONTROL SEQUENCES ///-->
279
280   <xsl:template match="tml:c">
281     <m:mrow>
282       <xsl:if test="@id">
283         <xsl:attribute name="xref">
284           <xsl:value-of select="@id"/>
285         </xsl:attribute>
286       </xsl:if>
287       <m:mtext mathcolor="blue">\<xsl:value-of select="@name"/></m:mtext>
288       <xsl:apply-templates select="*"/>
289     </m:mrow>
290   </xsl:template>
291
292   <xsl:template match="tml:c[@name='fun' and count(*)=3]">
293     <m:mrow>
294       <xsl:if test="@id">
295         <xsl:attribute name="xref">
296           <xsl:value-of select="@id"/>
297         </xsl:attribute>
298       </xsl:if>
299       <m:mo mathcolor="red">&#x03bb;</m:mo>
300       <xsl:apply-templates select="*[1]"/>
301       <m:mo>:</m:mo>
302       <xsl:apply-templates select="*[2]"/>
303       <m:mo>.</m:mo>
304       <xsl:apply-templates select="*[3]"/>
305     </m:mrow>
306   </xsl:template>
307
308   <xsl:template match="tml:c[@name='not'][*[1][self::tml:o]]">
309 <!-- not -->
310     <m:mo>
311       <xsl:if test="@id">
312         <xsl:attribute name="xref">
313           <xsl:value-of select="@id"/>
314         </xsl:attribute>
315       </xsl:if>
316       <xsl:value-of select="*[1]/@val"/>&#x0338;</m:mo>
317   </xsl:template>
318
319   <xsl:template match="tml:c[@name='buildrel']">
320 <!-- buildrel -->
321     <m:mover>
322       <xsl:if test="@id">
323         <xsl:attribute name="xref">
324           <xsl:value-of select="@id"/>
325         </xsl:attribute>
326       </xsl:if>
327       <xsl:apply-templates select="*[2]"/>
328       <xsl:apply-templates select="*[1]"/>
329     </m:mover>
330   </xsl:template>
331
332   <xsl:template match="tml:c[@name='left' or @name='right'][*[1][self::tml:o]]">
333 <!-- left -->
334     <m:mo stretchy="true">
335       <xsl:if test="@id">
336         <xsl:attribute name="xref">
337           <xsl:value-of select="@id"/>
338         </xsl:attribute>
339       </xsl:if>
340       <xsl:value-of select="*[1]/@val"/>
341     </m:mo>
342   </xsl:template>
343
344   <xsl:template match="tml:c[@name='bigl' or @name='bigr' or @name='bigm' or @name='big'][*[1][self::tml:o]]">
345 <!-- bigl -->
346     <m:mo stretchy="true" minsize="8.5pt">
347       <xsl:if test="@id">
348         <xsl:attribute name="xref">
349           <xsl:value-of select="@id"/>
350         </xsl:attribute>
351       </xsl:if>
352       <xsl:value-of select="*[1]/@val"/>
353     </m:mo>
354   </xsl:template>
355
356   <xsl:template match="tml:c[@name='Bigl' or @name='Bigr' or @name='Bigm'][*[1][self::tml:o]]">
357 <!-- Bigl -->
358     <m:mo stretchy="true" minsize="11.5pt">
359       <xsl:if test="@id">
360         <xsl:attribute name="xref">
361           <xsl:value-of select="@id"/>
362         </xsl:attribute>
363       </xsl:if>
364       <xsl:value-of select="*[1]/@val"/>
365     </m:mo>
366   </xsl:template>
367
368   <xsl:template match="tml:c[@name='biggl' or @name='biggr' or @name='biggm'][*[1][self::tml:o]]">
369 <!-- biggl -->
370     <m:mo stretchy="true" minsize="14.5pt">
371       <xsl:if test="@id">
372         <xsl:attribute name="xref">
373           <xsl:value-of select="@id"/>
374         </xsl:attribute>
375       </xsl:if>
376       <xsl:value-of select="*[1]/@val"/>
377     </m:mo>
378   </xsl:template>
379
380   <xsl:template match="tml:c[@name='Biggl' or @name='Biggr' or @name='Biggm'][*[1][self::tml:o]]">
381 <!-- biggl -->
382     <m:mo stretchy="true" minsize="17.5pt">
383       <xsl:if test="@id">
384         <xsl:attribute name="xref">
385           <xsl:value-of select="@id"/>
386         </xsl:attribute>
387       </xsl:if>
388       <xsl:value-of select="*[1]/@val"/>
389     </m:mo>
390   </xsl:template>
391
392   <xsl:template match="tml:c[@name='hat']">
393 <!-- hat -->
394     <m:mover accent="true">
395       <xsl:if test="@id">
396         <xsl:attribute name="xref">
397           <xsl:value-of select="@id"/>
398         </xsl:attribute>
399       </xsl:if>
400       <xsl:apply-templates select="*[1]"/>
401       <m:mo>&#x0302;</m:mo>
402     </m:mover>
403   </xsl:template>
404
405   <xsl:template match="tml:c[@name='widehat']">
406 <!-- widehat -->
407     <m:mover accent="false">
408       <xsl:if test="@id">
409         <xsl:attribute name="xref">
410           <xsl:value-of select="@id"/>
411         </xsl:attribute>
412       </xsl:if>
413       <xsl:apply-templates select="*[1]"/>
414       <m:mo stretchy="true">&#x0302;</m:mo>
415     </m:mover>
416   </xsl:template>
417
418   <xsl:template match="tml:c[@name='check']">
419 <!-- check -->
420     <m:mover accent="true">
421       <xsl:if test="@id">
422         <xsl:attribute name="xref">
423           <xsl:value-of select="@id"/>
424         </xsl:attribute>
425       </xsl:if>
426       <xsl:apply-templates select="*[1]"/>
427       <m:mo>&#x030c;</m:mo>
428     </m:mover>
429   </xsl:template>
430
431   <xsl:template match="tml:c[@name='tilde']">
432 <!-- tilde -->
433     <m:mover accent="true">
434       <xsl:if test="@id">
435         <xsl:attribute name="xref">
436           <xsl:value-of select="@id"/>
437         </xsl:attribute>
438       </xsl:if>
439       <xsl:apply-templates select="*[1]"/>
440       <m:mo>&#x0303;</m:mo>
441     </m:mover>
442   </xsl:template>
443
444   <xsl:template match="tml:c[@name='widetilde']">
445 <!-- widetilde -->
446     <m:mover>
447       <xsl:if test="@id">
448         <xsl:attribute name="xref">
449           <xsl:value-of select="@id"/>
450         </xsl:attribute>
451       </xsl:if>
452       <xsl:apply-templates select="*[1]"/>
453       <m:mo stretchy="true">&#x0303;</m:mo>
454     </m:mover>>
455   </xsl:template>
456
457   <xsl:template match="tml:c[@name='acute']">
458 <!-- acute -->
459     <m:mover accent="true">
460       <xsl:if test="@id">
461         <xsl:attribute name="xref">
462           <xsl:value-of select="@id"/>
463         </xsl:attribute>
464       </xsl:if>
465       <xsl:apply-templates select="*[1]"/>
466       <m:mo>&#x0301;</m:mo>
467     </m:mover>
468   </xsl:template>
469
470   <xsl:template match="tml:c[@name='grave']">
471 <!-- grave -->
472     <m:mover accent="true">
473       <xsl:if test="@id">
474         <xsl:attribute name="xref">
475           <xsl:value-of select="@id"/>
476         </xsl:attribute>
477       </xsl:if>
478       <xsl:apply-templates select="*[1]"/>
479       <m:mo>&#x0300;</m:mo>
480     </m:mover>>
481   </xsl:template>
482
483   <xsl:template match="tml:c[@name='dot']">
484 <!-- dot -->
485     <m:mover accent="true">
486       <xsl:if test="@id">
487         <xsl:attribute name="xref">
488           <xsl:value-of select="@id"/>
489         </xsl:attribute>
490       </xsl:if>
491       <xsl:apply-templates select="*[1]"/>
492       <m:mo>&#x0307;</m:mo>
493     </m:mover>
494   </xsl:template>
495
496   <xsl:template match="tml:c[@name='ddot']">
497 <!-- ddot -->
498     <m:mover accent="true">
499       <xsl:if test="@id">
500         <xsl:attribute name="xref">
501           <xsl:value-of select="@id"/>
502         </xsl:attribute>
503       </xsl:if>
504       <xsl:apply-templates select="*[1]"/>
505       <m:mo>&#x0308;</m:mo>
506     </m:mover>
507   </xsl:template>
508
509   <xsl:template match="tml:c[@name='breve']">
510 <!-- breve -->
511     <m:mover accent="true">
512       <xsl:if test="@id">
513         <xsl:attribute name="xref">
514           <xsl:value-of select="@id"/>
515         </xsl:attribute>
516       </xsl:if>
517       <xsl:apply-templates select="*[1]"/>
518       <m:mo>&#x0306;</m:mo>
519     </m:mover>
520   </xsl:template>
521
522   <xsl:template match="tml:c[@name='bar']">
523 <!-- bar -->
524     <m:mover accent="true">
525       <xsl:if test="@id">
526         <xsl:attribute name="xref">
527           <xsl:value-of select="@id"/>
528         </xsl:attribute>
529       </xsl:if>
530       <xsl:apply-templates select="*[1]"/>
531       <m:mo>&#x0304;</m:mo>
532     </m:mover>
533   </xsl:template>
534
535   <xsl:template match="tml:c[@name='vec']">
536 <!-- vec -->
537     <m:mover accent="true">
538       <xsl:if test="@id">
539         <xsl:attribute name="xref">
540           <xsl:value-of select="@id"/>
541         </xsl:attribute>
542       </xsl:if>
543       <xsl:apply-templates select="*[1]"/>
544       <m:mo>&#x20d7;</m:mo>
545     </m:mover>
546   </xsl:template>
547
548   <xsl:template match="tml:c[@name='overline']">
549 <!-- overline -->
550     <m:mover>
551       <xsl:if test="@id">
552         <xsl:attribute name="xref">
553           <xsl:value-of select="@id"/>
554         </xsl:attribute>
555       </xsl:if>
556       <xsl:apply-templates select="*[1]"/>
557       <m:mo stretchy="true">&#x0305;</m:mo>
558     </m:mover>
559   </xsl:template>
560
561   <xsl:template match="tml:c[@name='underline']">
562 <!-- underline -->
563     <m:munder>
564       <xsl:if test="@id">
565         <xsl:attribute name="xref">
566           <xsl:value-of select="@id"/>
567         </xsl:attribute>
568       </xsl:if>
569       <xsl:apply-templates select="*[1]"/>
570       <m:mo stretchy="true">&#x0332;</m:mo>
571     </m:munder>
572   </xsl:template>
573
574   <xsl:template match="tml:c[@name='sqrt']">
575 <!-- sqrt -->
576     <m:msqrt>
577       <xsl:if test="@id">
578         <xsl:attribute name="xref">
579           <xsl:value-of select="@id"/>
580         </xsl:attribute>
581       </xsl:if>
582       <xsl:apply-templates select="*"/>
583     </m:msqrt>
584   </xsl:template>
585
586   <xsl:template match="tml:c[@name='root']">
587 <!-- root -->
588     <m:mroot>
589       <xsl:if test="@id">
590         <xsl:attribute name="xref">
591           <xsl:value-of select="@id"/>
592         </xsl:attribute>
593       </xsl:if>
594       <xsl:choose>
595         <xsl:when test="count(*) &lt; 2">
596           <m:mrow/>
597           <xsl:apply-templates select="*[1]"/>
598         </xsl:when>
599         <xsl:otherwise>
600           <xsl:apply-templates select="*[2]"/>
601           <xsl:apply-templates select="*[1]"/>
602         </xsl:otherwise>
603       </xsl:choose>
604     </m:mroot>
605   </xsl:template>
606
607   <xsl:template match="tml:c[@name='frac']">
608 <!-- frac -->
609     <m:mfrac>
610       <xsl:if test="@id">
611         <xsl:attribute name="xref">
612           <xsl:value-of select="@id"/>
613         </xsl:attribute>
614       </xsl:if>
615       <xsl:apply-templates select="*[1]"/>
616       <xsl:apply-templates select="*[2]"/>
617     </m:mfrac>
618   </xsl:template>
619
620   <xsl:template match="tml:c[@name='over']">
621 <!-- over -->
622     <m:mfrac>
623       <xsl:if test="@id">
624         <xsl:attribute name="xref">
625           <xsl:value-of select="@id"/>
626         </xsl:attribute>
627       </xsl:if>
628       <xsl:apply-templates select="*[1]"/>
629       <xsl:apply-templates select="*[2]"/>
630     </m:mfrac>
631   </xsl:template>
632
633   <xsl:template match="tml:c[@name='atop']">
634 <!-- atop -->
635     <m:mfrac linethickness="0">
636       <xsl:if test="@id">
637         <xsl:attribute name="xref">
638           <xsl:value-of select="@id"/>
639         </xsl:attribute>
640       </xsl:if>
641       <xsl:apply-templates select="*[1]"/>
642       <xsl:apply-templates select="*[2]"/>
643     </m:mfrac>
644   </xsl:template>
645
646   <xsl:template match="tml:c[@name='choose']">
647 <!-- choose -->
648     <m:mrow>
649       <xsl:if test="@id">
650         <xsl:attribute name="xref">
651           <xsl:value-of select="@id"/>
652         </xsl:attribute>
653       </xsl:if>
654       <m:mo stretchy="true">(</m:mo>
655       <m:mfrac linethickness="0">
656         <xsl:apply-templates select="*[1]"/>
657         <xsl:apply-templates select="*[2]"/>
658       </m:mfrac>
659       <m:mo stretchy="true">)</m:mo>
660     </m:mrow>
661   </xsl:template>
662
663   <xsl:template match="tml:c[@name='brace']">
664 <!-- brace -->
665     <m:mrow>
666       <xsl:if test="@id">
667         <xsl:attribute name="xref">
668           <xsl:value-of select="@id"/>
669         </xsl:attribute>
670       </xsl:if>
671       <m:mo stretchy="true">{</m:mo>
672       <m:mfrac linethickness="0">
673         <xsl:apply-templates select="*[1]"/>
674         <xsl:apply-templates select="*[2]"/>
675       </m:mfrac>
676       <m:mo stretchy="true">}</m:mo>
677     </m:mrow>
678   </xsl:template>
679
680   <xsl:template match="tml:c[@name='brack']">
681 <!-- brack -->
682     <m:mrow>
683       <xsl:if test="@id">
684         <xsl:attribute name="xref">
685           <xsl:value-of select="@id"/>
686         </xsl:attribute>
687       </xsl:if>
688       <m:mo stretchy="true">[</m:mo>
689       <m:mfrac linethickness="0">
690         <xsl:apply-templates select="*[1]"/>
691         <xsl:apply-templates select="*[2]"/>
692       </m:mfrac>
693       <m:mo stretchy="true">]</m:mo>
694     </m:mrow>
695   </xsl:template>
696
697   <xsl:template match="tml:c[@name='displaystyle']">
698 <!-- displaystyle -->
699     <m:mstyle displaystyle="true">
700       <xsl:if test="@id">
701         <xsl:attribute name="xref">
702           <xsl:value-of select="@id"/>
703         </xsl:attribute>
704       </xsl:if>
705       <xsl:apply-templates select="*[1]"/>
706     </m:mstyle>
707   </xsl:template>
708
709   <xsl:template match="tml:c[@name='textstyle']">
710 <!-- textstyle -->
711     <m:mstyle scriptlevel="0">
712       <xsl:if test="@id">
713         <xsl:attribute name="xref">
714           <xsl:value-of select="@id"/>
715         </xsl:attribute>
716       </xsl:if>
717       <xsl:apply-templates select="*[1]"/>
718       <xsl:if test="tml:g/tml:cursor[@visible='1']">
719         <m:msub>
720           <m:mtext mathcolor="#808080">}</m:mtext>
721           <m:mtext><xsl:value-of select="@name"/></m:mtext>
722         </m:msub>
723       </xsl:if>
724     </m:mstyle>
725   </xsl:template>
726
727   <xsl:template match="tml:c[@name='scriptstyle']">
728 <!-- scriptstyle -->
729     <m:mstyle scriptlevel="1">
730       <xsl:if test="@id">
731         <xsl:attribute name="xref">
732           <xsl:value-of select="@id"/>
733         </xsl:attribute>
734       </xsl:if>
735       <xsl:apply-templates select="*[1]"/>
736     </m:mstyle>
737   </xsl:template>
738
739   <xsl:template match="tml:c[@name='scriptscriptstyle']">
740 <!-- scriptscriptstyle -->
741     <m:mstyle scriptlevel="2">
742       <xsl:if test="@id">
743         <xsl:attribute name="xref">
744           <xsl:value-of select="@id"/>
745         </xsl:attribute>
746       </xsl:if>
747       <xsl:apply-templates select="*[1]"/>
748     </m:mstyle>
749   </xsl:template>
750
751   <xsl:template match="tml:c[@name='pmod']">
752 <!-- pmod -->
753     <m:mrow>
754       <xsl:if test="@id">
755         <xsl:attribute name="xref">
756           <xsl:value-of select="@id"/>
757         </xsl:attribute>
758       </xsl:if>
759       <m:mo>(</m:mo>
760       <m:mrow>
761         <m:mo>mod</m:mo>
762         <xsl:apply-templates select="*[1]"/>
763       </m:mrow>
764       <m:mo>)</m:mo>
765     </m:mrow>
766   </xsl:template>
767
768   <xsl:template match="tml:c[@name='rm']">
769 <!-- rm -->
770     <m:mstyle mathvariant="normal">
771       <xsl:if test="@id">
772         <xsl:attribute name="xref">
773           <xsl:value-of select="@id"/>
774         </xsl:attribute>
775       </xsl:if>
776       <xsl:apply-templates select="*[1]"/>
777     </m:mstyle>
778   </xsl:template>
779
780   <xsl:template match="tml:c[@name='bf']">
781 <!-- bf -->
782     <m:mstyle mathvariant="bold">
783       <xsl:if test="@id">
784         <xsl:attribute name="xref">
785           <xsl:value-of select="@id"/>
786         </xsl:attribute>
787       </xsl:if>
788       <xsl:apply-templates select="*[1]"/>
789     </m:mstyle>
790   </xsl:template>
791
792   <xsl:template match="tml:c[@name='tt']">
793 <!-- tt -->
794     <m:mstyle mathvariant="monospace">
795       <xsl:if test="@id">
796         <xsl:attribute name="xref">
797           <xsl:value-of select="@id"/>
798         </xsl:attribute>
799       </xsl:if>
800       <xsl:apply-templates select="*[1]"/>
801     </m:mstyle>
802   </xsl:template>
803
804   <xsl:template match="tml:c[@name='sl']">
805 <!-- sl -->
806     <m:mstyle mathvariant="italic">
807       <xsl:if test="@id">
808         <xsl:attribute name="xref">
809           <xsl:value-of select="@id"/>
810         </xsl:attribute>
811       </xsl:if>
812       <xsl:apply-templates select="*[1]"/>
813     </m:mstyle>
814   </xsl:template>
815
816   <xsl:template match="tml:c[@name='it']">
817 <!-- it -->
818     <m:mstyle mathvariant="italic">
819       <xsl:if test="@id">
820         <xsl:attribute name="xref">
821           <xsl:value-of select="@id"/>
822         </xsl:attribute>
823       </xsl:if>
824       <xsl:apply-templates select="*[1]"/>
825     </m:mstyle>
826   </xsl:template>
827
828   <xsl:template match="tml:c[@name=',']">
829 <!-- , -->
830     <m:mspace width="thinmathspace">
831       <xsl:if test="@id">
832         <xsl:attribute name="xref">
833           <xsl:value-of select="@id"/>
834         </xsl:attribute>
835       </xsl:if>
836     </m:mspace>
837   </xsl:template>
838
839   <xsl:template match="tml:c[@name='&gt;']">
840 <!-- > -->
841     <m:mspace width="mediummathspace">
842       <xsl:if test="@id">
843         <xsl:attribute name="xref">
844           <xsl:value-of select="@id"/>
845         </xsl:attribute>
846       </xsl:if>
847     </m:mspace>
848   </xsl:template>
849
850   <xsl:template match="tml:c[@name=';']">
851 <!-- ; -->
852     <m:mspace width="thickmathspace">
853       <xsl:if test="@id">
854         <xsl:attribute name="xref">
855           <xsl:value-of select="@id"/>
856         </xsl:attribute>
857       </xsl:if>
858     </m:mspace>
859   </xsl:template>
860
861   <xsl:template match="tml:c[@name='!']">
862 <!-- ! -->
863     <m:mspace width="-0.166667em">
864       <xsl:if test="@id">
865         <xsl:attribute name="xref">
866           <xsl:value-of select="@id"/>
867         </xsl:attribute>
868       </xsl:if>
869     </m:mspace>
870   </xsl:template>
871
872   <xsl:template name="table-content">
873       <xsl:choose>
874         <xsl:when test="tml:row">
875           <xsl:apply-templates select="tml:row"/>
876         </xsl:when>
877         <xsl:otherwise>
878           <m:mtr>
879             <m:mtd>
880               <xsl:apply-templates select="*"/>
881             </m:mtd>
882           </m:mtr>
883         </xsl:otherwise>
884       </xsl:choose>
885   </xsl:template>
886
887   <xsl:template match="tml:c[@name='matrix']">
888 <!-- matrix -->
889     <m:mtable>
890       <xsl:if test="@id">
891         <xsl:attribute name="xref">
892           <xsl:value-of select="@id"/>
893         </xsl:attribute>
894       </xsl:if>
895       <xsl:call-template name="table-content"/>
896     </m:mtable>
897   </xsl:template>
898
899   <xsl:template match="tml:row">
900     <m:mtr>
901       <xsl:apply-templates select="tml:cell"/>
902     </m:mtr>
903   </xsl:template>
904
905   <xsl:template match="tml:cell">
906     <m:mtd>
907       <xsl:apply-templates select="*"/>
908     </m:mtd>
909   </xsl:template>
910
911   <xsl:template match="tml:c[@name='pmatrix']">
912 <!-- pmatrix -->
913     <m:mrow>
914       <xsl:if test="@id">
915         <xsl:attribute name="xref">
916           <xsl:value-of select="@id"/>
917         </xsl:attribute>
918       </xsl:if>
919       <m:mo stretchy="true">(</m:mo>
920       <m:mtable>
921         <xsl:call-template name="table-content"/>
922       </m:mtable>
923       <m:mo stretchy="true">)</m:mo>
924     </m:mrow>
925   </xsl:template>
926
927   <xsl:template match="tml:c[@name='bordermatrix']">
928 <!-- bordermatrix -->
929     <m:mtable>
930       <xsl:if test="@id">
931         <xsl:attribute name="xref">
932           <xsl:value-of select="@id"/>
933         </xsl:attribute>
934       </xsl:if>
935       <m:mtr>
936         <xsl:apply-templates select="tml:row[1]/tml:cell[1]"/>
937         <m:mtd/>
938         <xsl:apply-templates select="tml:row[1]/tml:cell[position() &gt; 1]"/>
939         <m:mtd/>
940       </m:mtr>
941       <xsl:for-each select="tml:row[position() &gt; 1]">
942         <m:mtr>
943           <xsl:apply-templates select="tml:cell[1]"/>
944           <xsl:if test="position() = 1">
945             <m:mtd rowspan="{count(../tml:row) - 1}">
946               <m:mo stretchy="true">(</m:mo>
947             </m:mtd>
948           </xsl:if>
949           <xsl:apply-templates select="tml:cell[position() &gt; 1]"/>
950           <xsl:if test="position() = 1">
951             <m:mtd rowspan="{count(../tml:row) - 1}">
952               <m:mo stretchy="true">)</m:mo>
953             </m:mtd>
954           </xsl:if>         
955         </m:mtr>
956       </xsl:for-each>      
957     </m:mtable>
958   </xsl:template>
959
960   <xsl:template match="tml:c[@name='overbrace']">
961 <!-- overbrace -->
962     <m:mover>
963       <xsl:if test="@id">
964         <xsl:attribute name="xref">
965           <xsl:value-of select="@id"/>
966         </xsl:attribute>
967       </xsl:if>
968       <xsl:apply-templates select="*[1]"/>
969       <m:mo stretchy="true">????</m:mo>
970     </m:mover>>
971   </xsl:template>
972
973   <xsl:template match="tml:c[@name='underbrace']">
974 <!-- underbrace -->
975     <m:munder>
976       <xsl:if test="@id">
977         <xsl:attribute name="xref">
978           <xsl:value-of select="@id"/>
979         </xsl:attribute>
980       </xsl:if>
981       <xsl:apply-templates select="*[1]"/>
982       <m:mo stretchy="true">????</m:mo>
983     </m:munder>
984   </xsl:template>
985
986   <xsl:template match="tml:c[@name='cases']">
987 <!-- cases -->
988     <m:mrow>
989       <xsl:if test="@id">
990         <xsl:attribute name="xref">
991           <xsl:value-of select="@id"/>
992         </xsl:attribute>
993       </xsl:if>
994       <m:mo stretchy="true">{</m:mo>
995       <m:mtable>
996         <xsl:call-template name="table-content"/>
997       </m:mtable>
998     </m:mrow>
999   </xsl:template>
1000
1001   <xsl:template match="tml:c[@name='red']">
1002 <!-- red  -->
1003     <m:mstyle mathcolor="red">
1004       <xsl:if test="@id">
1005         <xsl:attribute name="xref">
1006           <xsl:value-of select="@id"/>
1007         </xsl:attribute>
1008         <xsl:apply-templates/>
1009       </xsl:if>
1010     </m:mstyle>
1011   </xsl:template>
1012
1013   <xsl:template match="tml:c[@name='green']">
1014 <!-- green  -->
1015     <m:mstyle mathcolor="green">
1016       <xsl:if test="@id">
1017         <xsl:attribute name="xref">
1018           <xsl:value-of select="@id"/>
1019         </xsl:attribute>
1020         <xsl:apply-templates/>
1021       </xsl:if>
1022     </m:mstyle>
1023   </xsl:template>
1024
1025   <xsl:template match="tml:c[@name='duedelim']">
1026 <!-- duedelim  -->
1027     <m:mfrac>
1028       <xsl:if test="@id">
1029         <xsl:attribute name="xref">
1030           <xsl:value-of select="@id"/>
1031         </xsl:attribute>
1032       </xsl:if>
1033       <xsl:apply-templates select="*[1]"/>
1034       <xsl:apply-templates select="*[2]"/>
1035     </m:mfrac>
1036   </xsl:template>
1037
1038   <xsl:template match="tml:c[@name='space']">
1039     <m:mspace width="veryverythickmathspace">
1040     </m:mspace>
1041   </xsl:template>
1042
1043 </xsl:stylesheet>