DocBook 5,将(MathML)命名空间添加到HTML输出?
问题描述:
我正在用一些用MathML编写的数学公式来输入一本书。这本书有一个 “主” XML文件,其中包括所有的章节文件是这样的:DocBook 5,将(MathML)命名空间添加到HTML输出?
<?xml version="1.0" encoding="utf-8"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
version="5.1"
xml:lang="en">
<title>Some title</title>
<xi:include href="intro.xml"/>
</book>
而且intro.xml竟把
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="ch-intro" xmlns:m="http://www.w3.org/1998/Math/MathML">
<title>Introduction</title>
<para>Some text
<inlineequation>
<m:math><m:msqrt><m:mi>a</m:mi></m:msqrt></m:math>
</inlineequation>
Some other text.
</para>
</chapter>
这将产生类似
<p>Some text
<m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
<m:msqrt><m:mi>a</m:mi></m:msqrt>
</m:math>
Some other text.</p>
我在Docbook-XSL的HTML XSLT上加载定制层XSLT以加载MathJax:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.w3.org/1998/Math/MathML"
version="1.0">
<xsl:import href="docbook-xsl-nons-snapshot/html/docbook.xsl"/>
<!-- Add MathJax <script> tags to document <head> -->
<xsl:template name="user.head.content">
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=MML_CHTML"></script>
</xsl:template>
</xsl:stylesheet>
这意味着它确实会将<script>
标记添加到<head>
,但MathJax不会呈现公式,因为MathML命名空间本身在<math>
上时不起作用。命名空间需要去<html>
。
所以我的问题是,我应该如何编写XSLT自定义图层以将xmlns:m="http://www.w3.org/1998/Math/MathML"
添加到生成的<html>
标记中?
答
,如果你通过把它变成你的主要样式表模块覆盖下面的模板会发生什么:
<xsl:template match="*" mode="process.root">
<xsl:variable name="doc" select="self::*"/>
<xsl:call-template name="user.preroot"/>
<xsl:call-template name="root.messages"/>
<html>
<xsl:call-template name="root.attributes"/>
<head>
<xsl:call-template name="system.head.content">
<xsl:with-param name="node" select="$doc"/>
</xsl:call-template>
<xsl:call-template name="head.content">
<xsl:with-param name="node" select="$doc"/>
</xsl:call-template>
<xsl:call-template name="user.head.content">
<xsl:with-param name="node" select="$doc"/>
</xsl:call-template>
</head>
<body>
<xsl:call-template name="body.attributes"/>
<xsl:call-template name="user.header.content">
<xsl:with-param name="node" select="$doc"/>
</xsl:call-template>
<xsl:apply-templates select="."/>
<xsl:call-template name="user.footer.content">
<xsl:with-param name="node" select="$doc"/>
</xsl:call-template>
</body>
</html>
<xsl:value-of select="$html.append"/>
<!-- Generate any css files only once, not once per chunk -->
<xsl:call-template name="generate.css.files"/>
</xsl:template>
鉴于该模块具有MATHML命名空间声明我会想到的是,生成的根元素有它。
这很好!它也让每个