I hear time and time again about how you should avoid the use of XSLT for-each. That it\'s your inner imperative programming demon that should be banished.
What\'s
Essential difference between
and
that nobody has pointed out:
xsl:apply-templates
is much richer and deeper than xsl:for-each
, even
simply because we don't know what code will be applied on the nodes of
the selection -- in the general case this code will be different for
different nodes of the node-list.
Also, the code that will be applied can be written way after the xsl:apply templates was written and by people that do not know the original author.
_2. On the other side, using
is processed
The trouble is that a lot of newcomers to XSLT that have experience in imperative programming take
as a substitute of a "loop" in their favorite PL and think that it allows them to perform the impossible -- like incrementing a counter or any other modification of an already defined
.
One indispensable use of
is to change the current document -- this is often needed in order to be able to use the key() function on a document, different from the current source XML document, for example to efficiently access lookup-table that resides in its own xml document.