Re: Using apply templates vs using value-of select /for-each

Subject: Re: Using apply templates vs using value-of select /for-each
From: Keith Visco <kvisco@xxxxxxxxx>
Date: Fri, 09 Apr 1999 09:52:50 -0400
A couple of other things to note.

When using xsl:apply-templates you are asking the processor to find the
appropriate template to use when processing the resulting Node Set. For
each node in the Node Set the XSL processor will look for a template,
and could apply a different template to each node.

When you use xsl:for-each you are "inlining" the template that the xsl
processor is to use for all nodes in the resulting Node Set.

You remove the overhead of finding the matching template when you
xsl:for-each. So when all the nodes will be processed using the sam the
Node Set, xsl:for-each will probably be more efficient.
xsl:apply-templates is better for mixed content that needs to be
processed differently, or when you want to use a template in more than
once place. 

xsl:value-of will return a string value for the given node that it
selects.

--Keith

> Kay Michael wrote:
> 
> > Looking at all the examples of XSL I have found/received,
> > I've noticed that some people use "xsl:value-of select" and/or
> "xsl:for-each
> > select" while others use "apply templates".
> 
> xsl:for-each works best where the structure of the document is fairly
> rigid (e.g. <BOOK> elements nested within a <BOOKLIST>);
> xsl:apply-templates works best where there are elements that can
> appear in many different contexts e.g. <FOOTNOTE>. I think that "apply
> templates" can do everything that "for each" can do, but "for each"
> may be more readable in those circumstances where it works.
> 
> Mike Kay


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


Current Thread