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

Re: Order which templates apply

Subject: Re: Order which templates apply
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 8 Mar 2003 19:22:05 +0100
order templates
"Karl Stubsjoen" <karl@xxxxxxxxxxxxx> wrote in message
news:01d001c2e4cd$7018b050$71d76844@xxxxxxx
> 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.  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, for a general question the answer is also general.

The order in which templates are applied to nodes generally cannot be
controlled, because XSLT is a functional language and when a sequence of
(siblings) independent xslt instructions are executed, there's no way to be
sure in what order they will be executed (e.g. we could have a parallel
implementation of an XSLT processor, or a clever XSLT processor could decide
to perform some optimisations, ..., etc.).

The only thing that is guaranteed is that their *output* will be the same as
in the case when they were executed sequentially -- and it seems to me that
this is what you actually care about.

This is what the XSLT spec
(http://www.w3.org/TR/xslt#section-Processing-Model) says:

"A list of source nodes is processed to create a result tree fragment. The
result tree is constructed by processing a list containing just the root
node. A list of source nodes is processed by appending the result tree
structure created by processing each of the members of the list in order. A
node is processed by finding all the template rules with patterns that match
the node, and choosing the best amongst them; the chosen rule's template is
then instantiated with the node as the current node and with the list of
source nodes as the current node list. A template typically contains
instructions that select an additional list of source nodes for processing.
The process of matching, instantiation and selection is continued
recursively until no new source nodes are selected for processing.
Implementations are free to process the source document in any way that
produces the same result as if it were processed using this processing
model."



So, if you care just about the ordering of the output, you can explicitly
control it by specifying a sequence of (let's say) xsl:apply elements, each
with a specific nodeset (subset of the nodes to be processed) specified as
the value of the "select" attribute. In your case you coud have:



  <xsl:apply-templates select="hiddenFormProducingElementsExpression"/>

  <xsl:apply-templates select="otherElementsExpression"/>



In this way in the resulting output the hidden form elements will be before
the other elements.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL





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


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.