[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Apply Templates, when to use which? how do templat

Subject: Re: Apply Templates, when to use which? how do templates work?
From: "John Smith" <debrief@xxxxxxxxx>
Date: Tue, 28 Aug 2007 12:44:48 +0100
Re:  Apply Templates
> > 0. Does <apply-templates select="xyz" /> perform a match on the xyz
> > node??? xyz node and all its immediate children only??? or xyz node
> > and all descendants of xyz node?
>
>
> the xpath xyz selects a set of nodes, in this case the set of all
> children of the current node with that name. Templates are then applied
> to those nodes (only) in document order. this call to apply templates
> will not apply templates to descendants of any of these
> nodes. Descendants will only be processed if one of the templates that
> is applied recursively applies templates.  (The default template for
> elements applies templates to child nodes, so there maty not be any
> explict calls to apply-templates)
>

How does one get rid of default templates?

> > 1. Does
> > <template match="xyz"> ... </template>
> > match xyz regardless of whether I wanted it do do so or not?
>
>
> If you didn't want it to match xyz you would presumably use a different
> match pattern. The template _matches_ xyz but it may or may not be
> executed depending on whether templates are ever applied to that node.
>
> >  What I'm
> > trying to say there is no starting point of execution which I can use
> > to then decide which template should be applied at any given moment???
>
> In XSLT 1 the starting point is always / so if for example you have
>
> <xsl:template match="/">
> hello world
> </xsl:template>
>
> then processing any input document always produces "hello world" it
> doesn't matter what other match templates are in the stylesheet as they
> will never be executed as this template just outputs the text and stops
> it does not apply templates to any more nodes.
>

What's the behaviour of xslt 2.0 in this regards?

>
> > 4. What's the best practice for using applying templates in terms of
> > when to use which form??
> > <apply-templates />
> > <apply-templates select="xyz" />
> > <apply-templates select="xyz" mode="foo" />
> > <call-template name="bar" />
>
>
> It's not a case of best practice, they all do different things.

What do each do differently? I don't have experience with
xslt(obviously apparent) but it appears that using call-template can
achieve what the others achieve plus the use of parameters.

Also, are there any efficiency implications with each of these ?


Many thanks for the reply, it has cleared up a lot of things I was
struggling with :S

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.