]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-mmlp.xsl
index 69de8c52e38531b7d96f4bd4b48946b620530066..73d2ab049b9fea0eb85fa83f8ca285c6e021e1cd 100644 (file)
@@ -1,8 +1,36 @@
 <?xml version="1.0"?>
+
+<!--
+ This file is part of EdiTeX, an editor of mathematical
+ expressions based on TeX syntax.
+ Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
+                    2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+ For more information, please visit the project's home page
+ http://helm.cs.unibo.it/editex/
+ or send an email to <lpadovan@cs.unibo.it>
+-->
+
 <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
      xmlns:m="http://www.w3.org/1998/Math/MathML"
+     exclude-result-prefixes="tml"
      version="1.0">
 
   <xsl:output indent="yes"/>
@@ -10,6 +38,7 @@
   <xsl:param name="id" select="/.."/>
 
   <xsl:template match="/">
+   <wrapper>
     <xsl:choose>
       <xsl:when test="$id">
         <xsl:apply-templates select="descendant::*[@id=$id]"/>
         <xsl:apply-templates/>
       </xsl:otherwise>
     </xsl:choose>
+   </wrapper>
+  </xsl:template>
+
+  <xsl:template match="tml:tex[not(tml:math)]">
+    <!-- This is an empty TeX document. We generate the corresponding  -->
+    <!-- empty MathML document.                                        -->
   </xsl:template>
 
   <xsl:template match="tml:math">
-    <m:math>
-      <xsl:if test="@id">
-        <xsl:attribute name="xref">
-          <xsl:value-of select="@id"/>
-        </xsl:attribute>
-      </xsl:if>
-       <xsl:if test="@display='1'">
-        <xsl:attribute name="display">block</xsl:attribute>
-      </xsl:if>
-      <xsl:attribute name="display">block</xsl:attribute>
-      <xsl:apply-templates select="*"/>
-    </m:math>
+    <m:mstyle mathvariant="normal">
+     <xsl:if test="@id">
+       <xsl:attribute name="xref">
+         <xsl:value-of select="@id"/>
+       </xsl:attribute>
+     </xsl:if>
+      <xsl:if test="@display='1'">
+       <xsl:attribute name="display">block</xsl:attribute>
+     </xsl:if>
+     <xsl:attribute name="display">block</xsl:attribute>
+     <xsl:apply-templates select="*"/>
+    </m:mstyle>
   </xsl:template>
 
   <xsl:template match="tml:i">
     </m:mo>
   </xsl:template>
 
+  <xsl:template match="tml:s">
+<!-- this template is used only for testing purpose and should not be here-->
+    <m:mspace width="veryverythickmathspace">
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+          <xsl:value-of select="@id"/>
+        </xsl:attribute>
+      </xsl:if>
+    </m:mspace>
+  </xsl:template>
+
+<!--
+  <xsl:template name="cursor">
+    <xsl:choose>
+      <xsl:when test="contains(@val, '\')">
+        <m:mrow>
+         <xsl:if test="@id">
+           <xsl:attribute name="xref">
+             <xsl:value-of select="@id"/>
+           </xsl:attribute>
+         </xsl:if>
+         <xsl:if test="substring-before(@val, '\')">
+            <m:mtext><xsl:value-of select="substring-before(@val, '\')"/></m:mtext>
+         </xsl:if>
+          <m:mo stretchy="false">&#x2329;</m:mo>
+          <m:mtext mathcolor="blue"><xsl:value-of select="concat('\', substring-after(@val, '\'))"/></m:mtext>
+          <m:mo stretchy="false">&#x232a;</m:mo>
+       </m:mrow>
+      </xsl:when>
+      <xsl:when test="string-length(@val)>=1">
+        <m:mrow>
+         <xsl:if test="@id">
+           <xsl:attribute name="xref">
+             <xsl:value-of select="@id"/>
+           </xsl:attribute>
+         </xsl:if>
+         <xsl:choose>
+           <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
+              <m:mn>
+               <xsl:value-of select="@val"/>
+             </m:mn>
+           </xsl:when>
+           <xsl:otherwise>
+             <m:mi>
+               <xsl:value-of select="@val"/>
+             </m:mi>
+           </xsl:otherwise>
+         </xsl:choose>
+         <m:mtext mathcolor="blue">I</m:mtext>
+       </m:mrow>
+      </xsl:when>
+      <xsl:otherwise>
+        <m:mtext mathcolor="blue">
+         <xsl:if test="@id">
+           <xsl:attribute name="xref">
+             <xsl:value-of select="@id"/>
+           </xsl:attribute>
+         </xsl:if>I</m:mtext>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  -->
+
+  <xsl:template match="tml:o[@val='-']">
+    <m:mo>
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+          <xsl:value-of select="@id"/>
+        </xsl:attribute>
+      </xsl:if>
+      &#x2212;
+    </m:mo>
+  </xsl:template>
+
   <xsl:template match="tml:cursor">
     <xsl:choose>
       <xsl:when test="substring(@val,1,1)='\'">
           <m:mo stretchy="false">&#x232a;</m:mo>
         </m:mrow>
       </xsl:when>
+      <xsl:when test="string-length(@val)>=1">
+        <m:mrow>
+         <xsl:if test="@id">
+           <xsl:attribute name="xref">
+             <xsl:value-of select="@id"/>
+           </xsl:attribute>
+         </xsl:if>
+         <xsl:choose>
+           <xsl:when test="contains('0123456789', substring(@val, 1, 1))">
+              <m:mn>
+               <xsl:value-of select="@val"/>
+             </m:mn>
+           </xsl:when>
+           <xsl:otherwise>
+             <m:mi>
+               <xsl:value-of select="@val"/>
+             </m:mi>
+           </xsl:otherwise>
+         </xsl:choose>
+         <xsl:if test="@visible='1'">
+          <m:mtext mathcolor="blue">I</m:mtext>
+         </xsl:if>
+       </m:mrow>
+      </xsl:when>
       <xsl:otherwise>
-        <m:mtext mathcolor="blue">
+       <xsl:if test="@visible='1'">
+         <m:mtext mathcolor="blue">
           <xsl:if test="@id">
             <xsl:attribute name="xref">
               <xsl:value-of select="@id"/>
             </xsl:attribute>
           </xsl:if>
-         <xsl:value-of select="@val"/>
-       </m:mtext>
+         <xsl:text>I</xsl:text>
+        </m:mtext>
+       </xsl:if>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
           <xsl:value-of select="@id"/>
         </xsl:attribute>
       </xsl:if>
-      <xsl:apply-templates select="*[2]"/>
-      <xsl:apply-templates select="*[1]"/>
+      <xsl:choose>
+        <xsl:when test="count(*) &lt; 2">
+         <m:mrow/>
+         <xsl:apply-templates select="*[1]"/>
+       </xsl:when>
+       <xsl:otherwise>
+          <xsl:apply-templates select="*[2]"/>
+          <xsl:apply-templates select="*[1]"/>
+       </xsl:otherwise>
+      </xsl:choose>
     </m:mroot>
   </xsl:template>
 
         </xsl:attribute>
       </xsl:if>
       <xsl:apply-templates select="*[1]"/>
+      <xsl:if test="tml:g/tml:cursor[@visible='1']">
+        <m:msub>
+          <m:mtext mathcolor="#808080">}</m:mtext>
+         <m:mtext><xsl:value-of select="@name"/></m:mtext>
+        </m:msub>
+      </xsl:if>
     </m:mstyle>
   </xsl:template>
 
     </m:mstyle>
   </xsl:template>
 
+  <xsl:template match="tml:c[@name='_']">
+<!-- _ -->
+    <m:mi>
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+          <xsl:value-of select="@id"/>
+        </xsl:attribute>
+      </xsl:if>
+      <xsl:text>_</xsl:text>
+    </m:mi>
+  </xsl:template>
+
   <xsl:template match="tml:c[@name=',']">
 <!-- , -->
     <m:mspace width="thinmathspace">
     </m:mrow>
   </xsl:template>
 
+  <xsl:template match="tml:c[@name='red']">
+<!-- red  -->
+    <m:mstyle mathcolor="red">
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+         <xsl:value-of select="@id"/>
+       </xsl:attribute>
+       <xsl:apply-templates/>
+      </xsl:if>
+    </m:mstyle>
+  </xsl:template>
+
+  <xsl:template match="tml:c[@name='green']">
+<!-- green  -->
+    <m:mstyle mathcolor="green">
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+         <xsl:value-of select="@id"/>
+       </xsl:attribute>
+       <xsl:apply-templates/>
+      </xsl:if>
+    </m:mstyle>
+  </xsl:template>
+
+  <xsl:template match="tml:c[@name='duedelim']">
+<!-- duedelim  -->
+    <m:mfrac>
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+          <xsl:value-of select="@id"/>
+        </xsl:attribute>
+      </xsl:if>
+      <xsl:apply-templates select="*[1]"/>
+      <xsl:apply-templates select="*[2]"/>
+    </m:mfrac>
+  </xsl:template>
+
+  <xsl:template match="tml:c[@name='nodeside']">
+<!-- nodeside  -->
+    <m:mfrac>
+      <xsl:if test="@id">
+        <xsl:attribute name="xref">
+          <xsl:value-of select="@id"/>
+        </xsl:attribute>
+      </xsl:if>
+      <xsl:apply-templates select="*[1]"/>
+      <xsl:apply-templates select="*[2]"/>
+    </m:mfrac>
+  </xsl:template>
+
 </xsl:stylesheet>