Language XSLT
Date: | 04/20/05 |
Author: | Bernd Sokolowsky |
URL: | n/a |
Comments: | 3 |
Info: | n/a |
Score: | ![]() |
<?xml version="1.0"?> <!-- XSLT version of 99 Bottles of Beer author: Bernd Sokolowsky <ulmo@garozzo.franken.de> Erlangen/Germany, 11/2001 --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:template match="/"> <xsl:call-template name="loop"/> </xsl:template> <xsl:template name="bottles"> <xsl:param name="bottles"/> <xsl:choose> <xsl:when test="$bottles = 0"> <xsl:text>no bottles</xsl:text> </xsl:when> <xsl:when test="$bottles = 1"> <xsl:text>1 bottle</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$bottles"/> <xsl:text> bottles</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="loop"> <xsl:param name="n" select="99"/> <xsl:call-template name="bottles"> <xsl:with-param name="bottles" select="$n"/> </xsl:call-template> <xsl:text> of beer on the wall,</xsl:text> <xsl:value-of select="$newline"/> <xsl:call-template name="bottles"> <xsl:with-param name="bottles" select="$n"/> </xsl:call-template> <xsl:text> of beer,</xsl:text> <xsl:value-of select="$newline"/> <xsl:text>take one down, pass it around,</xsl:text> <xsl:value-of select="$newline"/> <xsl:call-template name="bottles"> <xsl:with-param name="bottles" select="$n - 1"/> </xsl:call-template> <xsl:text> of beer on the wall.</xsl:text> <xsl:value-of select="$newline"/> <xsl:if test="$n > 1"> <xsl:value-of select="$newline"/> <xsl:call-template name="loop"> <xsl:with-param name="n" select="$n - 1"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
This code could be three times shorter if all redundant xsl:texts (what else could it be) dropped.