syncing up to 3.0.0rc1
[Samba.git] / docs / docbook / xslt / db2latex / mathml / mathml.content.token.mod.xsl
blob1f3f5667634fba36e1919cadeb96d564104136e2
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet
4 <!ENTITY % mmlalias PUBLIC "MathML alias" "ent/mmlalias.ent"> %mmlalias;
5 <!ENTITY % mmlextra PUBLIC "MathML extra" "ent/mmlextra.ent"> %mmlextra;
6 ]>
7 <!--#############################################################################
8 |- #############################################################################
9 |
10 | PURPOSE: MathML Content Markup, tokens (ci, cn, csymbol)
11 | MathML namespace used -> mml
12 + ############################################################################## -->
14 <xsl:stylesheet version='1.0'
15 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns="http://www.w3.org/1998/Math/MathML">
18 <xsl:strip-space elements="mml:math mml:mrow"/>
21 <!-- Content Number -->
22 <!-- support for bases and types-->
23 <xsl:template match="mml:cn">
24 <xsl:text>{</xsl:text>
25 <xsl:text>{</xsl:text>
26 <xsl:choose>
27 <xsl:when test="./@type='complex-cartesian' or ./@type='complex'">
28 <mn><xsl:value-of select="text()[position()=1]"/></mn>
29 <xsl:choose>
30 <xsl:when test="contains(text()[position()=2],'-')">
31 <xsl:text>-</xsl:text><xsl:value-of select="substring-after(text()[position()=2],'-')"/>
32 <!-- substring-after does not seem to work well in XT :
33 if imaginary part is expressed with at least one space char
34 before the minus sign, then it does not work (we end up with
35 two minus sign since the one in the text is kept)-->
36 </xsl:when>
37 <xsl:otherwise>
38 <xsl:text>+</xsl:text> <xsl:value-of select="text()[position()=2]"/>
39 </xsl:otherwise>
40 </xsl:choose>
41 <xsl:text>\dot\textrm{i}</xsl:text>
42 </xsl:when>
43 <xsl:when test="./@type='complex-polar'">
44 <xsl:text>\textrm{Polar}(</xsl:text><xsl:value-of select="text()[position()=1]"/><xsl:text>,</xsl:text>
45 <xsl:value-of select="text()[position()=2]"/>
46 <xsl:text>)</xsl:text>
47 </xsl:when>
48 <xsl:when test="./@type='rational'">
49 <xsl:text>\frac{</xsl:text><xsl:value-of select="text()[position()=1]"/><xsl:text>}{</xsl:text>
50 <xsl:value-of select="text()[position()=2]"/>
51 <xsl:text>}</xsl:text>
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:value-of select="."/>
55 </xsl:otherwise>
56 </xsl:choose>
57 <xsl:text>}</xsl:text>
58 <xsl:if test="@base and @base!=10"> <!-- base specified and different from 10 ; if base = 10 we do not display it -->
59 <xsl:text>_{</xsl:text><xsl:value-of select="@base"/><xsl:text>}</xsl:text>
60 </xsl:if>
61 <xsl:text>}</xsl:text>
62 </xsl:template>
66 <!-- Content Identifier -->
67 <!-- identifier -->
68 <!--support for presentation markup-->
69 <xsl:template match="mml:ci">
70 <xsl:choose>
71 <xsl:when test="./@type='complex-cartesian' or ./@type='complex'">
72 <xsl:choose>
73 <xsl:when test="count(*)>0"> <!--if identifier is composed of real+imag parts-->
74 <xsl:text>{</xsl:text>
75 <xsl:choose>
76 <xsl:when test="*[self::mml:mchar and position()=1]"> <!-- if real part is an mchar -->
77 <xsl:text>\textrm{</xsl:text><xsl:copy-of select="*[position()=1]"/><xsl:text>}</xsl:text>
78 </xsl:when>
79 <xsl:otherwise> <!-- if real part is simple text -->
80 <xsl:text>\textrm{</xsl:text><xsl:copy-of select="*[position()=1]"/><xsl:text>}</xsl:text>
81 </xsl:otherwise>
82 </xsl:choose>
83 <xsl:choose> <!-- im part is negative-->
84 <xsl:when test="contains(text()[preceding-sibling::*[position()=1 and self::mml:sep]],'-')">
85 <xsl:text>-\textrm{</xsl:text>
86 <xsl:choose>
87 <xsl:when test="mml:mchar[preceding-sibling::*[self::mml:sep]]"><!-- if im part is an mchar -->
88 <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
89 </xsl:when>
90 <xsl:otherwise><!-- if im part is simple text -->
91 <xsl:value-of select="substring-after(text()[preceding-sibling::*[position()=1 and self::mml:sep]],'-')"/>
92 </xsl:otherwise>
93 </xsl:choose>
94 <xsl:text>}</xsl:text>
95 <xsl:text>\dot\textrm{i}</xsl:text>
96 </xsl:when>
97 <xsl:otherwise> <!-- im part is not negative-->
98 <xsl:text>+\textrm{</xsl:text>
99 <xsl:choose><!-- if im part is an mchar -->
100 <xsl:when test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
101 <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
102 </xsl:when>
103 <xsl:otherwise><!-- if im part is simple text -->
104 <xsl:value-of select="text()[preceding-sibling::*[position()=1 and self::mml:sep]]"/>
105 </xsl:otherwise>
106 </xsl:choose>
107 <xsl:text>}</xsl:text>
108 <xsl:text>\dot\textrm{i}</xsl:text>
109 </xsl:otherwise>
110 </xsl:choose>
111 <xsl:text>}</xsl:text>
112 </xsl:when>
113 <xsl:otherwise> <!-- if identifier is composed only of one text child-->
114 <xsl:text>\dot\textrm{</xsl:text><xsl:value-of select="."/><xsl:text>}</xsl:text>
115 </xsl:otherwise>
116 </xsl:choose>
117 </xsl:when>
118 <xsl:when test="./@type='complex-polar'">
119 <xsl:choose>
120 <xsl:when test="count(*)>0"> <!--if identifier is composed of real+imag parts-->
121 <xsl:text>{</xsl:text>
122 <mi>Polar</mi>
123 <mfenced><mi>
124 <xsl:value-of select="text()[following-sibling::*[self::mml:sep]]"/>
125 <xsl:if test="mml:mchar[following-sibling::*[self::mml:sep]]">
126 <xsl:copy-of select="mml:mchar[following-sibling::*[self::mml:sep]]"/>
127 </xsl:if>
128 </mi>
129 <mi>
130 <xsl:value-of select="text()[preceding-sibling::*[self::mml:sep]]"/>
131 <xsl:if test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
132 <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
133 </xsl:if>
134 </mi></mfenced>
135 <xsl:text>}</xsl:text>
136 </xsl:when>
137 <xsl:otherwise> <!-- if identifier is composed only of one text child-->
138 <mi><xsl:value-of select="."/></mi>
139 </xsl:otherwise>
140 </xsl:choose>
141 </xsl:when>
142 <xsl:when test="./@type='rational'">
143 <xsl:choose>
144 <xsl:when test="count(*)>0"> <!--if identifier is composed of two parts-->
145 <xsl:text>{</xsl:text><mi>
146 <xsl:value-of select="text()[following-sibling::*[self::mml:sep]]"/>
147 <xsl:if test="mml:mchar[following-sibling::*[self::mml:sep]]">
148 <xsl:copy-of select="mml:mchar[following-sibling::*[self::mml:sep]]"/>
149 </xsl:if>
150 </mi>
151 <mo>/</mo>
152 <mi>
153 <xsl:value-of select="text()[preceding-sibling::*[self::mml:sep]]"/>
154 <xsl:if test="mml:mchar[preceding-sibling::*[self::mml:sep]]">
155 <xsl:copy-of select="mml:mchar[preceding-sibling::*[self::mml:sep]]"/>
156 </xsl:if>
157 </mi><xsl:text>}</xsl:text>
158 </xsl:when>
159 <xsl:otherwise> <!-- if identifier is composed only of one text child-->
160 <mi><xsl:value-of select="."/></mi>
161 </xsl:otherwise>
162 </xsl:choose>
163 </xsl:when>
164 <xsl:when test="./@type='vector'">
165 <mi fontweight="bold">
166 <xsl:value-of select="text()"/>
167 <xsl:if test="mml:mchar">
168 <xsl:copy-of select="mml:mchar"/>
169 </xsl:if>
170 </mi>
171 </xsl:when>
172 <!-- type 'set' seems to be deprecated (use 4.4.12 instead); besides, there is no easy way to translate set identifiers to chars in ISOMOPF -->
173 <xsl:otherwise> <!-- no type attribute provided -->
174 <xsl:choose>
175 <xsl:when test="mml:mchar"> <!-- test if identifier is expressed using mchar nodes -->
176 <mi><xsl:value-of select="text()"/><xsl:copy-of select="mml:mchar"/></mi>
177 </xsl:when>
178 <xsl:when test="count(node()) != count(text())">
179 <!--test if children are not all text nodes, meaning there is markup assumed
180 to be presentation markup (the case where there are mchar nodes has been tested just before)-->
181 <xsl:text>{</xsl:text><xsl:copy-of select="child::*"/><xsl:text>}</xsl:text>
182 </xsl:when>
183 <xsl:otherwise> <!-- common case -->
184 <mi><xsl:value-of select="."/></mi>
185 </xsl:otherwise>
186 </xsl:choose>
187 </xsl:otherwise>
188 </xsl:choose>
189 </xsl:template>
196 <!-- externally defined symbols-->
197 <xsl:template match="mml:apply[mml:csymbol]">
198 <xsl:text>{</xsl:text>
199 <xsl:apply-templates select="mml:csymbol[position()=1]"/>
200 <xsl:text>\left(</xsl:text>
201 <xsl:for-each select="child::*[position()!=1]">
202 <xsl:apply-templates select="."/>
203 </xsl:for-each>
204 <xsl:text>\right)</xsl:text>
205 <xsl:text>}</xsl:text>
206 </xsl:template>
209 <xsl:template match="mml:csymbol">
210 <xsl:choose>
211 <!--test if children are not all text nodes, meaning there is markup assumed to be presentation markup-->
212 <!--perhaps it would be sufficient to test if there is more than one node or text node-->
213 <xsl:when test="count(node()) != count(text())">
214 <xsl:text>{</xsl:text> <xsl:copy-of select="child::*"/> <xsl:text>}</xsl:text>
215 </xsl:when>
216 <xsl:otherwise>
217 <xsl:text>\textrm{</xsl:text> <xsl:copy-of select="."/> <xsl:text>}</xsl:text>
218 </xsl:otherwise>
219 </xsl:choose>
220 </xsl:template>
222 <xsl:template match="mml:mchar">
223 <xsl:copy-of select="."/>
224 </xsl:template>
225 <!--
226 <xsl:template match="mml:mtext">
227 <xsl:copy-of select="."/>
228 </xsl:template>
230 </xsl:stylesheet>