2

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?

user1989
  • 163
  • 7
  • Please post the XML input as code. Is the XML input in the MathML namespace? Why are you trying to use a stylesheet that creates XML output to insert nodes in an HTML document? – Martin Honnen Aug 24 '15 at 10:32
  • @MartinHonnen the input is content mathml. I want to convert it into math notation , so that it can be passed to my python program!! – user1989 Aug 24 '15 at 11:50
  • I don't think you should be applying "ctop.xsl" directly to your XML, as all the templates in the XSLT use the "mode" attribute, so initially no templates will be matched. You should be using it as an "include" file in another XSLT, where you do an "xsl:apply-templates" with a mode to select the first element. See http://www.w3.org/Math/XSL/mathml.xsl as an example (although you probably don't want to copy that as-is). – Tim C Aug 25 '15 at 07:59
  • @TimC ctop.xsl has one template matching / in the default mode, so it should be OK. – David Carlisle Aug 25 '15 at 10:46

1 Answers1

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

David Carlisle
  • 5,582
  • 1
  • 19
  • 23