ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
by Jeni Tennison other posts by this author
Nov 7 2001 4:52PM messages near this date
Re: [xsl] Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once? | [xsl] Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
Dimitre,

>  However, in the worst-case scenario, when the number of times must
>  be not 1000 but a big prime number

You're right; asking for 1009 repetitions is just the kind of thing
that David would do.

Jeni

P.S. Calculating the next prime after 1000 made me write the following
(infinitely recursive) templates for generating prime numbers:

<xsl:template name="findPrimes"> 
  <xsl:param name="prime" select="11" /> 
  <xsl:param name="primes" select="'2/3/5/7/'" /> 
  <xsl:variable name="divisor"> 
    <xsl:call-template name="testPrime"> 
      <xsl:with-param name="prime" select="$prime" /> 
      <xsl:with-param name="primes" select="$primes" /> 
    </xsl:call-template> 
  </xsl:variable> 
  <xsl:choose> 
    <xsl:when test="string($divisor)"> 
      <xsl:call-template name="findPrimes"> 
        <xsl:with-param name="prime" select="$prime + 2" /> 
        <xsl:with-param name="primes" select="$primes" /> 
      </xsl:call-template> 
    </xsl:when> 
    <xsl:otherwise> 
      <xsl:message> <xsl:value-of select="$prime" /></xsl:message>
      <xsl:call-template name="findPrimes"> 
        <xsl:with-param name="prime" select="$prime + 2" /> 
        <xsl:with-param name="primes"
                        select="concat($primes, $prime, '/')" /> 
      </xsl:call-template> 
    </xsl:otherwise> 
  </xsl:choose> 
</xsl:template> 

<xsl:template name="testPrime"> 
  <xsl:param name="prime" /> 
  <xsl:param name="primes" /> 
  <xsl:variable name="divisor" select="substring-before($primes, '/')" /> 
  <xsl:choose> 
    <xsl:when test="($divisor * $divisor) >  $prime" />
    <xsl:when test="not($prime mod $divisor)"> 
      <xsl:value-of select="$divisor" /> 
    </xsl:when> 
    <xsl:otherwise> 
      <xsl:call-template name="testPrime"> 
        <xsl:with-param name="prime" select="$prime" /> 
        <xsl:with-param name="primes"
                        select="substring-after($primes, '/')" /> 
      </xsl:call-template> 
    </xsl:otherwise> 
  </xsl:choose> 
</xsl:template> 

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Thread:
Dimitre Novatchev
Jeni Tennison
Dimitre Novatchev
David Carlisle
Jeni Tennison

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved