xsl-list
[Top] [All Lists]

XSLT 2.0 function - fastest node comparison

2005-03-10 06:43:09

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[(_at_)from &lt;= $char][(_at_)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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--