The significant difference between <xsl:apply-templates> and <xsl:-for-each> , which no one mentioned :
xsl:apply-templates much richer and deeper than xsl:for-each , even simply because we don’t know which code will be used on the nodes of the choice - in general, this code will be different for different nodes of the node -list .
In addition, the code that will be applied can be written after xsl: apply templates, and people who do not know the original author .
_2. On the other hand, using <xsl:for-each> is in no way harmful if you know exactly how <xsl:for-each> handled .
The problem is that many XSLT newbies with experience in imperative programming accept <xsl:for-each> as a replacement for the "loop" in their favorite PL and consider that it allows them to accomplish the impossible, such as increasing the counter or whatever modification of an already defined <xsl:variable> .
One of the indispensable uses of <xsl:for-each> is to modify the current document - this is often necessary in order to be able to use the key () in a document different from the current source XML document , for example, to effectively access the lookup table located in native XML document.
Dimitre novatchev
source share