Discussion Locked

Examine xsl:for-each and xsl:template

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
There are advantages and disadvantages for both xsl:for-each and xsl:template. Which method do you use most often in your XML development?

1 reply

by bmilbank

Generally, I prefer xsl:for-each. It is more program-ish and has the added benefit of avoiding problems with unwanted recursion when using xsl:include.

xsl:for-each is particularly useful when using named templates and then using xsl:call-template to invoke a template ... much like invoking a method or subroutine in a program.

Barring that, however, xsl:template does allow recursion without an explicit loop. I guess I am a control freak ... I want my recursion to be explicit and not implicit.

The end result: it is a matter of preference. Since I tend to modularize my XSL transformation documents (e.g., generic HTML XSLT, IE-specific XSLT, Netscape-specific XSLT, and then manage the inclusions dynamically, for-each and named templates tends to work much better and with less confusion ... particularly when debugging.

bmm

This discussion is closed to new replies.