]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-tex.xsl
* added template for tml:s
[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:s">
92     <xsl:text> </xsl:text>
93   </xsl:template>
94
95   <xsl:template match="tml:sb">
96     <xsl:choose>
97       <xsl:when test="@under='1'">
98         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
99       </xsl:when>
100       <xsl:otherwise>
101         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
102       </xsl:otherwise>
103     </xsl:choose>
104   </xsl:template>
105
106   <xsl:template match="tml:sp">
107     <xsl:choose>
108       <xsl:when test="@over='1'">
109         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
110       </xsl:when>
111       <xsl:otherwise>
112         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
113       </xsl:otherwise>
114     </xsl:choose>
115   </xsl:template>
116
117   <xsl:template match="tml:g[@id]">{<xsl:apply-templates select="*"/>}</xsl:template>
118
119   <xsl:template match="tml:g[count(*)&gt;1]">{<xsl:apply-templates select="*"/>}</xsl:template>
120
121   <xsl:template match="tml:g">
122     <xsl:apply-templates select="*"/>
123   </xsl:template>
124
125   <xsl:template match="tml:row">
126     <xsl:apply-templates select="cell"/>\cr </xsl:template>
127
128   <xsl:template match="tml:cell">
129     <xsl:apply-templates select="*"/>
130     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
131   </xsl:template>
132
133 <!--/// CONTROL SEQUENCES ///-->
134
135   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]">
136     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
137     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
138     <xsl:apply-templates select="*[position()&gt;1]"/>
139   </xsl:template>
140
141   <xsl:template match="tml:c">\<xsl:value-of select="@name"/>
142     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
143     <xsl:apply-templates select="*"/>
144   </xsl:template>
145
146 <!--/// CURSOR ///-->
147
148   <xsl:template match="tml:cursor[@visible='1' and @val]">
149     <xsl:choose>
150       <xsl:when test="string-length(@val)=0"/>
151       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
152       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
153     </xsl:choose>
154   </xsl:template>
155
156 </xsl:stylesheet>
157