Read up on "grouping". That is the declarative
way to do what you want to do, rather than the
imperative approaches you've described as
considering. With grouping you don't need any mutable variables.
For many imperative programmers, wrapping one's
head around the declarative style can be
challenging, but it sure is rewarding when finally understood!
I have made my book on the subject free, available at:
https://cranesoftwrights.github.io/books/ptux/
... and there is an entire section on the many
kinds of grouping available when using XSLT.
Good luck!
. . . . . . Ken
At 2018-03-02 21:05 +0000, Jacopille, David djacopille(_at_)mfs(_dot_)com wrote:
Hello,
We have a for-each loop that constructs a
table. The first column is a region that would
normally look like the following ? we would like
to show the firstt region name only to avoid repetition.
US
US
US
US
Europe
Europe
Europe
Asia
Asia
My non-xsl mind wants to use a mutable variable:
* initialize a variable $current_region to â??â??
* loop through each row
* If current rowâ??s region column
COLUMN[@name=â??regionâ??] does not equal $current_region then:
* select the region so it shows in the table
* reassign $current_region to the string
value of the current rowâ??s region column
Perhaps comparing the current category to the preceding-sibling?
Perhaps a loop on select=â??distinct_values? to
find region names, enclosing aanother loop that
goes through each distinct regionâ??s rows? If
position()=1 worked in that context perhaps this would work?
Weâ??re aware of the saxon namespace that allows
for the mutable variable cheat, but would like to avoid this.
I would greatly appreciate your recommendations.
Thank you,
David Jacopille
Boston
--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) |
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--