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