Hi All,
Attached is a version of the xslt snippet. This version sets up the appropriate Javascript code so that the browser get the XML feed, transforms it using a the XSL file, and outputs the result to the document. The xslt snippet in the repository does the transform on the server.
Instructions
1. Copy xslt.txt into a plugin called xslt
2. Save loadXMLFeed.js in directory /assets/snippets/xslt/
3. In a page with a blank template, place a call to the snippet with &isProxy=`yes` as the only option. (Make sure the snippet call is the only content on this page, and, you only need one of these per site. This is the page that acts as a proxy for the remote XML feeds.
4. Each page where you want the transformed XML to appear, place the snippet call, with URL of the XML feed, the path to the XSL file, and the id of the page withe the &isProxy=`yes` option. (Example calls in xslt.txt).
Proxy page
The default security settings in Firefox do not allow a xmlHttpRequest object (which is used to retrieve the remote XML) to access an address that is on a different domain from that of the original page. Thus some sort of proxy page is necessary.
Limitations
1. Only tested in Firefox, I imagine it won’t work in IE at the moment.
2. Even in Firefox, the Javascript code only sometimes seems to work, I’ve not figured out why yet (I don’t really have that much javascript experience)
3. At the moment, only one call per page would work. However, I just need to figure out a way of uniquely ID’ing divs on a page and then this would be fixed.
4. No parameters can be passed to the xsl file (unlike the xslt snippet in the repository)
Possible improvements
(Apart from fix the limitations)
1. Merge with the xslt snippet in the repository, so an option in the call could determine whether the transform will happen on the server or in the browser.
2. Somehow have the snippet detect if the browser can do the xsl transform. If no, make sure the processing happens on the server. I have no idea how this is possible though.
3. Use a library to make it compatible with multiple browsers: Google AJAXSLT or Sarissa are examples.
Any comments/suggestions welcome.
Michal.
Just looking into this a bit more, I have found there are xslt libraries for cross browser compatibility: Google AJAXSLT or sarissa for example. Perhaps a possible improvement would be to have the xslt transform done using one of these. (I have added this to the first post)
-
☆ A M B ☆
- 24,524 Posts
So this will make a browser act like a poor man’s RSS reader? I really don’t know all that much about RSS, I’m usually kind of slow to pick up on the latest technology, I’m too busy still trying to figure out the older stuff!
I was more thinking that someone might want to include a feed from a remote site, on their site. Say latest news, their events from a calendar (possibly Google calendar?), perhaps have their latest photos from their flickr feed - something like that? NewsparserX does this already I think for RSS feeds, but this will be more general.
Thinking about the Sarissa vs Google AJAXSLT issue: Sarissa has good browser compliance (it looks like all recentish version of the major browsers: Firefox, IE, Opera, Safari and Konqueror), and uses the W3C Dom XML/XSLT functions if they are available. Google AJAXSLT does not (at the moment) use the W3C Dom XSLT functions if they are available: in all cases it does the XSL tranformation in javascript, thus I imagine it is much slower. For these reasons I think I am more pro using Sarissa at the moment.