Subject: Re: [xsl] 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 17:38:26 -0000 |
> The requirement asked for elegance, not efficiency. > > And this is the way we identify new optimization opportunities: > > (a) (1 to n, n+1 to m) ==> 1 to m. > > (b) deep-equal(a to b, x to y) ==> a=x and b=y. Thanks, and I am glad to have contributed something for optimizing Saxon. Still, isn't it a better choice to write code that will not rely on a particular optimizer and just be ... simple and efficient? As for "elegance", our own definitions may be subjective and biased. One well-known principle is KISS and I often find that compliance with this principle is well-correlated with "elegance". Thanks, Dimitre On Sun, May 26, 2024 at 9:53b/AM Michael Kay mike@xxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > The requirement asked for elegance, not efficiency. > > And this is the way we identify new optimization opportunities: > > (a) (1 to n, n+1 to m) ==> 1 to m. > > (b) deep-equal(a to b, x to y) ==> a=x and b=y. > > MK > > On 26 May 2024, at 16:31, Dimitre Novatchev dnovatchev@xxxxxxxxx < > xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > > > 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 > > > > > > > > > >> >> >> > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by > email) > > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by > email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Seeking an elegant XSLT f, Michael Kay mike@xxx | Thread | [xsl] [ANN] Balisage 2024: Call for, B Tommie Usdin btusd |
Re: [xsl] Seeking an elegant XSLT f, Michael Kay mike@xxx | Date | [xsl] [ANN] Balisage 2024: Call for, B Tommie Usdin btusd |
Month |