Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language XSLT

Date:04/20/05
Author:Bernd Sokolowsky
URL:n/a
Comments:3
Info:n/a
Score: (3.03 in 129 votes)
<?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 &gt; 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

Alternative Versions

Comments

>>  deltaflight said on 11/29/06 16:13:20

deltaflight Almos as big as the brainfuck language version :)

>>  Ilya Kasnacheev said on 12/18/08 14:16:06

Ilya Kasnacheev Why are you misusing the language in such a horrible way?
This code could be three times shorter if all redundant xsl:texts (what else could it be) dropped.

>>   hiphone said on 09/20/10 08:18:40

   hiphone I like this website very much<a href=“http://www.efox-shop.com/”>Sciphones i68</a>&#65292;<a href=“www.efox-shop.com/index.php/cPath/5_35”> Ciphone </a>.

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!

Name:

eMail:

URL:

Security Code:
  
Comment: