Linking to XML Stylesheet Stored on Local Server in Firefox

Problem

I created an XML stylesheet which I wanted to place on a local Samba share. 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

About Jeff Fitzsimons

Jeff Fitzsimons is a software engineer in the California Bay Area. Technical specialties include C++, Win32, and multithreading. Personal interests include rock climbing, cycling, motorcycles, and photography.
This entry was posted in Technology. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *