首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DocBook 5,在MathML输出中添加(MathML)命名空间?

DocBook 5,在MathML输出中添加(MathML)命名空间?
EN

Stack Overflow用户
提问于 2017-07-06 18:55:17
回答 1查看 237关注 0票数 0

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

代码语言:javascript
复制
<?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就像

代码语言:javascript
复制
<?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>

这产生了类似的东西

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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>标记中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-06 21:11:50

如果您通过将模板放入主样式表模块来覆盖下面的模板,会发生什么情况:

代码语言:javascript
复制
<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命名空间声明,我希望生成的根元素也具有它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44956861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档