[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|