Friday, February 23rd, 2007
XPath/XSLT support in Safari
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:
- google AJAXSLT (168 KB)
- Cameron McCormack’s Xpath implementation (119 KB)
- JS-XPath IE-only (16 KB)
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
-
-
// xpath
-
var nodeset = XPath.selectNodes("//j:teleport/node()|text()", xmlContextNode);
-
-
// xslt
-
var xsltProcessor = new XSLTProcessor();
-
xsltProcessor.importStylesheet(xslDoc);
-
d = document.implementation.createDocument("", "", null);
-
f = xsltProcessor.transformToFragment(this, d);
-












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!
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/
This is great! I have been looking for something like this.
The other libraries out there leaves to much of a footprint.