]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-litex.xsl
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-litex.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 + Long Identifiers                                -->
30 <!-- Example: <tml:i val="hello"/> is transformed simply to "hello" -->
31 <!-- and not to its 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:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
71     </xsl:choose>
72   </xsl:template>
73
74   <xsl:template match="tml:n">
75     <xsl:choose>
76       <xsl:when test="@name">\<xsl:value-of select="@name"/>
77         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
78       </xsl:when>
79       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
80     </xsl:choose>
81   </xsl:template>
82
83   <xsl:template match="tml:o">
84     <xsl:choose>
85       <xsl:when test="@name">\<xsl:value-of select="@name"/>
86         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
87       </xsl:when>
88       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
89       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
90     </xsl:choose>
91   </xsl:template>
92
93   <xsl:template match="tml:s">
94     <xsl:text> </xsl:text>
95   </xsl:template>
96
97   <xsl:template match="tml:sb">
98     <xsl:choose>
99       <xsl:when test="@under='1'">
100         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
101       </xsl:when>
102       <xsl:otherwise>
103         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
104       </xsl:otherwise>
105     </xsl:choose>
106   </xsl:template>
107
108   <xsl:template match="tml:sp">
109     <xsl:choose>
110       <xsl:when test="@over='1'">
111         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
112       </xsl:when>
113       <xsl:otherwise>
114         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
115       </xsl:otherwise>
116     </xsl:choose>
117   </xsl:template>
118
119   <xsl:template match="tml:g[@id]">{<xsl:apply-templates select="*"/>}</xsl:template>
120
121   <xsl:template match="tml:g[count(*)&gt;1]">{<xsl:apply-templates select="*"/>}</xsl:template>
122
123   <xsl:template match="tml:g">
124     <xsl:apply-templates select="*"/>
125   </xsl:template>
126
127   <xsl:template match="tml:row">
128     <xsl:apply-templates select="cell"/>\cr </xsl:template>
129
130   <xsl:template match="tml:cell">
131     <xsl:apply-templates select="*"/>
132     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
133   </xsl:template>
134
135 <!--/// CONTROL SEQUENCES ///-->
136
137   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]">
138     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
139     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
140     <xsl:apply-templates select="*[position()&gt;1]"/>
141   </xsl:template>
142
143   <xsl:template match="tml:c">\<xsl:value-of select="@name"/>
144     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
145     <xsl:apply-templates select="*"/>
146   </xsl:template>
147
148 <!--/// CURSOR ///-->
149
150   <xsl:template match="tml:cursor[@val]">
151     <xsl:choose>
152       <xsl:when test="string-length(@val)=0"/>
153       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
154     </xsl:choose>
155   </xsl:template>
156
157 </xsl:stylesheet>
158