使用 ctop.xsl 中缀表示法的内容 mathml 未获得所需格式 [英] content mathml to infix notation using ctop.xsl not getting as desired format

查看:20
本文介绍了使用 ctop.xsl 中缀表示法的内容 mathml 未获得所需格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从内容 mathml 中制作数学符号或中缀表达式,

I am trying to make math notation or infix expression from content mathml,

我正在为此提供 ctop.xsl 的帮助:

I am making help of ctop.xsl for this:

/***ctop.xsl**/

参考

可以解析得到如下表达式:

It can be parsed to get the expression as follows:

<html>
<head>
<script>
function loadXMLDoc(filename)
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else 
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml = loadXMLDoc("contentmathml.xml");
xsl = loadXMLDoc("ctop.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
  {
  ex = xml.transformNode(xsl);
  document.getElementById("example").innerHTML = ex;
  }
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml, document);
  document.getElementById("example").appendChild(resultDocument);
  }
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

这里contentmathml.xml是我的输入

我的内容 mathml 为:

I am having content mathml as :

输入:

<math><apply><power></power><ci>x</ci><cn>2</cn></apply></math>

我得到 输出:x2

预期:x^2

我再次尝试作为输入:

<math><apply><sin></sin><ci>x</ci></apply></math>

输出:sinx预期输出:sin(x)'

如何更改 ctop.xsl 以获得中缀作为输出?

How can I change the ctop.xsl in such a way to get the infix as output?

推荐答案

您的输入不正确,应该在 MathML 命名空间中:

Your input is incorrect, it should be in the MathML namespace:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <apply><power></power><ci>x</ci><cn>2</cn></apply>
</math>

与您的问题没有直接关系,但这里有更新的、维护的 ctop.xsl 样式表版本

Not directly related to your problem but there is a newer, maintained, version of the ctop.xsl stylesheet here

https://github.com/davidcarlisle/web-xslt/tree/master/ctop

这篇关于使用 ctop.xsl 中缀表示法的内容 mathml 未获得所需格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆