Please quote what you're replying to. (And if you start
quoting--don't top-post.) Read something about proper
etiquette when posting on the usenet.
monmonja wrote:
<xsl:template match="/">
<xsl:call-template name="tmpColors" >
<xsl:with-param name="counter" select="5" />
</xsl:call-template>
flash OBJECT
<xsl:apply-templates select="avatars/avatar/colors" />
</xsl:template>
<xsl:template match="avatars/avatar/colors"
name="tmpColors">
<xsl:param name="counter" />
<xsl:value-of select="count(color)" />
<xsl:for-each
select="avatars/avatar/colors/color[position()
< $counter]">
Try
<xsl:value-of select="colornameame" />
<xsl:text</xsl:text>
</xsl:for-each>
</xsl:template>
On call-template count(color) = 0 while on apply-template
count(color) = n. but if i do XPath from the root down
count(avatars/avatar/colors/color) the opposite happens.
Do call-template use the match patterns?
No, they don't. (I remember vividly putting my foot in my
mouth regarding this a few months ago--and Joe Kesselman
gently biting my head off shortly thereafter. Ah, sweet
memories.) call-template simply invokes another template,
without changing the context node.
Any advice from the experts out there when its more
appropriate to use call-template over apply-template.
Again thanks in advance.
First of all, I'd say using the same template as both
matchable and callable is a bad idea. Naturally, there
might be certain situations where this would be
appropriate, but unless you have a very good reason to do
something like that--don't.
In terms of imperative programming it might help thinking
about named templates as something like functions, and
about templates invoked using apply-templates as
polymorphic methods. A named template doesn't really care
about the context it's invoked from: it just does some
largerly context-independent stuff and that's all. Applying
templates to a nodeset is similar to doing something with a
collection of objects that you know implement a certain
interface without really caring about implementations. You
just say: 'do-something with all these nodes', and the
templates matching the nodes in question will determine
precisely how it will be done.
--
Pavel Lepin