XSLT stylesheets for MathML

Note: This is the documentation of the original version of these stylesheets, which are still available from this site.

Versions of the stylesheets updated to MathML3 are currently maintained as google code projects..

Addtitional technical information. For a first overview of the stylesheet see the Overview Page.

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 accomplished 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 in the pmathml-css stylesheet 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.
pmathml-self-style.xml
A small Presentation MathML example file, which does not use the standard stylesheet but uses an alternative form, which avoids the need to link to extenal files. See below for details.

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.

Alternatives

Self referencing stylesheet

Sometimes it is inconvenient to arrange that a document is always generated with the correct relative link to the stylesheet, and the Internet Explorer security restrictions cause problems with using an absolute URI to (for example) the copy on the W3C site.

It is possible to make use of XSLT's "literal result element as stylesheet" syntax, and use the document itself as the stylesheet. This form can not do the Content to Presentation transform required by Mozilla, so it should only be used for documents using presentation MathML, also currently it generates a warning about unsupported XSLT elements in Amaya. However for Internet Explorer, Mozilla and Netscape, one can follow the example pmathml-self-style.xml, the main parts of which are shown below.

<?xml-stylesheet type="text/xsl" href="pmathml-self-style.xml"?>
<html
  xmlns:m="http://www.w3.org/1998/Math/MathML"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"
  xmlns="http://www.w3.org/1999/xhtml" >
<head><title>Presentation MathML</title>

<object id="mmlFactory" 
        classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">
</object>

<xsl:processing-instruction name="import"
>namespace="m" implementation="#mmlFactory"</xsl:processing-instruction>

</head>
<body>
<h1>Presentation MathML</h1>
....
<m:math mode="display">
<m:mrow>
  <m:msqrt>
.....
</m:mrow>
</m:math>

</body>
</html>

To use this mechanism:

  1. The stylesheet processing instruction href must refer to the file itself.
  2. The XSLT namespace declaration and xsl:version attribute must be placed on the html element.
  3. An object refering to a behaviour for Internet Explorer should be added to the document head. The one shown should work for MathPlayer changing the id to classid="clsid:0E76D59A-C088-11D4-9920-002035EFB1A4" should work for Techexplorer. (This version of the stylesheet can not support the different options simultaneously.).
  4. An xsl:processing-instruction element should be added as shown, to generate a processing instruction to work with Microsoft Behaviors.
  5. The MathML elements must be explictly prefixed with the prefix declaed in the document head, as this simplified stylesheet can not convert unprefixed elements to the required prefix for Internet Explorer.

Switching Mime Types

For Content MathML, Mozilla requires a transformation to Presentation, but in all other cases of MathML rendering using the stylesheet, there is little "transformation" happening; the main process is an identity transformation, with some additional features, mainly to enable the Internet explorer behaviors mechanism.

If you have access to the server configuration then an alternative to using the stylesheet is produce the file in XHTML, with the additional object and processing instructions required by Internet explorer. However serve the file as content type text/html if the client requesting the page is Internet Explorer (and text/xml otherwise). By serving the file as HTML, Internet Explorer will use its HTML parser and so trigger the behavior mechanism. Without needing a stylesheet to perform an XHTML to HTML transformation.

If attempting this mechanism one should be aware of the compatibility guidelines in the XHTML 1.0 Recommendation which give advice on how to avoid XHTML features that may cause problems in HTML browsers.


The W3C Math Working Group. Send comments, questions and fixes to www-math@w3.org

$Id: Overview-tech.html,v 1.10 2012/03/29 15:58:10 dcarlis Exp $