-->

content mathml to infix notation using ctop.xsl no

2019-02-26 07:17发布

问题:

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