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

Re: Re: lookup-table thoughts (was Re: matching multip

Subject: Re: 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
name number matching
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

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.