DocBook 5,将 (MathML) 命名空间添加到 HTML 输出?



我正在打一本书,里面有一些用MathML编写的数学公式。 本书有一个"主"XML文件,其中包括所有章节文件,如下所示:

<?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>

介绍.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 命名空间声明,我希望生成的根元素也具有它。

最新更新