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