Encoding attributes

MathType integration works with MathML, but under some circumstances, it modifies the XML encoding slightly.

MathType imports and exports MathML which, sometimes, cannot be placed directly inside HTML files. For example, the Moodle platform filters some HTML tags (APPLET, OBJECT, EMBED, etc.) and all unrecognized XML tags, and so it removes any MathML formula. This also occurs when the MathML appears inside an HTML attribute (for example, the SRC attribute of an IMG tag) and the browser, wrongly, tries to parse it.

In these situations, the 5 reserved characters of XML are replaced by other characters as shown in the following table:

Original XML character Replacing character
< (#3C) « (#AB)
> (#3E) » (#BB)
& (#26) § (#A7)
" (#22) ¨ (#A8)
' (#27) ` (#60)

Then, recovering the MathML from the modified version is as simple as undoing the replacement. We provide below-attached the content os a .XSLT file that does this replacement.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <!-- template for text -->
    <xsl:template match="child::text()">
    <!-- « (#AB), » (#BB), § (#A7), ¨ (#A8), ` (#B4) -->
    <xsl:variable name="text" select="translate(.,'&#xAB;&#xBB;&#xA7;&#xA8;','&lt;&gt;&amp;&quot;')"/>
    <!--  ` (#B4) -->
    <xsl:value-of  disable-output-escaping="yes" select='translate($text,"&#xB4;","&apos;")'/>
    </xsl:template>
    <!-- template for other nodes (including attributes) -->
    <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
</xsl:stylesheet>