Friday, February 23rd, 2007

XPath/XSLT support in Safari

Category: Articles, WebKit

<>p>Ruben Daniels was on a mission to create XPath and XSLT support that works on Safari.

This isn’t the first effort:

After searching the web I found several XPath/XSLT implementations:

I always try to keep the socalled ‘footprint’ of the application as low as possible. Loading a more than 100KB library to just add some functionality that should’ve existed in the first place, was unacceptable. The JS-XPath library only extends the one already available in IE. So I started building an XPath implementation myself with only one goal in mind; Create the smallest Xpath and XSLT implementation in javascript possible.

He ended up with some small libraries, and he discusses how he got there in his entry.

How to use it

javascript
< view plain text >
  1. // xpath
  2. var nodeset = XPath.selectNodes("//j:teleport/node()|text()", xmlContextNode);
  3.  
  4. // xslt
  5. var xsltProcessor = new XSLTProcessor();
  6. xsltProcessor.importStylesheet(xslDoc);
  7. d = document.implementation.createDocument("", "", null);
  8. f = xsltProcessor.transformToFragment(this, d);

Related Content:

Posted by Dion Almaer at 6:49 pm
3 Comments

++++-
4.3 rating from 26 votes

3 Comments »

Comments feed TrackBack URI

This is really an excellent job! I read the post stating the library sizes – 12.2kb for XPath and 4.6kb for XSLT – these sizes are just plain sick.

Two questions: support for other browsers? It should be great to have a standard way to perform XPath and apply XSLT without tinkering between each browser’s features; second, is full XSLT 1.0 supported? if not, which features aren’t supported?

Thanks for your work!

Comment by Rui Lopes — February 24, 2007

Hi Rui Lopes, I’ve posted an answer to your questions on my blog here: http://www.rubendaniels.com/2007/02/24/followup-questions-on-xpathxslt-for-safari/

Comment by Ruben Daniels — February 24, 2007

This is great! I have been looking for something like this.

The other libraries out there leaves to much of a footprint.

Comment by T — February 25, 2007

Leave a comment

You must be logged in to post a comment.