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

Re: Re: Re: Re: lookup-table thoughts (was Re: matchin

Subject: Re: Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 7 Nov 2001 16:52:01 +0000
primes after 1000
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


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.