99 Bottles XSLT challenge
This is an open discussion with 5 replies, filed under XSLT.
Search
Take this:
<xsl:template match="/"> <xsl:call-template name="loop" /> <xsl:text>2 bottles of beer on the wall, 2 bottles of beer,</xsl:text><br /> <xsl:text>Take one down and pass it around, 1 bottle of beer on the wall.</xsl:text><br /><br /> <xsl:text>1 bottle of beer on the wall, 1 bottle of beer,</xsl:text><br /> <xsl:text>Take one down and pass it around, no bottles of beer on the wall.</xsl:text><br /><br /> <xsl:text>No more bottles of beer on the wall, no more bottles of beer.</xsl:text><br /> <xsl:text>Go to the store and buy some more, 99 bottles of beer on the wall.</xsl:text><br /><br /> </xsl:template> <xsl:template name="loop"> <xsl:param name="n" select="99"/> <xsl:value-of select="concat($n ,' bottles of beer on the wall, ', $n ,' bottles of beer,')" /><br /> <xsl:value-of select="concat('Take one down, pass it around, ', $n - 1 ,' bottles of beer on the wall.')" /><br /><br /> <xsl:if test="$n > 3"> <xsl:call-template name="loop"> <xsl:with-param name="n" select="$n - 1"/> </xsl:call-template> </xsl:if> </xsl:template>
Haha, nice challenge :)
Looks like you've won hands down Vlad!
I thought this would be a good way to show how awesome XSL is in handling recursion etc.
Neat game indeed.
Awesome! Great idea. We need to have more of these.
Create an account or sign in to comment.
Someone showed me this site today and I thought it would interesting to share.
The challenge is to write the old 99 bottles rhyme in as little code as possible.
The song's simple lyrics are as follows:
The same verse is repeated, each time with one fewer bottle. The song is completed when the singer or singers reach zero.
So, could you come up a more elegant solution then then example below?
Let the games begin!