|
Subject: Re: [xsl] Re: lookup-table thoughts (was Re: matching multiple times, outputting once? From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 7 Nov 2001 13:14:21 +0000 |
David,
Jeni>> I find it easier to design a tail-recursive template if I
Jeni>> imagine the equivalent loop for what I want to do, which in
Jeni>> this case would be:
>
> Jeni, this shows a serious lack of indoctrination.
You should be happy that you've finally succeeded in indoctrinating me
with tail recursion!
> Write out 1000 lines:
>
> I should understand loops as being syntax for a simple form of
> recursion.
>
> (extra bonus points awarded for using a tail recursive procedure to
> produce the text...)
<xsl:template name="writeLines">
<xsl:param name="number" select="1000" />
<xsl:param name="line">
I should understand loops as being syntax for a simple form of
recursion.
</xsl:param>
<xsl:value-of select="$line" />
<xsl:if test="$number > 1">
<xsl:call-template name="writeLines">
<xsl:with-param name="number" select="$number - 1" />
<xsl:with-param name="line" select="$line" />
</xsl:call-template>
</xsl:if>
</xsl:template>
And for Dimitre:
<xsl:template name="writeLines">
<xsl:param name="number" select="1000" />
<xsl:param name="line">
I should understand loops as being syntax for a simple form of
recursion.
</xsl:param>
<xsl:choose>
<xsl:when test="not($number mod 5)">
<xsl:call-template name="writeLines">
<xsl:with-param name="number" select="$number div 5" />
<xsl:with-param name="line"
select="concat($line, $line, $line, $line, $line)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="not($number mod 2)">
<xsl:call-template name="writeLines">
<xsl:with-param name="number" select="$number div 2" />
<xsl:with-param name="line" select="concat($line, $line)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$line" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Re: lookup-table thoughts, David Carlisle | Thread | [xsl] reliability of MSXML, Pedro Pastor |
| RE: [xsl] Transform XML to HTML tab, Johan Andersson | Date | [xsl] Question about XPATH result s, Tim Crook |
| Month |