|Perl Monk, Perl Meditation|
Re: XSLT vs Templating?by Matts (Deacon)
|on Jan 28, 2002 at 22:00 UTC||Need Help??|
Whee - a question just made for me! ;-)
Let me start off by saying that almost everyone misses the point when it comes to XML+XSLT. Especially when it comes up against everyone's favourite tool: TT2. Passions rise, and fevers pitch.
So what is the point? Well in my opinion, the biggest point about XSLT is it's all about structures, not text. The problem is people think of XML as text, and so think inside a very limited "text" box. But really what XML is, is a fancy "dump" format for a hierarchical structure. That's why XML is so cool - because it's not about text - it's about structures.
So why does that make XSLT cool? Well because with XSLT you don't take some structure plus a template and generate some text (the TT2 model, along with every single other perl templating tool out there). You actually take a structure, plus a template, and generate a new structure! This is a whole new approach to "templating" that Perl people don't tend to be comfortable with, but really it's very very smart, and very very useful.
One of the most useful things you can do with that model is do chaining or pipelining - piping the output of one transformation into the next - like Unix pipes only better. This is one of the things AxKit implements, and is also the sheer beauty behind SAX filters that I love so much. This may sound quite inefficient, but it's really useful to develop stylesheets that do one small thing well (e.g. create a ToC from a file), and chain multiple stylesheets together, than it is to create one big monolith and debug it.
Also most of the Perl templating solutions miss out on declarative processing. XSLT implements this and does it really quite cleanly. The idea is that rather than iterate over your structure manually (foreach loop), you declare what you want to happen when the XSLT processor sees certain node types. This makes processing documents possible (as opposed to processing data, which is all perl templating solutions are really good for IMHO), and it also makes your templates nice and clean. I believe Andy was talking about adding something like this to TT2, but I'm not sure how far he got. But think though that this technology in XSLT has been in design since the mid-1980's, in DSSSL.
Another useful thing is multiple implementations. Often it's good to be able to use somebody else's XSLT engine. This goes among other comments about cross platform utility too.
Finally, another bonus is debugging. It may not seem like it now, but XSLT actually has much better debugging support than TT2, with the likes of Komodo and all the commercial players (MS, Oracle, IBM, etc) all have XSLT debuggers included in their development environments now. Hopefully we'll see more in the open source arena in terms of XSLT debugging, but I believe there's now a plugin for Emacs that can use libxslt's debugging hooks.
OK, about books... If you're hardcore, Michael Kay's "XSLT Programmer's Reference" is indispensible. But it's seriously hardcore. I have heard good things about some of the recent XSLT books, but I don't own any so I would hesitate to recommend any. I'll recommend XML in a Nutshell, but I was involved in its production (tech editor), so I'm biased.
As far as Perl XML books are concerned, I'm keeping schtum on that.
Don't be scared of the XML syntax. It takes a bit of learning, but a lot of thought has gone into XSLT over the last 20 years, and they got most things just right. It does have a steep learning curve, but it's very powerful, and there's not much it can't do.