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:31:15 -0000
On Sun, May 26, 2024 at 7:15b/AM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Another mind-blowing solution. This one from Michael Kay:
>
> <!--
>     Determine if the ranges in $seq are consecutive.
>     $seq = (0-2, 3-7, 8, 9-15) returns true
>     $seq = (0-3, 3-7, 8, 9-15) returns false
> -->
> <xsl:function name="f:isConsecutive" as="xs:boolean">
>     <xsl:param name="seq"/>
>
>     <xsl:variable name="seq-with-to" as="xs:integer*">
>         <xsl:evaluate xpath="$seq ! replace(., '-', ' to ') =>
> string-join(',')"/>
>     </xsl:variable>
>     <xsl:sequence select="deep-equal($seq-with-to, $seq-with-to[1] to
> $seq-with-to[last()])"/>
> </xsl:function>
>

Not very efficient, though.

Try it with: (1-10000000, 10000001-20000000, 20000001-30000000, 30000001)

Then run the pure XPath solution (provided earlier in this thread) - it
takes 0.0s (as per Oxygen) to execute.

The above XSLT transformation takes 5.2s (as per Oxygen) to produce the
same result.

Anyone, please try these for yourself.

Thanks,
Dimitre

Current Thread