This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
- To: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Subject: Re: [xsl] Re: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Wed, 7 Nov 2001 16:52:01 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20011107155758.84016.qmail@web14508.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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