A fascinating problem, for which I've coded various partial solutions in 3 or 4
languages over the years.
As you've suggested, a simple workable approach is to make a list of end
points, put them in order, and pair them off to form new ranges. (I've never
thought of this as a "grouping" problem.)
I've also implemented it as a segment tree (see in Wikipedia). This is
particularly elegant and can solve problems that are very difficult otherwise
(e.g. Is there a configuration where all components are like X?)
There are other approaches but typing on phone is tedious so if you are
interested let me know.
Regards,
--Paul
On Nov 17, 2014, at 23:07, Michael Friedman sumarimike(_at_)hotmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Greetings,
I'm trying to use XSLT 2.0 to create a new set of grouped ranges based on the
overlap of an aggregation of a set of non-contiguous individual ranges.
Example:
Given a range of numbers as an individual set:
1. <range>150-202</range>
2. <range>201-225</range>
3. <range>201-204</range>
4. <range>205-234</range>
5. <range>226-234, 250-260</range>
I'm trying to produce a new grouping based on the way the groups overlap:
150-200 (this is where <range> 1 starts and overlaps to 2 & 3)
201-202 (this is where 1 & 2 overlap, and group 1 ends)
203-204 (this is where 2 & 3 overlap and 3 ends)
205-225 (this is where 4 starts and begins to overlap with 5)
226-234 (this is where 4 & 5 overlap and end for the first part of 5)
250-260 (this is where the second range in 5 exists)
The start and end point of the individual source ranges form the boundaries.
I expect to end up with a string or variable structure like:
<finalrange>
<range>150-200</range>
<range>201-202</range>
etc
</finalrange>
or:
<range start="150" end="200"/>
<range start="201" end="202"/>
etc
Ultimately I have to format some content in XSLFO based on the XML's
participation in the "new" given range grouping. If you know aircraft
effectivity, this is what I am trying to group.
I've been using <xsl:sequence> to find all the numbers of a single range, so
I can do compares against individual numbers in the entire range, if
necessary. But, it seems like it may be easier to just work with the
boundaries: the start and end points and see if a value falls within it,
somehow, rather than iterating repetitively through enumerations of sequences.
I've been searching the archives for a while and have found some evocative
possibilities from Dimitre Novatchev and Michael Kay, but I can't quite find
a way to work with the overlapping. I'm continuing to study their
ranging/grouping examples, but help would be appreciated!
Thanks,
Michael Friedman
XSL-List info and archive
EasyUnsubscribe (by email)
--~----------------------------------------------------------------
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
--~--