Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) 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.


In reply to Re: XSLT vs Templating? by Matts
in thread XSLT vs Templating? by Masem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found