Rendering canSAS1D in Web Browsers

From canSAS
Revision as of 15:40, 12 March 2012 by Ajj (talk | contribs) (Created page with " == Using a stylesheet with XML files == One of the benefits of XML is that with an appropriate stylesheet, web browsers should be able to render the page as HTML. In order ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using a stylesheet with XML files

One of the benefits of XML is that with an appropriate stylesheet, web browsers should be able to render the page as HTML.

In order to use this feature, the XML file must have a stylesheet associated with it. This can either be local to the machine the XML file resides on, or accessed via a remote URL.

A default stylesheet is provided for the cansSAS1D format at: http://www.smallangles.net/cansas1d/1.0/cansasxml-html.xsl

In order to use this, there must be a line in the XML data file (usually the second line, after the xml declaration itself) as follows:

<?xml-stylesheet type="text/xsl" href="http://www.smallangles.net/cansas1d/1.0/cansasxml-html.xsl"?>

Thus the header will look something like:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.smallangles.net/cansas1d/1.0/cansasxml-html.xsl"?>
<SASroot version="1.0" 
   xmlns="cansas1d/1.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="cansas1d/1.0  http://www.smallangles.net/cansas1d/1.0/cansas1d.xsd">
<SASentry> ...

Browser Compatibility

However, not all browsers will behave well as it is often seen to be a security risk having a local file referencing a remote one. Hence in some cases you must store the XSL file locally and change the URL in the header appropriately.

Below is a list of various browsers and how they behave

Windows 7

  • IE 8
    • Works with local and remote stylesheets
  • IE 9
    • Works with local stylesheets only after allowing "Access data sources across domains" in the security settings
  • Firefox 10
    • Works with local stylesheets only
  • Google Chrome
    • Does not work with remote or local stylesheets
  • Opera
    • Not tested
  • Safari
    • Not tested

Mac OS

  • Safari 5
    • Works with remote and local stylesheets with no changes
  • Google Chrome
    • Does not work with remote or local stylesheets
  • Firefox 6
    • Works with local stylesheets only