]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-tex.xsl
Initial revision
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-tex.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet
4      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
5      xmlns:tml="http://helm.cs.unibo.it/2002/TML"
6      xmlns:m="http://www.w3.org/1998/Math/MathML"
7      version="1.0">
8
9   <xsl:output method="text" indent="yes"/>
10
11   <xsl:param name="id" select="/.."/>
12
13   <xsl:template match="/">
14     <xsl:choose>
15       <xsl:when test="$id">
16         <xsl:apply-templates select="descendant::*[@id=$id]"/>
17       </xsl:when>
18       <xsl:otherwise>
19         <xsl:apply-templates select="*"/>
20       </xsl:otherwise>
21     </xsl:choose>
22   </xsl:template>
23
24   <xsl:template match="tml:tex">
25     <xsl:apply-templates select="*"/>
26   </xsl:template>
27
28   <xsl:template match="tml:math">
29     <xsl:choose>
30       <xsl:when test="@display='1'">$$<xsl:apply-templates select="*"/>$$</xsl:when>
31       <xsl:otherwise>$<xsl:apply-templates select="*"/>$</xsl:otherwise>
32     </xsl:choose>
33   </xsl:template>
34
35   <xsl:template match="tml:i">
36     <xsl:choose>
37       <xsl:when test="@name">\<xsl:value-of select="@name"/><xsl:value-of select="' '"/></xsl:when>
38       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
39       <xsl:otherwise>{\it <xsl:value-of select="@val"/>}</xsl:otherwise>
40     </xsl:choose>
41   </xsl:template>
42
43   <xsl:template match="tml:n">
44     <xsl:choose>
45       <xsl:when test="@name">\<xsl:value-of select="@name"/><xsl:value-of select="' '"/></xsl:when>
46       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
47       <xsl:otherwise>{\rm <xsl:value-of select="@val"/>}</xsl:otherwise>
48     </xsl:choose>
49   </xsl:template>
50
51   <xsl:template match="tml:o">
52     <xsl:choose>
53       <xsl:when test="@name">\<xsl:value-of select="@name"/><xsl:value-of select="' '"/></xsl:when>
54       <xsl:when test="string-length(@val)=1"><xsl:value-of select="@val"/></xsl:when>
55       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
56     </xsl:choose>
57   </xsl:template>
58
59   <xsl:template match="tml:sb">
60     <xsl:choose>
61       <xsl:when test="@under='1'">
62         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
63       </xsl:when>
64       <xsl:otherwise>
65         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
66       </xsl:otherwise>
67     </xsl:choose>
68   </xsl:template>
69
70   <xsl:template match="tml:sp">
71     <xsl:choose>
72       <xsl:when test="@over='1'">
73         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
74       </xsl:when>
75       <xsl:otherwise>
76         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
77       </xsl:otherwise>
78     </xsl:choose>
79   </xsl:template>
80
81   <xsl:template match="tml:g[@id]">{<xsl:apply-templates select="*"/>}</xsl:template>
82
83   <xsl:template match="tml:g">
84     <xsl:apply-templates select="*"/>
85   </xsl:template>
86
87   <xsl:template match="tml:row">
88     <xsl:apply-templates select="cell"/>\cr </xsl:template>
89
90   <xsl:template match="tml:cell">
91     <xsl:apply-templates select="*"/>
92     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
93   </xsl:template>
94
95 <!--/// CONTROL SEQUENCES ///-->
96
97   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]">
98     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
99     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
100     <xsl:apply-templates select="*[position()&gt;1]"/>
101   </xsl:template>
102
103   <xsl:template match="tml:c">\<xsl:value-of select="@name"/>
104     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
105     <xsl:apply-templates select="*"/>
106   </xsl:template>
107
108 </xsl:stylesheet>
109