]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/xsl/tml-texid.xsl
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / xsl / tml-texid.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="*[@id]">{\id{<xsl:value-of select="@id"/>}{<xsl:apply-templates select="." mode="core"/>}}</xsl:template>
25
26   <xsl:template match="*"><xsl:apply-templates select="." mode="core"/></xsl:template>
27
28   <xsl:template match="tml:tex">
29     <xsl:apply-templates select="*"/>
30   </xsl:template>
31
32   <xsl:template match="tml:math[@id]">
33     <xsl:choose>
34       <xsl:when test="@display='1'">$${\id{<xsl:value-of select="@id"/>}{<xsl:apply-templates select="*" mode="core"/>}}$$</xsl:when>
35       <xsl:otherwise>${\id{<xsl:value-of select="@id"/>}{<xsl:apply-templates select="*" mode="core"/>}}$</xsl:otherwise>
36     </xsl:choose>
37   </xsl:template>
38   
39   <xsl:template match="tml:math">
40     <xsl:choose>
41       <xsl:when test="@display='1'">$$<xsl:apply-templates select="*"/>$$</xsl:when>
42       <xsl:otherwise>$<xsl:apply-templates select="*"/>$</xsl:otherwise>
43     </xsl:choose>
44   </xsl:template>
45
46   <xsl:template match="tml:i" mode="core">
47     <xsl:choose>
48       <xsl:when test="@name">\<xsl:value-of select="@name"/>
49         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
50       </xsl:when>
51       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
52     </xsl:choose>
53   </xsl:template>
54
55   <xsl:template match="tml:n" mode="core">
56     <xsl:choose>
57       <xsl:when test="@name">\<xsl:value-of select="@name"/>
58         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
59       </xsl:when>
60       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
61     </xsl:choose>
62   </xsl:template>
63
64   <xsl:template match="tml:o" mode="core">
65     <xsl:choose>
66       <xsl:when test="@name">\<xsl:value-of select="@name"/>
67         <xsl:if test="parent::tml:g and following-sibling::tml:i"><xsl:value-of select="' '"/></xsl:if>
68       </xsl:when>
69       <xsl:otherwise><xsl:value-of select="@val"/></xsl:otherwise>
70     </xsl:choose>
71   </xsl:template>
72
73   <xsl:template match="tml:s" mode="core">
74     <xsl:text> </xsl:text>
75   </xsl:template>
76
77   <xsl:template match="tml:sb" mode="core">
78     <xsl:choose>
79       <xsl:when test="@under='1'">
80         <xsl:apply-templates select="*[1]"/>__<xsl:apply-templates select="*[2]"/>
81       </xsl:when>
82       <xsl:otherwise>
83         <xsl:apply-templates select="*[1]"/>_<xsl:apply-templates select="*[2]"/>
84       </xsl:otherwise>
85     </xsl:choose>
86   </xsl:template>
87
88   <xsl:template match="tml:sp" mode="core">
89     <xsl:choose>
90       <xsl:when test="@over='1'">
91         <xsl:apply-templates select="*[1]"/>^^<xsl:apply-templates select="*[2]"/>
92       </xsl:when>
93       <xsl:otherwise>
94         <xsl:apply-templates select="*[1]"/>^<xsl:apply-templates select="*[2]"/>
95       </xsl:otherwise>
96     </xsl:choose>
97   </xsl:template>
98
99   <xsl:template match="tml:g" mode="core">{<xsl:apply-templates select="*"/>}</xsl:template>
100
101   <xsl:template match="tml:row" mode="core">
102     <xsl:apply-templates select="cell"/>\cr </xsl:template>
103
104   <xsl:template match="tml:cell" mode="core">
105     <xsl:apply-templates select="*"/>
106     <xsl:if test="position() &lt; last()">&amp;</xsl:if>
107   </xsl:template>
108
109 <!--/// CONTROL SEQUENCES ///-->
110
111   <xsl:template match="tml:c[*[1][self::tml:g[@left-open='1']]]" mode="core">
112     <xsl:apply-templates select="*[1]"/>\<xsl:value-of select="@name"/>
113     <xsl:if test="*[2][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
114     <xsl:apply-templates select="*[position()&gt;1]"/>
115   </xsl:template>
116
117   <xsl:template match="tml:c" mode="core">\<xsl:value-of select="@name"/>
118     <xsl:if test="*[1][self::tml:i]"><xsl:value-of select="' '"/></xsl:if>
119     <xsl:apply-templates select="*"/>
120   </xsl:template>
121
122 </xsl:stylesheet>
123