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

Subject: RE: [xsl] RE:"*NEVER* use for-each"
From: "Patrick, Curtis W" <curtis.patrick@xxxxxxx>
Date: Tue, 27 Feb 2001 13:29:41 -0600
A coworker found a few tidbits of information regarding XSL optimization if
one is using XALAN.  The information is somewhere in the site.
One of the items is quoted below:
	"xsl:for-each is fast because it does not require pattern matching"

To say "never use for-each" is a ridiculous statement.  To suggest that a
beginner try to use templates as much as possible is a fair guideline,
simply because it is practice.  In time, that person will have a better
understanding of XSL and XML (Doms, trees, etc) and can make a better
assessment in the future whether or not for-each is appropriate.

In Mr. Duffey's example below, he is obviously not a beginner with XSL, and
if speed is an issue, perhaps for-each is the correct solution for him.  

In this age of huge storage devices, ridiculously fast machines, and bloated
OSes, the art of optimization is dwindling.  People just don't get how
important optimizing for speed can be.  In my case, I MUST be concerned with
speed and size and will likely use a for-each (if I see a gain in testing)
over the "correct" method of using templates.  Response time is that

-----Original Message-----
From: Duffey, Kevin [mailto:KDuffey@xxxxxxxxxxxx]
Sent: Tuesday, February 27, 2001 11:51 AM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: [xsl] RE:"*NEVER* use for-each"


That sounds like a good plan, but I have come to understand that there are
several possible ways of devising HTML pages out of an XML tree. One is to
use templates for everything. Another is to use a normal HTML approach where
by you use XSL throughout the page as needed to get to dynamic data and do
conditional things with that data. I have taken the latter approach.

The question I have is if it is "better" to do everything via templates for
the sake of using templates, or because for performance reasons it is better
as well? My main concern about using XSL is performance (second would be
memory use as XSLT uses DOM to read in XML which if you have several hundred
pages with several requests each happening at the same time, its quite
possible 1000's of DOM objects will be in memory at the same time..which is
another question I had..can SAX be used to conserve memory?). I want to make
sure the optimal performance can be achieved to support 1000's of requests
at the same time. I am not objected to using multiple servers in a farm to
handle bigger loads either. I thus far haven't done any load-testing on my
use of XSL, but it appears to be the same speed as JSP returns..although I
know I am being fooled by the single-page problem..I am not testing hundreds
of pages at the same time, my perceived visual is lying to me. ;)

I think someone else said there isn't any "wrong way" in using XSL..whether
it be inlined xsl in HTML, or templates. So I ask you, and Michael Kay and
others who have alot of knowledge, is it advisable to use templates over
inlined xsl for reasons of performance, effeciency, manageability (and any
of the above combinations). I can say from looking at XSL with templates,
its harder to follow that using inline xsl inside of html. That brings
around one other concern..the ability for others to manage the page in a
fashion that doesn't require extensive time to figure out the page. What is
more manageable, as well as provides best performance/memory use.


> -----Original Message-----
> From: Chris Bayes [mailto:Chris@xxxxxxxxxxx]
> Sent: Tuesday, February 27, 2001 9:41 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] RE:"*NEVER* use for-each"
> 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
> *[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
> >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:

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread