At 2003-02-24 07:51 -0500, dvw6514@xxxxxxxxxxxx wrote:
What i want is to compare the value of currCpmBI with the previous value
in the iteration (which i have not defined in the above code). If they
differ I want to add a some extra html.
My question now boils down to:
- How can i remember the previous value of cpmMemBI and how would I store
it so i can compare it with the current value in the iteration?
You cannot do so.
- If the current value has changed, how can i re-initialise the previous
value with the current value?
You cannot do so.
Hope my question is clear.... ;-)
Very clear, but you are looking in the wrong direction for the answer to
your needs.
XSLT is functional and side-effect free, so there are no global variables
and there is no way to change the value of a variable in its scope once it
is bound. Looking in the direction of variable assignment is a tangent
away from the Recommendation and you have to think in terms of tree processing.
To compare a value found in the source tree in a given iteration with the
value found in the source tree in a previous iteration, it is necessary to
revisit the source node tree with an appropriate XPath address to locate
the information that had been found in that previous iteration.
The nuance in your specific example, however, is that you have sorted the
information extracted from the source node tree into the current node list
... which means an XPath address cannot be used to identify the "previous"
node in sorted order ... only the "previous" node in document order which
won't help you.
Once the current node list, selected from the source node tree, is sorted
all you know is the current node's position in the sorted list. You cannot
then address the sorted current node list to find adjacent members.
Have you considered a two-pass approach, reading and sorting your
information in the first step into an intermediate result tree and then
chaining to a second step that can address your information in the new
already-sorted intermediate as a source node tree?
A computationally intensive one-pass approach that may be a candidate for
you if the sorted collection is small is to revisit the sorted node list
repeatedly for each member of the sorted node list in order to extract into
result tree fragment variables indexed members based on their position
relative to the position of the current node in the sorted list. This is
not typically advised though because of the many many loops through the
source information.
I hope this helps.
.......................... Ken
--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO
North America: June 16-20, 2003
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 0-13-140374-5 Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1 Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list