问题
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>∑</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 ∑
is not declared. Obviously I would like the ∑ sign displayed as it should. When I use the numeric entity ∑
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