Re: [xsl] XSLT Dead?

Subject: Re: [xsl] XSLT Dead?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 17 Apr 2007 21:35:01 +0200
G. Ken Holman wrote:
At 2007-04-17 15:02 -0400, Steve wrote:
This one has me kind of stumped. Maybe I'm one of these people. What
is the difference between for-each and apply-templates? I have a hard
time even mentally comparing the two.

Think "pull" and "push".


One function iterates through a node set and the other matches up a
template with a node based on a given context or passed mode. Is that
the right answer, or close to it?

With for-each one pulls nodes from the source tree and the instruction supplies the one result tree construction rule used for all nodes pulled.


With apply-templates one pushes nodes from the source tree at the stylesheet and the processor finds the template rule with the result tree construction rule for each individual node pushed.

These characterizations seem to be received well by my students.

Boolean algebra has always been difficult, boolean grammar even more. Whether is was yes or no, true or false, or push or pull. You can push a door open, or you can pull it, the result may be the same, but if the door can be opened to two sides, the results will differ.


With apply-templates, you pull (as in grab) the data from the tree (or were it apples?) into the basket (the template match) and with for-each (and call-template), you push the data from the source tree with enough force right where you want it (like pushing a fat man through a small door: pulling is easier than pushing).

The problem is that push and pull are easily mixed up (even more by non-native speakers) and depending on how you use the words (like above), either context suits. I find the connotation of 'pull' lighter and easier than the connotation of 'push'. Which is why I prefer to use the wording 'pull' for the (easier/lighter) apply-templates and push for the (harder) for-each (the fat man).

Or is it the weather? Maybe, when it rains, the apples will grow large enough and I push them from the tree with apply-templates.

I usually explain it to others like in: "with for-each _you_ tell the processor what to do, with apply-templates you let the _processor_ do the work for you".

Sorry for adding to the confusion,

Cheers,
-- Abel

Current Thread