我正在打字一本书,里面有一些用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>而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来加载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>标记中?
发布于 2017-07-06 21:11:50
如果您通过将模板放入主样式表模块来覆盖下面的模板,会发生什么情况:
<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命名空间声明,我希望生成的根元素也具有它。
https://stackoverflow.com/questions/44956861
复制相似问题