content mathml to infix notation using ctop.xsl not getting as desired format

北慕城南 提交于 2019-12-02 04:54:10

问题


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

I am making help of ctop.xsl for this:

/***ctop.xsl**/

Refer

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>

Here contentmathml.xml is my input

I am having content mathml as :

Input:

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

I am getting as output: x2

Expected: x^2

I tried again as input:

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

output: sinx Expected output: sin(x)'

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


回答1:


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>

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



来源:https://stackoverflow.com/questions/32179237/content-mathml-to-infix-notation-using-ctop-xsl-not-getting-as-desired-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!