0

Say I have an XML file test.xml which contains (among other things) some MATHML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="template.xsl"?>
<equation>
    <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
        <row>    
            <!-- Using a MATHML entity name here! -->  
            <mi>&Sum;</mi>
        </row>
    </math>
</equation>

I would like to use a browsers XSLT engine to convert the test.xml into XHTML+MATHML and display it. My XSLT file template.xsl looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/equation">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <body>
            Here is an equation:
            <xsl:copy-of select="."/>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

When I open test.xml in the browser it errors out stating that the entity &Sum; is not declared. Obviously I would like the ∑ sign displayed as it should. When I use the numeric entity &#8721; it works as expected, but looking up the numeric entities for each math symbol is a pain.

I tried playing the the <xsl:output> tag trying different document-types, such as doctype-system="http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" but so far no luck.

Marijn van Vliet
  • 5,239
  • 2
  • 33
  • 45
  • 1
    I don't think it is an XSLT problem, parsing the XML document (before the XSLT processor deals with it) already fails because of the reference to an undeclared entity. Which browser is that, what happens with that browser if you load an XML document containing only MathML markup with entity references to undeclared entities, do you get the same error? Or does the browser in that way support the MathML entities the same way most browsers do with XHTML and its entities, by somehow hard coding or pre-loading known entities? – Martin Honnen May 31 '12 at 15:37
  • You're right. Opera also gives an error when just opening the XML with the reference to the XSL template removed. – Marijn van Vliet May 31 '12 at 16:22

1 Answers1

1

XSLT requires well-formed XML as input, and a file that references an undeclared entity is not well-formed. If you're going to use MathML entity references in an XML document, you need to reference the DTD that contains their definitions.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • How would I go about doing that? (I'm not an XML expert...) – Marijn van Vliet May 31 '12 at 16:21
  • Rodin, I think doing this inside the browser is quite a challenge as browsers like Firefox/Mozilla use an XML parser that does not load external entities at all and as I think that other browsers like Opera or Chrome, although they use an XML parser capable of loading external entities, might not load them if you simply link to URL on the W3C web site, due to the same origin policy preventing such access. I think with client-side XML you would basically need to copy the contents of http://www.w3.org/2003/entities/2007/w3centities-f.ent into the internal subset of the DOCTYPE of your XML doc. – Martin Honnen Jun 01 '12 at 10:52
  • Actually, it turns out if I give the XML file a doctype that contains the MATHML entities (I picked the w3c XHTML+MATHML+SVG doctype), Opera imports the correct entities. – Marijn van Vliet Jun 01 '12 at 19:11
  • As currently defined in HTML5 (and implemented in current browsers) the full mathml entity set will be loaded if you specify a legacy XHTML1 or MathML2 DTD that does not define them with the same definitions, and will not be loaded if you specify a DTD that actually defines these entities. I have repeatedly re-opened a bug on this but the editor (who doesn't use xml) is "unmoved" and closes it each time. https://www.w3.org/Bugs/Public/show_bug.cgi?id=13409 – David Carlisle Jul 22 '12 at 01:31