Re: [xsl] Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?

Subject: Re: [xsl] 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
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