I'm working my way through Jeni Tennison's new book Beginning XSLT 2.0: From Novice to Professional. As I'm doing this I'm trying to do all the transforms through client side javascript. To that end I've used Microsoft's MSXML, the XSLTProcessor in Firefox, and Google AJAXSLT. Sadly, the one I've found easiest to work with every time is Microsoft's MSXML. The other two are giving me headaches.
AJAXSLT is a breeze to use but it's not fully featured so some of the transforms just don't work. My initial thought is that the processor doesn't support built-in templates but it will take some playing around and possibly a post on their group for more information. Mark that down as a homework item.
The problem I'm having with XSLTProcessor just stems from my own stupidity. The transforms I'm doing are producing a full HTML document. The XSLTProcessor has a method to create a full document (the method is aptly named transformToDocument) but it returns a HTMLDocument DOM object instead of just a string of HTML like Microsoft and Google's processors. My problem at this point is I have no idea how to display this thing. I've tried appending that to a document in a new window, or different frame but those don't seem to work. I have no idea how to serialize the thing into its HTML equivalent so I can only examine the transformation at this point in the debugger. This will require further investigation as well.
Another note about something I found with Firefox. It automatically tries to validate the XSL document when you load it up. Here's a snippet of code to show what I'm talking about.
xslDoc = document.implementation.createDocument("", "", null);
xslDoc.onload = doStuffFunction;
xslDoc.load("test.xsl");
Now in order for this to work, test.xsl has to validate properly. A minor issue is that if test.xsl is a simple stylesheet, the validation fails and the document doesn't load. Also note that the failure is silent so you won't know unless you check the documentElement. The funny thing is that if you take a simple stylesheet and simply give it a .xml extension instead of xsl, it loads up fine. Firefox seems to be doing an xsl validation based on the file extension so you can trick the browser by renaming the file.
I'll have to keep working through some of this stuff. In the meantime, I'm enjoying the book. It's well laid out and Ms. Tennison uses a consistent example of an on-line TV guide that she extends through the course of the book to illustrate concepts.
Comments