[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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.
')"/> <xsl:value-of select="concat(f:getBottleStr(.), ' of beer.
Take one down, pass it around,
')"/> <xsl:value-of select="concat(f:getBottleStr(. - 1), ' of beer on the wall.
')"/> </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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|