xsl-list
[Top] [All Lists]

Re: [xsl] When exactly is the current node changed?

2006-11-16 17:23:08
On 11/16/06, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:

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:for-each select="$current-node-list">

   <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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--