Linking to XML Stylesheet Stored on Local Server in Firefox

July 1st, 2008 | by Jeff Fitzsimons |

Problem

I created an XML stylesheet which I wanted to place on a local Samba. In the XML file to be transformed, I placed a file:// URI in the xml-stylesheet tag, but it wouldn’t work in Firefox. Internet Explorer would happily format the content as expected, but Firefox simply displayed a rather uninformative error:

Error loading stylesheet: (null)

Cause

As it turns out, I was formatting the URI incorrectly.

Solution

Proper URI formatting for the file protocol requires three slashes to establish an empty authority or host segment, followed by the full path, with all backslashes converted to forward slashes. Since it was a path to a file on a local Samba server, which normally begins with two backslashes, this means I needed a total of five forward slashes following file:!

So, given a Windows-style path such as:

\\myserver\mypath\mystylesheet.xslt

The corresponding URI would be:

file://///myserver/mypath/mystylesheet.xslt

Yielding an xml-stylesheet tag like

<?xml-stylesheet type="text/xsl"
                 href="file://///myserver/mypath/mystylesheet.xslt">

Reference

MozillaZine: Links to local pages don’t work

Post a Comment