XSLT stylesheets for MathML

Publishing XHTML+MathML Documents on the Web

At the current time few browsers have "native" support for MathML, and none have native support for the Content part of MathML. However Mozilla and Amaya have good support for Presentation MathML, and for other browsers there are a range of extensions that will render MathML (in particular, WebEQ and MathPlayer from Design Science and Techexplorer from IBM).

The main disadvantage of using a third party extension to render MathML within a web page is that it requires specific markup to specify the rendering extension (so <applet> for Java applets, <embed> for plugins and <object> for Microsoft Behavior extensions). The use of such markup ties the document to one particular platform, whereas the ideal of publishing information on the Web is that it should be accessible to all using a range of tools. We present here a proposed mechanism for using the XSLT transformation language to avoid these drawbacks and to allow XML files that conform to the XHTML and MathML Recommendations to be rendered on a range of browsers, with no browser specific markup in the document. The document just requires a single processing instruction linking to the stylesheet described here. The stylesheet transforms the supplied XML file, adding whatever markup is required to render MathML in the current browser, and pass the resulting document to the browser for rendering. Clearly this does require that the browser supports XSLT transformations, which does mean that a relatively new browser is required, however the current versions of (at least) Internet Explorer, Netscape and Mozilla all support XSLT, so while XSLT support is not universal it is, or soon will be, available on the majority of desktop browsers.

Linking to stylesheets

In order to use these stylesheets you need to add one line such as the following to your document, before the top level <html> element.

<?xml-stylesheet type="text/xsl" href="mathml.xsl"?>
<?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/mathml.xsl"?>
The stylesheet mathml.xsl will render documents containing any part of MathML, including Content Elements. If the document does not contain any Content MathML, then as an alternative one may link to a slightly simpler stylesheet:
<?xml-stylesheet type="text/xsl" href="pmathml.xsl"?>
<?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/pmathml.xsl"?>

This avoids loading the XSLT required to transform Content MathML to Presentation MathML that is needed to display Content MathML in some platforms. Most of the examples presented here will use this second stylesheet as this is sufficient to demonstrate the rendering capabilities of the various systems.

Examples

Specifying Preferences

Normally the stylesheet will transform the input document to use a suitable MathML renderer, depending on the browser in use and any browser extensions that it detects. It tries a list of possibilities and selects the first one which appears to be installed.

One may control this behaviour, adding one rendering possibility to the front of the list of renderers to be attempted. This is accomplised by adding an attribute from the MathML preferences namespace to the top level html element of the input document. For example:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html pref:renderer="css">


</html>

from the pmathml-css example file specifies that the "css" rendering is to be preferred (in preference to Techexplorer or MathPlayer that might otherwise have been chosen in Internet Explorer).

Still to do....

There are still improvements to be made to these stylesheets and the documentation...

In particular the JavaScript code is not very robust at present.

Support for more browsers is particularly important, including porting the JavaScript/CSS code from Internet Explorer to Netscape to give an alternative on no-MathML builds of Mozilla and Netscape.

Current Browser support

OS Browser XSLT MathML Renderer
Native Presentation MathPlayer Behaviour Techexplorer Behaviour Techexplorer Plugin CSS/Java Script
Windows IE x, x < 5.0 no no no no no no
IE 5.0 wd-xsl no no no yes no
IE 5.5 wd-xsl no yes yes yes no
IE 5.0/MSXML3 yes no no no yes no
IE 5.5/MSXML3 yes no yes yes yes yes
IE 6 yes no yes yes yes yes
Netscape x, x <= 6.0 no no no no no no
Netscape 6.1 yes no no no yes no
Netscape 7.0 yes yes no no no no
Mozilla 0.9.4 yes no no no no no
Mozilla 0.9.4/MathML yes yes no no no no
Mozilla 0.9.5+ yes yes no no no no
Amaya no yes no no no no
Opera no no no no no no
Lynx no no no no no no
Macintosh IE 5.0 wd-xsl no no no yes no
Netscape x, x <= 6.0 no no no no no no
Netscape 6.1 yes no no no yes no
Mozilla yes no no no no no
Opera no no no no no no
Lynx no no no no no no
Linux / Unix Netscape x, x <= 6.0 no no no no no no
Netscape 6.1 yes no no no yes no
Netscape 7.0 yes yes no no no no
Mozilla 0.9.4 yes no no no no no
Mozilla 0.9.4/MathML yes yes no no no no
Mozilla 0.9.5+ yes yes no no no no
Amaya no yes no no no no
Opera no no no no no no
Lynx no no no no no no

Files in the Distribution

XSLT Stylesheets

pmathml.xsl
The main stylesheet for Presentation MathML. Detects the rendering possibilities available to the current browser, and any preferences specified in the document and sets up an appropriate transformation.
mathml.xsl
The main stylesheet for Content or Presentation MathML. Currently this is largely a copy of pmathml.xsl, it may be that future versions of this distribution will be able to merge these files. It acts identically to pmathml.xsl unless running with transformiix (mozilla or netscape) in which case a pre-transformation of Content MathML to Presentation MathML is performed before rendering the Presentation MathML.
ctop.xsl
Implements a transformation from Content MathML to Presentation MathML. Currently this is only used for Mozilla (which does not have native Content MathML capability) However it could be offered as an option even if the system can render Content MathML natively as it is perhaps easier to modify such a stylesheet to local preferences than to modify a built in rendering rule in a MathML renderer.
pmathmlcss.xsl
This stylesheet transforms Presentation MathML to XHTML + CSS + Javascript, so rendering MathML (to somewhat variable quality) in a standard HTML browser without any extra plugin. In addition to its use as a fall back option in these client side transformations, this stylesheet could be used as a server based transformation to produce something acceptable on browsers without any XSLT or MathML support. (Currently the javascript has a Microsoft Bias, but this can hopefully be removed in future versions.)
svg.xsl
A simplified version of pmathml.xsl, extended to work with SVG as well as MathML, under Internet Explorer it uses the Adobe SVG Behavior.
xsldoc.xsl
A stylesheet for displaying XSLT stylesheets as HTML.

Example Files and Documentation

Overview.html
This file.
pmathml.xml
Small Presentation MathML example file,
pmathml-css.xml
As above but giving a preference to the "CSS" rendering.
pmathml-mathplayer.xml
As above but giving a preference to the "MathPlayer" rendering.
pmathml-mathplayer-dl.xml
As above but giving a preference to the "MathPlayer" rendering, after prompting the user to install MathPlayer if necessary.
pmathml-techexplorer-plugin.xml
As above but giving a preference to the "Techexplorer Plugin" rendering.
pmathml-techexplorer.xml
As above but giving a preference to the "Techexplorer Behaviour" rendering.
csmall.xml
Small Content MathML example file.
cmathml.xml
Larger Content MathML example file
cmathml-css.xml
As above but prefering CSS rendering
cmathml-mathplayer.xml
As above but prefering MathPlayer rendering
cmathml-techexplorer.xml
As above but prefering Techexplorer rendering
mml2002-01.xml ... mml2002-16.xml
Presentation given at the 2nd International MathML Conference.

Archive

xsl.zip
Zip archive of entire distribution

Copyright and Distribution Conditions

The majority of the code in these styleseets has been written by David Carlisle. Contributions from others are acknowledged at appropriate places within the sources.

The code is made available under the following conditions:

Copyright © David Carlisle 2001, 2002.

Use and distribution of this code are permitted under the terms of the W3C Software Notice and License.