[Home] [By Thread] [By Date] [Recent Entries]
On 2/5/07, Abel Braaksma <abel.online@xxxxxxxxx> wrote:
Andrew Welch wrote: > 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: Nice! However a couple of small problems: 2 bottles of beer on the wall.
2 bottles of beer.
Take one down, pass it around
1 bottles of beer on the wall.
^^^^^^^1 bottle of beer on the wall.
1 bottle of beer.
Take one down, pass it around
0 bottle of beer on the wall.
^^^^^^^^You just need to modify it slightly: <xsl:value-of select="for $i in reverse(1 to 3), $j in
(' on the wall.',
'. Take one down, pass it around',
' on the wall. ' ) return concat
($i - xs:integer(ends-with($j, ' ')),
' bottle', if ($i - xs:integer(ends-with($j,
' ')) = 1) then '' else 's',
' of beer', $j)"separator=" "/> which gives: 2 bottles of beer on the wall. 2 bottles of beer. Take one down, pass it around 1 bottle of beer on the wall. 1 bottle of beer on the wall. 1 bottle of beer. Take one down, pass it around 0 bottles of beer on the wall. cheers andrew
|

Cart



