This is the mail archive of the mailing list .

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Read the data only once.

Hi Raj,

> In my xsl I have a global varaible which caluculates and holds some
> data. I am using that variable from all over the xsl. I am making
> calls to named templates while creating the variable. Each time I
> call the varialbe, that named templates are being called to extract
> the value. I need a different behaviour here. In my case that
> variable remains constant through out the xsl. So I want to
> calculate the variable only once. Is there a easy way to implement
> this.

I assume that you mean you have something like:

<xsl:variable name="header">
  <xsl:call-template name="createHeader" />

<xsl:template name="createHeader">

Is that correct?

XSLT is, by definition, side-effect free, which means that the same
code can be executed multiple times and always give the same value.
The only thing that I can think of which would make the variable
change is if you are using some extensions within your named template
and those extensions have side-effects. Is that what you're doing?

The trouble is that because XSLT is designed to be side-effect free,
processors make optimisations when executing the stylesheet that
depend on this feature -- they might calculate the value of a variable
more than once to save the memory it would take to store the result,
or only call a function once with the same set of arguments because
they already know what the answer's going to be. Because the results
of evaluating something in XSLT cannot change, by definition, this
doesn't matter.

So basically, no, there isn't an easy way to tell your processor to
forget everything it knows about the fundamental rules of XSLT. What
you should do is redesign your stylesheet so that the information
that's being generated by the extensions is calculated prior to the
transformation and passed in to the stylesheet through parameters or
external files instead.



Jeni Tennison

 XSL-List info and archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]