[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSLT 2.0 function - fastest node comparison

Subject: RE: XSLT 2.0 function - fastest node comparison
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 10 Mar 2005 15:09:24 -0000
xslt node comparison
You can always replace

  if (EXP) then true() else false()

by 

  boolean(EXP)

or in this case 

  exists(EXP)

If there are many ranges and you need it to go at better than linear speed,
you could code a binary-chop. I think Dimitre has done this in the past, I
don't know if it's available in packaged form.

You could experiment to see if reversing the conditions:

$ranges/range[@to &gt;=$char][@from &lt;= $char]

is any faster: this will only do one test on the ranges that are too low,
rather than two (assuming that Saxon searches in forwards order, which it
does). Still linear, but potentially up to twice the speed.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: Andrew Welch [mailto:ajwelch@xxxxxxxxxxxxxxx] 
> Sent: 10 March 2005 13:43
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XSLT 2.0 function - fastest node comparison
> 
> 
> I'm checking if a number exists within a set of ranges.  The 
> ranges are
> stored as a variable:
> 
> <xsl:variable name="ranges">
>   <range from="988" to="989"/>
>   <range from="1008" to="1009"/>
>   <range from="1014" to="1014"/>
>   <range from="1025" to="1036"/>
>   <range from="1038" to="1103"/>
>   <range from="1105" to="1116"/>
>   <range from="1118" to="1119"/>
>   <range from="4150" to="4150"/>
>   <range from="8194" to="8197"/>
>   ...
> </xsl:variable>
> 
> I've written a function that accepts an integer and returns true or
> false if the number exists within one of the ranges:
> 
> <xsl:function name="f:isInRange" as="xs:boolean">
>   <xsl:param name="char" as="xs:integer"/>
>   <xsl:sequence select="if ($ranges/range[@from &lt;= $char][@to &gt;=
> $char])
>                         then true()
>                         else false()"/>
> </xsl:function>
> 
> 
> -Is there a better way of writing this?
> 
> -How efficient is the test?  Does it check each <range> element
> sequentially in document order?
> 
> thanks
> andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.