]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-tex.xsl
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-tex.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 <!-- TML ===> TeX                                    -->
30 <!-- Example: <tml:i val="hello"/> is transformed to -->
31 <!-- it TeX "rendering" "{\rm hello}"                -->
32
33 <xsl:stylesheet
34      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
35      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
36      xmlns:m="http://www.w3.org/1998/Math/MathML"
37      version="1.0">
38
39   <xsl:output method="text" indent="yes"/>
40
41   <xsl:param name="id" select="/.."/>
42
43   <xsl:template match="/">
44     <xsl:choose>
45       <xsl:when test="$id">
46         <xsl:apply-templates select="descendant::*[@id=$id]"/>
47       </xsl:when>
48       <xsl:otherwise>
49         <xsl:apply-templates select="*"/>
50       </xsl:otherwise>
51     </xsl:choose>
52   </xsl:template>
53
54   <xsl:template match="tml:tex">
55     <xsl:apply-templates select="*"/>
56   </xsl:template>
57
58   <xsl:template match="tml:math">
59     <xsl:choose>
60       <xsl:when test="@display='1'">$$<xsl:apply-templates select="*"/>$$</xsl:when>
61       <xsl:otherwise>$<xsl:apply-templates select="*"/>$</xsl:otherwise>
62     </xsl:choose>
63   </xsl:template>
64
65   <xsl:template match="tml:i">
66     <xsl:choose>
67       <xsl:when test="@name">\<xsl:value-of select="@name"/>
68         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
69       </xsl:when>
70       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
71       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
72     </xsl:choose>
73   </xsl:template>
74
75   <xsl:template match="tml:n">
76     <xsl:choose>
77       <xsl:when test="@name">\<xsl:value-of select="@name"/>
78         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
79       </xsl:when>
80       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
81       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
82     </xsl:choose>
83   </xsl:template>
84
85   <xsl:template match="tml:o">
86     <xsl:choose>
87       <xsl:when test="@name">\<xsl:value-of select="@name"/>
88         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
89       </xsl:when>
90       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
91       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
92     </xsl:choose>
93   </xsl:template>
94
95   <xsl:template match="tml:s">
96     <xsl:text> </xsl:text>
97   </xsl:template>
98
99   <xsl:template match="tml:sb">
100     <xsl:choose>
101       <xsl:when test="@under='1'">
102         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
103       </xsl:when>
104       <xsl:otherwise>
105         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
106       </xsl:otherwise>
107     </xsl:choose>
108   </xsl:template>
109
110   <xsl:template match="tml:sp">
111     <xsl:choose>
112       <xsl:when test="@over='1'">
113         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
114       </xsl:when>
115       <xsl:otherwise>
116         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
117       </xsl:otherwise>
118     </xsl:choose>
119   </xsl:template>
120
121   <xsl:template match="tml:g[@id]">{<xsl:apply-templates select="*"/>}</xsl:template>
122
123   <xsl:template match="tml:g[count(*)&gt;1]">{<xsl:apply-templates select="*"/>}</xsl:template>
124
125   <xsl:template match="tml:g">
126     <xsl:apply-templates select="*"/>
127   </xsl:template>
128
129   <xsl:template match="tml:row">
130     <xsl:apply-templates select="cell"/>\cr </xsl:template>
131
132   <xsl:template match="tml:cell">
133     <xsl:apply-templates select="*"/>
134     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
135   </xsl:template>
136
137 <!--/// CONTROL SEQUENCES ///-->
138
139   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]">
140     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
141     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
142     <xsl:apply-templates select="*[position()&gt;1]"/>
143   </xsl:template>
144
145   <xsl:template match="tml:c">\<xsl:value-of select="@name"/>
146     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
147     <xsl:apply-templates select="*"/>
148   </xsl:template>
149
150 <!--/// CURSOR ///-->
151
152   <xsl:template match="tml:cursor[@val]">
153     <xsl:choose>
154       <xsl:when test="string-length(@val)=0"/>
155       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
156       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
157     </xsl:choose>
158   </xsl:template>
159
160 </xsl:stylesheet>
161