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

  1. use xslt 1.0 only, not xslt 2.0.
  2. 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> 
  3. serve xslt server, not local file.
  4. make sure xslt originates same domain xml.

finally, sure check browser console error messages. example, here's ie shows when xslt cannot located:

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -