使用 XSLT 的 XML 到 XHTML:使用诸如 ∑ 之类的实体;(这是一个 MATHML 实体) [英] XML to XHTML using XSLT: using entities such as ∑ (which is a MATHML entity)
问题描述
假设我有一个 XML 文件 test.xml
,其中包含(除其他外)一些 MATHML:
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>
我想使用浏览器的 XSLT 引擎将 test.xml
转换为 XHTML+MATHML 并显示它.我的 XSLT 文件 template.xsl
看起来像这样:
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>
当我在浏览器中打开 test.xml
时,它会出错,指出实体 ∑
未声明.显然,我希望 ∑ 符号按原样显示.当我使用数字实体 ∑
时,它按预期工作,但查找每个数学符号的数字实体很痛苦.
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.
我尝试使用 <xsl:output>
标签尝试不同的文档类型,例如 doctype-system="http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"
但到目前为止还没有运气.
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.
推荐答案
XSLT 需要格式良好的 XML 作为输入,并且引用未声明实体的文件格式不正确.如果要在 XML 文档中使用 MathML 实体引用,则需要引用包含其定义的 DTD.
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.
这篇关于使用 XSLT 的 XML 到 XHTML:使用诸如 &Sum; 之类的实体;(这是一个 MATHML 实体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!