[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

99 bottles of beer

Subject: 99 bottles of beer
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 5 Feb 2007 11:29:47 +0000
 99 bottles of beer
After seeing M. David's post about the bottles of beer problem, I
thought about how to solve this problem using XSLT 2.0.  Here's what
came to mind first:

<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:f="f"
	exclude-result-prefixes="xs">

	<xsl:function name="f:getBottleStr" as="xs:string">
		<xsl:param name="count" as="xs:integer"/>
		<xsl:sequence select="concat($count, ' bottle', if ($count = 1) then
'' else 's ')"/>
	</xsl:function>
	
	<xsl:template match="/" name="main">
		<xsl:for-each select="reverse(1 to 99)">
			<xsl:value-of select="concat(f:getBottleStr(.), ' of beer on the
wall.&#xa;')"/>
			<xsl:value-of select="concat(f:getBottleStr(.), ' of beer.&#xa;Take
one down, pass it around,&#xa;')"/>
			<xsl:value-of select="concat(f:getBottleStr(. - 1), ' of beer on
the wall.&#xa;')"/>
		</xsl:for-each>
	</xsl:template>

</xsl:stylesheet>

This demonstrates a few nice 2.0 features: the "to" operator for 1 to
99, sequences of items, custom functions, if-then-else, strong typing
and of course it's "standalone" and doesn't require token input file.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.