No XSLTProcessor() support in Safari?

2019-04-13 06:02发布

For whatever reason, I can't get XSLTProcessor() to work all the time.

Here is my JS:

... xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xmlRequest.responseXML);
// Pass variables
xsltProcessor.setParameter(null, "sectionNumber", section);
xsltProcessor.setParameter(null, "entryNumber", elementNo);

// Transform XML using XSL
var resultDocument = xsltProcessor.transformToFragment(phonebookDump,document);
// Append to document
document.getElementById('three').appendChild(resultDocument);

Works fine in: Firefox on OSX, iPhone Simulator on OSX, Safari on OSX

Doesn't work at all in: Mobile Safari on iPhone, Safari on Windows

Am I missing something? Is there a workaround to XSLTProcessor()? Would server-side XSLT processing be quicker for mobile development anyways?

2条回答
Deceive 欺骗
2楼-- · 2019-04-13 06:40

Your JS code seems right. Safari (and safari mobile as well) acutally has the xslt support. It's just a merciless implementation. The problem is that sometimes it may look like it is not working just because it is not verbose at all when it fails.

Remember that webkit xsl engine is based on libxsl, so you can use any software based on this library to test your style sheet against your document. I personally use xslproc that fails just like safari, but gives much more output.

If you can't get out of the problem, just post the xslt and the XML files.

查看更多
祖国的老花朵
3楼-- · 2019-04-13 06:56

I'm pretty sure Mobile Safari doesn't support XSLT, as the underlying OS X implementation does not include the relevant libraries that are present in desktop versions of OS X.

Server-side processing would definitely be quicker for a mobile app anyway: any processing you can reasonably shift away from the phone to the server is a win.

查看更多
登录 后发表回答