XSLT is Hard so Try JSLT Instead
Thursday, June 12 2008 - ajax
When I first read this post on the Ajaxian my very first (somewhat unkind) thought was OMG do we really need another XSLTesq language. Isn't XSLT hard enough to get anything done with as it is. I spent countless hours learning the ins and outs of XSLT and now someone has gone and written it (again) this time in JavaScript.
Now that I've taken a closer look at JSLT, which you can do here I take back most of my unkind thoughts. Sure, the JSLT example is easier to read, and sure it probably is lighter to push that bit of JSLT to the client than the enormous amount of XSLT I would push to get something similar done, however I'm not really convinced it is better.
There seems to be this unmitigated push to force JavaScript to do everything. It's as if someone woke up and said from this point forward all code should be done via JavaScript. It doesn't matter than JavaScript isn't necessarily the right choice, just extend it, bend it, mash it and make it work. It's cool to program in JavaScript once more so get at it.
Well, frankly, I spent way too much time programming in JavaScript back in the days when it was neither cool nor fun and I don't have any real desire to head back that direction. Can JavaScript do some things better than other alternatives out there right now? Of course it can. Does that mean it is always the right choice? Of course not.

2 comment(s)
Hi Tim,
Just a quick response.
I'm not trying to push javascript as the solution to everything. Let me explain the decisions i made:
1. I really hate working in XSLT. XML is not for code, XML is for data. This bloats XSLT and requires recursive solutions to simple problems. Lets find an alternative.
2. I need to transform XML and JS variables to HTML or other text content purely client-side.
3. The language has to be as simple as possible, with least new things to learn.
So this lays down the demands for the templating langauge. Now to invent a new templating language that fits these constraints.
Lets start with the language we implement the template engine in. What choices do we have Flash(plugin/javascript) Java(plugin) or Javascript. Well there is not much choice there. Lets take Javascript.
Second i hated XSLT for encoding logic in xml tags like <else>. So we dont want to do this again. That means i could go invent a whole new way of encoding if/else structures OR well just use Javascript. No learning curve (another point satisfied) and probably the fastest thing to do. Hey what do you know, we get extending the templating language with JS and using JS variables and templating JSON all for free because of this choice. cool.
So now we laid down the implementation language, the logic-encoding structure. All that is left is fill in the gaps to make XML data access easy. Take from XSLT what is useful in concepts. And that is what JSLT is.
I hope i explained why this is not a 'Oh Javascript is so cool. lets use it for anything.' idea.
Regards,
Rik Arends
Rik,
Thanks for the reply.
I probably wasn't being completely fair in lumping this into the "javascript" is cool category since as you stated this is really more than just another example of how I can twist javascript to do what I want.
I was impressed with how well you explained what you had done with examples from both XSLT and JSLT.
No more negative comments from me until I give it a try!