简体   繁体   中英

Loading XSL file with javascript

I am building a web app that converts Mathematical equations written in ascii to MathML format, and then converting the MathML format to OMML format. To do so, I found an xsl file that transforms the MathML to OMML using XSLTProcessor . In my script i managed to build the MathML file and load it, and to transform it, I'm having serious trouble loading the xsl file using:

    var xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet("MML2OMML.XSL");

The app is only a client-side it will be used for individual users, therefore there is no server. So knowing that chrome has permission issues:

Origin null is not allowed by Access-Control-Allow-Origin.

I learned that I cannot load the xsl file from my local filesystem unless I used FileReader with HTML5 , but this requires me to use a form input and I don't want this.

so I tried using a XMLHttpRequest with the file put on my public folder on dropbox using this code:

    var request = new XMLHttpRequest();
    var url = "http://dl.dropbox.com/u/27440550/MML2OMML.XSL";
    request.open("GET",url,true);
    request.send();
    console.log(request.responseXML);

And I'm still having the same error

Origin null is not allowed by Access-Control-Allow-Origin.

Isn't this error generated when Chrome detects that the file being accessed is local? And why is he considering that the file is local when it's on a public storage (Dropbox)?

It's been 2 days I'm searching for an answer and I'm really frustrated. Can someone provide me with a solution? thanks:)!

If you run the app as an offline app from file:///, then it doesn't matter that the XSLT file is online; both origins have to agree, and for your app it's still "null", so you won't be able to get that XSLT file. If the app truly is client-side only, include that XSLT file as part of the data the client downloads when they get the app, and store it as base64 encoded text so that you can unpack and inject it with Javascript, or have it sit in the same directory as your index.html and then make the XML you generate load the stylesheet as a relative link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM