So, my article got posted on Ajaxian :). I got 2 questions from Rui Lopes:
“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!”
Of course that’s great to hear! I will answer those questions here:
Support for other browsers
For Javeline Platform I have created a way to use the selectSingleNode and selectNodes methods for all browsers. Of course there are people who are really hooked on the ’standard’ way that is implemented in Gecko and Opera, but I am a big fan of the simplicity of this interface.
For this to work several constructors have to be extended with the aforementioned methods. The nightly of Safari supports this, as well as Opera and Firefox. Safari 1.4 however, doesnt. To fix this I use the following ‘hack’.
if(IS_SAFARI_OLD){
HTMLElement = HTMLDocument = XMLDocument = Element = {};
}
So now we are ready to extend constructors using the prototype construct:
if(IS_SAFARI){
HTMLDocument.prototype.selectNodes =
Element.prototype.selectNodes =
XMLDocument.prototype.selectNodes = function(sExpr, contextNode){
return XPath.selectNodes(sExpr, contextNode || this);
}
HTMLDocument.prototype.selectSingleNode =
Element.prototype.selectSingleNode =
XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
return XPath.selectNodes(sExpr, contextNode || this)[0];
}
}
In the same way we can extend Opera and Firefox. A similar solution can be created to have XSLT support in a generic way. You can download the solution here.
Is full XSLT 1.0 supported?
No. I have implemented what I needed for the projects we’ve done. Currently the following is implemented:
- value-of
- copy-of
- if
- for-each
- choose
- apply-templates
- when
- otherwise
If anyone wants to help me to finish this, you are very welcome ;).