RE: [xsl] Looping in XSLT(old question, but maybe new problem)

Subject: RE: [xsl] Looping in XSLT(old question, but maybe new problem)
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Tue, 24 Jun 2003 20:49:10 -0400
Hey Liu,

You last responded with:
>>... if foo-bar-temp is a global variable, is the nodeset initialized
>>only once or is it generated every time foo-bar-temp is called?

I'm not quite sure I understand your question, but I'll give it a whirl...

Globally scoped variable elements are intialized only once, when the
transform begins ... or, in essence when the stylesheet is "compiled" and
intially loaded with the source xml document.  

I don't know off-hand what all the exact sequence rules are for processing
child elements of the stylesheet element, but I'm sure you could find that
at the w3c.

However, my example solution doesn't have the foo-bar-xxx (et.al) variables
defined at global scope, they were defined within the local scope of the
root matching template.

You could move them to that level of visibility ... here are some things to
consider before doing that:
   1.  Other templates could use the node lists ... which can be a great
thing, sharing objects/state can be nice.
   2.  They are defined only once, upon beginning the transform ... which
can be a nice optimization--if consideration #1 is a factor--but, if you
need to re-define them upon entering a given template, your out of luck.
   3.  I would only do this if there are only a few templates within the
stylesheet, otherwise what if--for a given transform--depending on your use
case, your xslt execution path/thread may never accesses/uses those
variables? ... then you've spent needless overhead in "compiling" the
stylesheet due to having to construct those globally visible variables.

Also, please keep in mind this was only an example--one example--of how to
accomplish your solution.

Thanks,
Jeff

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


Current Thread