xml - XSLT not working in web browser -
i have xslt file styles in xml. xslt accessible via url (http://someurl/somefile.xsl) without problems.
when insert same url xml-stylesheet
processing instruction, renders plain text in browsers (ff, ie),
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="http://someurl/somefile.xsl"?> <rootelement>...</rootelement>
but when use local file path (file downloaded same folder xml file), works charm:
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="somefile.xsl"?> <rootelement>...</rootelement>
why?
running xslt in web browser
running xslt in browser subject limitations:
xslt 2.0 not supported of major web browsers.
browser security models differ regarding xslt processing.
cross-domain restrictions require xslt load same origin the xml. (this appears biting in case.)
chrome not allow locally loaded xslt run (even when xml locally loaded). can annoying during development.
for these reasons, xslt more run on server or in batch mode rather in browser.
if wish run xslt in browser , have work chrome, firefox, , ie, must
- use xslt 1.0 only, not xslt 2.0.
use
xml-stylesheet
processing instruction in xml file you've done link xslt file xml file:<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="http://origin-domain/path/to/file.xsl"?> <rootelement>...</rootelement>
- serve xslt server, not local file.
- make sure xslt originates same domain xml.
finally, sure check browser console error messages. example, here's ie shows when xslt cannot located:
Comments
Post a Comment