[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Order which templates apply


Subject: Re: [xsl] Order which templates apply
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 10 Mar 2003 11:18:55 -0700 (MST)

Karl Stubsjoen wrote:
> Hello,
> 
> I know this question has been asked... but I still don't get it.  More
> importantly, I don't understand how to change the order which template rules
> are applied.

xsl:apply-templates is what controls which nodes are selected for processing.
The best matching templates for those nodes are found and the instructions in
them are instantiated. The first node to be processed is the root node of the
source tree. After that, it is up to the template that matches that node to
have an xsl:apply-templates that will result in more nodes being selected
and processed.

> I have multiple template matches which match different parts
> of my xml object.  I'd like to control which template is applied first.  I
> have this:
> 
>      <form name='asdf' action='dbxmladmin.asp' method='POST'>
>            <xsl:apply-templates/>
>       </form>
> 
> 
> >From this, I build a set of form elements, and then some hidden form
> elements.  The hidden form elements, which appear higher up in the xml
> object are applied first, however I'd like this template to be applied last.
> Was I too vague, do I need to give more information?

Yes, too vague. But you should read up on the use of template modes and the
use of named templates. If you find that you are wanting to process the
same nodes from the source tree using different templates, you may find
these approaches to be what you are looking for.

Remember: xsl:apply-templates is not saying what templates to invoke; it is
saying what nodes to process. xsl:call-template will invoke a specific named
template without changing the context (what node is being processed, etc.)
although any variables will go out of scope in the called template, so you
have to pass them as parameters.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml