RE: [xsl] RE:"*NEVER* use for-each"

Subject: RE: [xsl] RE:"*NEVER* use for-each"
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Tue, 27 Feb 2001 17:41:26 -0000
Mike,
When a lot of people come to XSLT they see <xsl:for-each> and think "That's
what I need" when it most times isn't. They should be using templates. As
they start to develop their template they add <xsl:if> and <xsl:choose> all
over the place within the <xsl:for-each> to get round not using templates in
the first place. So to stop people making a bealine for <xsl:for-each> I
always say "Beginners rule #1 *NEVER* use for-each". Daniel's solution to
his own problem is

><xsl:value-of
>select="ANNUALSNAPSHOT[3]/CONSENSUSVALUE/ESTIMATEDATA/child::*[position()=$
I
>ndex]" />

>Now I know might not be pretty, but it DOES return what I want. $Index will
>range from 1 to 9

Next he will be asking how he can increment his $Index variable which he
can't do because you can't increment variables without using recursion. As
he hasn't got the hang of templates yet explaining to him how to do
recursion is not going to be easy.
To quote Francis in another thread

>People on this list find themselves bailing out people who've sailed on
>to the same old rocks, and try to let others know that they're sailing
>in that direction, that why we make suggestions of this kind.

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml

>As a beginner, who has just used for-each to solve a problem, why should I
>never use it?
>
>(OK, I admit having checked the <xsl:sort> description in Mike Kay's book I
>could probably have used another template, but why is that preferable to
>using for-each?)
>
>mike
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread