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?
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.
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.