1<?xml version="1.0"?> 2 3<!-- bottles of beer by Cyrus Dolph May 16, 2000 --> 4 5<!-- input template of form: <bottles>99</bottles> --> 6 7<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 8 9 <xsl:output method="text" encoding="utf-8"/> 10 11 <xsl:template name="bottles"> 12 <xsl:param name="bottles"/> 13 <xsl:choose> 14 <xsl:when test="$bottles = 1"> 15 <xsl:text>1 bottle</xsl:text> 16 </xsl:when> 17 <xsl:otherwise> 18 <xsl:value-of select='concat ($bottles, " bottles")'/> 19 </xsl:otherwise> 20 </xsl:choose> 21 </xsl:template> 22 23 <xsl:template name="verse"> 24 <xsl:param name="bottles"/> 25 <xsl:choose> 26 <xsl:when test="$bottles = 0"> 27 <xsl:text>0 bottles of beer on the wall, 280 bottles of beer! 29Go into town, buy a new round 30Get some more bottles of beer on the wall! 31</xsl:text> 32 </xsl:when> 33 <xsl:otherwise> 34 <xsl:call-template name="bottles"> 35 <xsl:with-param name="bottles" select="$bottles"/> 36 </xsl:call-template> 37 <xsl:text> of beer on the wall, 38</xsl:text> 39 <xsl:call-template name="bottles"> 40 <xsl:with-param name="bottles" select="$bottles"/> 41 </xsl:call-template> 42 <xsl:text> of beer! 43Take one down, pass it around; 44</xsl:text> 45 <xsl:call-template name="bottles"> 46 <xsl:with-param name="bottles" select="$bottles - 1"/> 47 </xsl:call-template> 48 <xsl:text> of beer on the wall. 49 50</xsl:text> 51 <xsl:call-template name="verse"> 52 <xsl:with-param name="bottles" select="$bottles - 1"/> 53 </xsl:call-template> 54 </xsl:otherwise> 55 </xsl:choose> 56 </xsl:template> 57 58 <xsl:template match="/"> 59 <xsl:call-template name="verse"> 60 <xsl:with-param name="bottles" select="/bottles"/> 61 </xsl:call-template> 62 </xsl:template> 63</xsl:stylesheet> 64 65