XML to XHTML using XSLT: using entities such as ∑ (which is a MATHML entity)

二次信任 提交于 2019-12-24 20:41:58

问题


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.


回答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.



来源:https://stackoverflow.com/questions/10833051/xml-to-xhtml-using-xslt-using-entities-such-as-sum-which-is-a-mathml-entity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!