You could do
<xsl:variable name="seq" as="xs:integer*">
<xsl:evaluate xpath="//Range ! replace(., '-', ' to ') =>
string-join(',')"/>
</xsl:variable>
<xsl:sequence select = deep-equal($seq, $seq[1] to $seq[last()])"/>
Michael Kay
Saxonica
> On 25 May 2024, at 22:02, 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
|