Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Reg apply-templates and for-each

From: David Carlisle <davidc@--------->
To:
Date: 9/1/2005 8:56:00 AM
> but can any
> one tell me when should one go for xsl:apply-templates and when for
> xsl:for-each.


<xsl:for-each select="zzzz">
.....
</xsl:for-each>

is the same thing (more or less) as

<xsl:apply-templates select="zzz" mode="yyy"/>

<xsl:template match="node()" mode="yyy">
....
</xsl:for-each>

So, as you see, for-each is really just a restricted form of
apply-templates, and so which to use is mainly a matter of taste.

Note the main thing about for-each is that each node that is selected
(zzzz here) gets the same code applied (..... here). If that is what is
required, using for-each which makes this explict is often clearer.

In the apply-templates case, typically different types of node that
are selected would have different templates matching. Note that
apply-templates is only equivalent to for-each in the case that there
is a single template that matches _all_ the selected nodes.

There are other differences due to the way the scope of variables etc
work, which means that it is sometiomes more convenient to use or-each
and have direct access to variables in the current template rather
than use apply-templates, and have to explictly pass the variables as
parameters to the template. But generally using apply-templates is
betetr as it makes it easier to modify/maintain your code by adding new
templates, or importing stylesheets to override specific templates.
Stylesheets taht have just one bug template with lots of for-each groups
are harder to customise as if youy import the stylesheet you have to
replace entire template if you need to change any part of it.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent