omml2mathml 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ module Omml2Mathml
2
+ VERSION = "0.0.1".freeze
3
+ end
4
+
@@ -0,0 +1,473 @@
1
+ <!--
2
+ $Id: xhtml-mathml.xsl,v 1.4 2007/05/11 00:58:31 David Carlisle Exp $
3
+
4
+ Copyright David Carlisle 2007.
5
+
6
+ Use and distribution of this code are permitted under the terms of the <a
7
+ href="http://www.w3.org/Consortium/Legal/copyright-software-19980720"
8
+ >W3C Software Notice and License</a>.
9
+ -->
10
+
11
+ <!--<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" -->
12
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
13
+ xmlns:d="data:,dpc"
14
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
15
+ xmlns="http://www.w3.org/1999/xhtml"
16
+ xmlns:h="http://www.w3.org/1999/xhtml"
17
+ xmlns:saxon="http://saxon.sf.net/"
18
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
19
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
20
+ exclude-result-prefixes="d h xs saxon m">
21
+
22
+ <!-- <xsl:import href="file:///Program%20Files/Microsoft%20Office/Office12/OMML2MML.XSL"/> -->
23
+ <xsl:import href="./omml2mml.xsl"/>
24
+
25
+ <xsl:param name="pmathml" select="'pmathml.xsl'"/>
26
+ <xsl:param name="dtd" select="false()"/>
27
+ <!--<xsl:output method="xhtml" indent="yes" encoding="US-ASCII"/>-->
28
+ <xsl:output method="xml" indent="yes" encoding="US-ASCII"/>
29
+
30
+
31
+ <xsl:template match="/">
32
+ <xsl:if test="$pmathml">
33
+ <xsl:processing-instruction name="xml-stylesheet"
34
+ >type="text/xsl" href="<xsl:value-of select="$pmathml"/>"</xsl:processing-instruction>
35
+ </xsl:if>
36
+ <xsl:if test="$dtd">
37
+ <xsl:text disable-output-escaping="yes"><![CDATA[
38
+ <!DOCTYPE html SYSTEM "]]></xsl:text>
39
+ <xsl:value-of select="$dtd"/>
40
+ <xsl:text disable-output-escaping="yes"><![CDATA[" [
41
+ <!ENTITY % MATHML.prefixed "INCLUDE" >
42
+ <!ENTITY % MATHML.prefix "mml" >
43
+ ]>
44
+ ]]>
45
+ </xsl:text>
46
+ </xsl:if>
47
+ <xsl:apply-templates/>
48
+ </xsl:template>
49
+
50
+ <xsl:template match="h:*">
51
+ <xsl:element name="{local-name()}">
52
+ <xsl:apply-templates select="@*|node()"/>
53
+ </xsl:element>
54
+ </xsl:template>
55
+
56
+ <xsl:template match="@*">
57
+ <!--<xsl:copy-of select=".[namespace-uri(.)=('')]"/>-->
58
+ <xsl:copy-of select="."/>
59
+ </xsl:template>
60
+
61
+ <!--
62
+ <xsl:template match="comment()[matches(.,'^\[if gte msEquation 12\]>&lt;m:oMath(Para)?')]">
63
+ <mml:math>
64
+ <xsl:if test="matches(.,'^\[if gte msEquation 12\]>&lt;m:oMathPara')">
65
+ <xsl:attribute name="display">block</xsl:attribute>
66
+ </xsl:if>
67
+ <xsl:variable name="mml" as="element()*">
68
+ <xsl:apply-templates select="saxon:parse(
69
+ concat('&lt;x xmlns:m=''http://schemas.openxmlformats.org/officeDocument/2006/math''>',
70
+ substring-before(replace(.,'&lt;/?span[^&lt;&gt;]*>',''),'&lt;![endif]'),
71
+ '&lt;/x>'))/x"/>
72
+ </xsl:variable>
73
+ <xsl:copy-of select="$mml" copy-namespaces="no"/>
74
+ </mml:math>
75
+ </xsl:template>
76
+ -->
77
+
78
+ <xsl:template match="h:img[../preceding-sibling::node()[1]/self::comment()[matches(.,'^\[if gte msEquation 12\]>&lt;m:oMath(Para)?')]]"/>
79
+
80
+
81
+ <!-- that should be it but some bug fixes (reported to MS) in omml2mml.xsl -->
82
+
83
+ <xsl:template match="m:e | m:den | m:num | m:lim | m:sup | m:sub">
84
+ <xsl:choose>
85
+
86
+ <!-- If there is no scriptLevel speified, just call through -->
87
+ <xsl:when test="not(m:argPr[last()]/m:scrLvl/@m:val)">
88
+ <!-- DPC make sure only one element returned -->
89
+ <mml:mrow><xsl:apply-templates select="*" /></mml:mrow>
90
+ </xsl:when>
91
+
92
+ <!-- Otherwise, create an mstyle and set the script level -->
93
+ <xsl:otherwise>
94
+ <mml:mstyle>
95
+ <xsl:attribute name="scriptlevel">
96
+ <xsl:value-of select="m:argPr[last()]/m:scrLvl/@m:val" />
97
+ </xsl:attribute>
98
+ <xsl:apply-templates select="*" />
99
+ </mml:mstyle>
100
+ </xsl:otherwise>
101
+ </xsl:choose>
102
+ </xsl:template>
103
+
104
+ <!-- avoid printing fnames twice -->
105
+ <xsl:template match="m:func">
106
+ <mml:mrow>
107
+ <mml:mrow>
108
+ <xsl:apply-templates select="m:fName[1]/*" />
109
+ </mml:mrow>
110
+ <mml:mo>&#x02061;</mml:mo>
111
+ <xsl:apply-templates select="m:fName[1]/following-sibling::*" />
112
+ </mml:mrow>
113
+ </xsl:template>
114
+
115
+
116
+ <!-- m:r reconstituted from Word comments don't have character data in m:t it is directly i m:r (and style information is in interleaved span and i elements, weird but true -->
117
+
118
+ <xsl:template match="m:r[not(.//m:t)]">
119
+ <xsl:for-each select=".//text()[translate(.,' &#10;&amp;','')]">
120
+ <xsl:call-template name="ParseMt">
121
+ <xsl:with-param name="sToParse" select="translate(.,' &#10;&amp;','')" />
122
+ <xsl:with-param name="scr" select="../m:rPr[last()]/m:scr/@m:val" />
123
+ <xsl:with-param name="sty" select="../m:rPr[last()]/m:sty/@m:val" />
124
+ <xsl:with-param name="nor" select="../m:rPr[last()]/m:nor/@m:val" />
125
+ </xsl:call-template>
126
+ </xsl:for-each>
127
+ </xsl:template>
128
+
129
+
130
+
131
+ <!--
132
+ MS stylesheet uses DOE which is (a) unevil, (b) non necessary, and (c) breaks the pass through a temporay tree to get rid of namespace nodes.
133
+ repeat the templates here without doe (and without double quoting amp)
134
+ -->
135
+ <xsl:template match="m:nary">
136
+ <xsl:variable name="sLowerCaseSubHide">
137
+ <xsl:choose>
138
+ <xsl:when test="count(m:naryPr[last()]/m:subHide) = 0">
139
+ <xsl:text>off</xsl:text>
140
+ </xsl:when>
141
+ <xsl:otherwise>
142
+ <xsl:value-of select="translate(m:naryPr[last()]/m:subHide/@m:val,
143
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
144
+ 'abcdefghijklmnopqrstuvwxyz')" />
145
+ </xsl:otherwise>
146
+ </xsl:choose>
147
+ </xsl:variable>
148
+ <xsl:variable name="sLowerCaseSupHide">
149
+ <xsl:choose>
150
+ <xsl:when test="count(m:naryPr[last()]/m:supHide) = 0">
151
+ <xsl:text>off</xsl:text>
152
+ </xsl:when>
153
+ <xsl:otherwise>
154
+ <xsl:value-of select="translate(m:naryPr[last()]/m:supHide/@m:val,
155
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
156
+ 'abcdefghijklmnopqrstuvwxyz')" />
157
+ </xsl:otherwise>
158
+ </xsl:choose>
159
+ </xsl:variable>
160
+ <xsl:choose>
161
+ <xsl:when test="not($sLowerCaseSupHide='off') and
162
+ not($sLowerCaseSubHide='off')">
163
+ <mml:mo>
164
+ <xsl:choose>
165
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
166
+ m:naryPr[last()]/m:chr/@m:val=''">
167
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
168
+ </xsl:when>
169
+ <xsl:otherwise>
170
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
171
+ </xsl:otherwise>
172
+ </xsl:choose>
173
+ </mml:mo>
174
+ </xsl:when>
175
+ <xsl:when test="not($sLowerCaseSubHide='off')">
176
+ <xsl:choose>
177
+ <xsl:when test="m:naryPr[last()]/m:limLoc/@m:val='subSup'">
178
+ <mml:msup>
179
+ <mml:mo>
180
+ <xsl:choose>
181
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
182
+ m:naryPr[last()]/m:chr/@m:val=''">
183
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
184
+ </xsl:when>
185
+ <xsl:otherwise>
186
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
187
+ </xsl:otherwise>
188
+ </xsl:choose>
189
+ </mml:mo>
190
+ <xsl:apply-templates select="m:sup[1]" />
191
+ </mml:msup>
192
+ </xsl:when>
193
+ <xsl:otherwise>
194
+ <mml:mover>
195
+ <mml:mo>
196
+ <xsl:choose>
197
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
198
+ m:naryPr[last()]/m:chr/@m:val=''">
199
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
200
+ </xsl:when>
201
+ <xsl:otherwise>
202
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
203
+ </xsl:otherwise>
204
+ </xsl:choose>
205
+ </mml:mo>
206
+ <xsl:apply-templates select="m:sup[1]" />
207
+ </mml:mover>
208
+ </xsl:otherwise>
209
+ </xsl:choose>
210
+ </xsl:when>
211
+ <xsl:when test="not($sLowerCaseSupHide='off')">
212
+ <xsl:choose>
213
+ <xsl:when test="m:naryPr[last()]/m:limLoc/@m:val='subSup'">
214
+ <mml:msub>
215
+ <mml:mo>
216
+ <xsl:choose>
217
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
218
+ m:naryPr[last()]/m:chr/@m:val=''">
219
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
220
+ </xsl:when>
221
+ <xsl:otherwise>
222
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
223
+ </xsl:otherwise>
224
+ </xsl:choose>
225
+ </mml:mo>
226
+ <xsl:apply-templates select="m:sub[1]" />
227
+ </mml:msub>
228
+ </xsl:when>
229
+ <xsl:otherwise>
230
+ <mml:munder>
231
+ <mml:mo>
232
+ <xsl:choose>
233
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
234
+ m:naryPr[last()]/m:chr/@m:val=''">
235
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
236
+ </xsl:when>
237
+ <xsl:otherwise>
238
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
239
+ </xsl:otherwise>
240
+ </xsl:choose>
241
+ </mml:mo>
242
+ <xsl:apply-templates select="m:sub[1]" />
243
+ </mml:munder>
244
+ </xsl:otherwise>
245
+ </xsl:choose>
246
+ </xsl:when>
247
+ <xsl:otherwise>
248
+ <xsl:choose>
249
+ <xsl:when test="m:naryPr[last()]/m:limLoc/@m:val='subSup'">
250
+ <mml:msubsup>
251
+ <mml:mo>
252
+ <xsl:choose>
253
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
254
+ m:naryPr[last()]/m:chr/@m:val=''">
255
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
256
+ </xsl:when>
257
+ <xsl:otherwise>
258
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
259
+ </xsl:otherwise>
260
+ </xsl:choose>
261
+ </mml:mo>
262
+ <xsl:apply-templates select="m:sub[1]" />
263
+ <xsl:apply-templates select="m:sup[1]" />
264
+ </mml:msubsup>
265
+ </xsl:when>
266
+ <xsl:otherwise>
267
+ <mml:munderover>
268
+ <mml:mo>
269
+ <xsl:choose>
270
+ <xsl:when test="not(m:naryPr[last()]/m:chr/@m:val) or
271
+ m:naryPr[last()]/m:chr/@m:val=''">
272
+ <xsl:text disable-output-escaping="no">&#x222b;</xsl:text>
273
+ </xsl:when>
274
+ <xsl:otherwise>
275
+ <xsl:value-of select="m:naryPr[last()]/m:chr/@m:val" />
276
+ </xsl:otherwise>
277
+ </xsl:choose>
278
+ </mml:mo>
279
+ <xsl:apply-templates select="m:sub[1]" />
280
+ <xsl:apply-templates select="m:sup[1]" />
281
+ </mml:munderover>
282
+ </xsl:otherwise>
283
+ </xsl:choose>
284
+ </xsl:otherwise>
285
+ </xsl:choose>
286
+ <mml:mrow>
287
+ <xsl:apply-templates select="m:e[1]" />
288
+ </mml:mrow>
289
+ </xsl:template>
290
+
291
+
292
+ <xsl:template name="CreateGroupChr">
293
+ <xsl:variable name="sLowerCasePos" select="translate(m:groupChrPr[last()]/m:pos/@m:val,
294
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
295
+ 'abcdefghijklmnopqrstuvwxyz')" />
296
+ <xsl:choose>
297
+ <xsl:when test="$sLowerCasePos!='top' or
298
+ not(m:groupChrPr[last()]/m:pos/@m:val) or
299
+ m:groupChrPr[last()]/m:pos/@m:val=''">
300
+ <mml:munder>
301
+ <xsl:apply-templates select="m:e[1]" />
302
+ <mml:mo>
303
+ <xsl:choose>
304
+ <xsl:when test="string-length(m:groupChrPr[last()]/m:chr/@m:val) &gt;= 1">
305
+ <xsl:value-of select="substring(m:groupChrPr[last()]/m:chr/@m:val,1,1)" />
306
+ </xsl:when>
307
+ <xsl:otherwise>
308
+ <xsl:text disable-output-escaping="no">&#x023DF;</xsl:text>
309
+ </xsl:otherwise>
310
+ </xsl:choose>
311
+ </mml:mo>
312
+ </mml:munder>
313
+ </xsl:when>
314
+ <xsl:otherwise>
315
+ <mml:mover>
316
+ <xsl:apply-templates select="m:e[1]" />
317
+ <mml:mo>
318
+ <xsl:choose>
319
+ <xsl:when test="string-length(m:groupChrPr[last()]/m:chr/@m:val) &gt;= 1">
320
+ <xsl:value-of select="substring(m:groupChrPr[last()]/m:chr/@m:val,1,1)" />
321
+ </xsl:when>
322
+ <xsl:otherwise>
323
+ <xsl:text disable-output-escaping="no">&#x023DF;</xsl:text>
324
+ </xsl:otherwise>
325
+ </xsl:choose>
326
+ </mml:mo>
327
+ </mml:mover>
328
+ </xsl:otherwise>
329
+ </xsl:choose>
330
+ </xsl:template>
331
+
332
+
333
+ <xsl:template match="m:bar">
334
+ <xsl:variable name="sLowerCasePos" select="translate(m:barPr/m:pos/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
335
+ 'abcdefghijklmnopqrstuvwxyz')" />
336
+ <xsl:choose>
337
+ <xsl:when test="$sLowerCasePos!='bot' or
338
+ not($sLowerCasePos) or
339
+ $sLowerCasePos='' ">
340
+ <mml:mover>
341
+ <xsl:attribute name="accent">true</xsl:attribute>
342
+ <xsl:apply-templates select="m:e[1]" />
343
+ <mml:mo>
344
+ <xsl:text disable-output-escaping="no">&#x000AF;</xsl:text>
345
+ </mml:mo>
346
+ </mml:mover>
347
+ </xsl:when>
348
+ <xsl:otherwise>
349
+ <mml:munder>
350
+ <xsl:apply-templates select="m:e[1]" />
351
+ <mml:mo>
352
+ <xsl:text disable-output-escaping="no">&#x00332;</xsl:text>
353
+ </mml:mo>
354
+ </mml:munder>
355
+ </xsl:otherwise>
356
+ </xsl:choose>
357
+ </xsl:template>
358
+
359
+
360
+ <!-- wrong name for (m)phantom -->
361
+
362
+ <xsl:template match="m:phant">
363
+ <xsl:variable name="sLowerCaseWidth" select="translate(m:phantPr[last()]/m:width/@m:val,
364
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
365
+ 'abcdefghijklmnopqrstuvwxyz')" />
366
+ <xsl:variable name="sLowerCaseAsc" select="translate(m:phantPr[last()]/m:asc/@m:val,
367
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
368
+ 'abcdefghijklmnopqrstuvwxyz')" />
369
+ <xsl:variable name="sLowerCaseDec" select="translate(m:phantPr[last()]/m:dec/@m:val,
370
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
371
+ 'abcdefghijklmnopqrstuvwxyz')" />
372
+ <xsl:if test="not($sLowerCaseWidth='off' and
373
+ $sLowerCaseAsc='off' and
374
+ $sLowerCaseDec='off')">
375
+ <mml:mphantom>
376
+ <xsl:apply-templates select="m:e[1]" />
377
+ </mml:mphantom>
378
+ </xsl:if>
379
+ </xsl:template>
380
+
381
+
382
+
383
+ <!-- html fixes -->
384
+ <!--
385
+ <xsl:template match="h:style">
386
+ <style type="text/css">
387
+ <xsl:copy-of select="@*"/>
388
+ <xsl:apply-templates/>
389
+ </style>
390
+ </xsl:template>
391
+
392
+ <xsl:template match="@lang">
393
+ <xsl:attribute name="xml:lang" select="."/>
394
+ </xsl:template>
395
+
396
+ <xsl:template match="@style[../(@align|@width|@clear|@nowrap|@height)]" priority="2"/>
397
+ <xsl:template match="@align">
398
+ <xsl:attribute name="style">
399
+ <xsl:value-of select="../@style,concat('text-align: ',.)" separator=";"/>
400
+ </xsl:attribute>
401
+ </xsl:template>
402
+
403
+
404
+ <xsl:template match="@width">
405
+ <xsl:attribute name="style">
406
+ <xsl:value-of select="../@style,concat('text-width: ',.)" separator=";"/>
407
+ </xsl:attribute>
408
+ </xsl:template>
409
+
410
+ <xsl:template match="@height">
411
+ <xsl:attribute name="style">
412
+ <xsl:value-of select="../@style,concat('height: ',.)" separator=";"/>
413
+ </xsl:attribute>
414
+ </xsl:template>
415
+
416
+
417
+ <xsl:template match="@clear">
418
+ <xsl:attribute name="style">
419
+ <xsl:value-of select="../@style,concat('clear: ',if(.='all') then 'both' else .)" separator=";"/>
420
+ </xsl:attribute>
421
+ </xsl:template>
422
+
423
+ <xsl:template match="@nowrap">
424
+ <xsl:attribute name="style">
425
+ <xsl:value-of select="../@style,'white-space:nowrap'" separator=";"/>
426
+ </xsl:attribute>
427
+ </xsl:template>
428
+
429
+ <xsl:template match="h:head[not(h:title)]">
430
+ <head>
431
+ <xsl:copy-of select="@*"/>
432
+ <title><xsl:value-of select="../h:body/descendant::*[self::h:h1|self::h2][1]"/></title>
433
+ <xsl:apply-templates/>
434
+ </head>
435
+ </xsl:template>
436
+
437
+ <xsl:template match="h:link/@target"/>
438
+ <xsl:template match="h:table[h:tr and not(h:tbody)]">
439
+ <table>
440
+ <xsl:copy-of select="@*"/>
441
+ <xsl:apply-templates select="* except h:tr"/>
442
+ <tbody>
443
+ <xsl:apply-templates select="h:tr"/>
444
+ </tbody>
445
+ </table>
446
+ </xsl:template>
447
+
448
+ <xsl:template match="h:span[not(node()[2])]" priority="2">
449
+ <xsl:apply-templates/>
450
+ </xsl:template>
451
+
452
+ <xsl:template match="h:table[not(@*)]" priority="3"/>
453
+
454
+ <xsl:template match="h:tr" priority="3">
455
+ <xsl:message>
456
+ [<xsl:copy-of select="ancestor::h:table[1]/following-sibling::*[not(self::h:span[not(normalize-space())])][1]"/>]
457
+ </xsl:message>
458
+ <tr>
459
+ <xsl:copy-of select="@*"/>
460
+ <xsl:apply-templates select="h:td"/>
461
+ <xsl:apply-templates select="ancestor::h:table[1]/following-sibling::*[not(self::h:span[not(normalize-space())])][1]//h:tr[not(@style)]" mode="tr"/>
462
+ </tr>
463
+ <xsl:apply-templates select="ancestor::h:table[1]/following-sibling::*[not(self::h:span[not(normalize-space())])
464
+ and not(self::h:table/h:tbody/h:tr[not(@style)])][1]//h:tr[@style]"/>
465
+ </xsl:template>
466
+
467
+ <xsl:template match="h:tr" priority="3" mode="tr">
468
+ <xsl:apply-templates select="h:td"/>
469
+ <xsl:apply-templates select="ancestor::h:table[1]/following-sibling::*[not(self::h:span[not(normalize-space())])][1]//h:tr[not(@style)]" mode="tr"/>
470
+ </xsl:template>
471
+ -->
472
+
473
+ </xsl:stylesheet>