Subject: Re: [xsl] When exactly is the current node changed? From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Thu, 16 Nov 2006 16:22:38 -0800 |
I think logically current nnode is changed by the apply templates and is set (in turn) to each of teh sekected nodes _before_ a template is instantiated. The definition of the match patern more or less implies this as it is in terms of defining which templates match the current node. Implementtaions may do something else entirely of course.
Hmmm... In case I'm instantiating matching templates to several nodes in parallel, wouldn't that make it possible that I'd end up with two current nodes existing at the same time? Probably having more than one current node isn't in fact as horrible as it sounds?
Also, if a matching template does not implicitly depend on its current node implicit parameter, then probably it has better chances for optimization (the same reasoning as for why an xsl:function has its current node unsefined).
So, changing the current node before instantiating the matching template could be something similar to this code (this should be regarded only as pseudo-code, of course):
<xsl:call-template name="name-of-bestMatching template"> <!-- With whatever other parameters --> </xsl:call-template > </xsl:for-each>
while setting the current node only when the matching template is instantiated can be expressed better with this code:
<xsl:template name="apply-templates"> <xsl:param name="current-node-list"/>
<xsl:if test="$current-node-list"> <xsl:call-template name="instantiateTemplate"> <xsl:with-param name="currentNode" select="$current-node-list[1]"/> <xsl:with-param name="name-of-bestMatching template"/>
<!-- With whatever other parameters --> </xsl:call-template>
<xsl:call-template name="apply-templates"> <xsl:with-param name="current-node-list"
select="$current-node-list[position() > 1]"/> </xsl:call-template> </xsl:if> </xsl:template>
This is all in XSLT 1.0, in XSLT 2.0 the processing will be more complex but could probably be better expressed using xsl:function.
David
-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] When exactly is the curre, David Carlisle | Thread | RE: [xsl] When exactly is the curre, Michael Kay |
Re: [xsl] When exactly is the curre, David Carlisle | Date | RE: [xsl] When exactly is the curre, Michael Kay |
Month |