Re: [xsl] Re: Seeking an elegant XSLT function to check that a pair of numeric ranges are consecutive

Subject: Re: [xsl] Re: Seeking an elegant XSLT function to check that a pair of numeric ranges are consecutive
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 May 2024 15:43:08 -0000
On Sat, May 25, 2024 at 2:18b/PM Dimitre Novatchev <dnovatchev@xxxxxxxxx>
wrote:

> > Recall the problem: determine if an integer range has no gaps in it.
>
> This is not the problem you provided to us.
>
> A sequence of overlapping intervals may be connected, but it violates the
> requirements for "consecutiveness".
>
>
Still this is an interesting problem in itself. Here is a pure XPath
expression that returns true when the set of segments is connected and
false otherwise:


let $ranges := /*/*/*, $d := '~',
    $starts := $ranges/xs:integer(substring-before(. || $d, $d)),
    $ends := $ranges/xs:integer(if(contains(., $d)) then substring-after(.,
$d)
                                else .),
    $min := min($starts), $max  := max($ends)
  return
    every $val in $min to $max satisfies
      some $j in 1 to count($ranges) satisfies
        $starts[$j] le $val and $ends[$j] ge $val

Thanks,
Dimitre



> Thanks,
> Dimitre
>
> On Sat, May 25, 2024 at 2:02b/PM Roger L Costello costello@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> Fantastic responses - thank you!
>>
>> Recall the problem: determine if an integer range has no gaps in it. Till
>> now, I have been thinking that the way to solve the problem is to perform
a
>> series of checks on pairs of ranges. But maybe there is a more general way
>> of looking at the problem ...
>>
>> Recall the XML document:
>>
>> <Document>
>>     <Record>
>>         <Range>0-2</Range>
>>     </Record>
>>     <Record>
>>         <Range>3-7</Range>
>>     </Record>
>>     <Record>
>>         <Range>8</Range>
>>     </Record>
>>     <Record>
>>         <Range>9-15</Range>
>>     </Record>
>> </Document>
>>
>> If we extract all the ranges, we get this sequence:
>>
>> (0-2, 3-7, 8, 9-15)
>>
>> Now the problem may be succinctly restated as:
>>
>>     Is the sequence connected?
>>
>> It seems like XSLT should provide a built-in function that evaluates a
>> sequence for connectedness and returns true (the sequence is a connected
>> sequence) or false (the sequence is not a connected sequence).
>>
>> Does looking at the problem from the perspective of evaluating the
>> connectedness of an entire sequence rather than from the perspective of
>> evaluating the connectedness of a pair of ranges ... does that provide
>> insight into a different/better way of solving the problem?
>>
>> As far as I know, XSLT does not provide a built-in function that
>> evaluates a sequence (such as the one shown above) for connectedness. If
>> XSLT did have such a function, what would be the name of the function?
>>
>> /Roger

Current Thread