[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Andrew Welch wrote:
Hi Andrew,
let me try what came to mind second ;)
Here's my go on it in a single XPath statement. A bit less well-suited for educational purposes. It shows nested for-loops in XPath, casting, use of sequences+separator and some ways how not to code (it is exactly an example of good programming practice ;)
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text" />
<xsl:template match="/" name="main">
<xsl:value-of select="
for $i in reverse(1 to 99)
return for $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 = 1) then '' else 's',
' of beer', $j)
" separator=" "/>
</xsl:template>
</xsl:stylesheet>
Re: [xsl] 99 bottles of beer
Subject: Re: [xsl] 99 bottles of beer From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Mon, 05 Feb 2007 13:47:01 +0100 |
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:
Hi Andrew,
let me try what came to mind second ;)
Here's my go on it in a single XPath statement. A bit less well-suited for educational purposes. It shows nested for-loops in XPath, casting, use of sequences+separator and some ways how not to code (it is exactly an example of good programming practice ;)
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text" />
<xsl:template match="/" name="main">
<xsl:value-of select="
for $i in reverse(1 to 99)
return for $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 = 1) then '' else 's',
' of beer', $j)
" separator=" "/>
</xsl:template>
</xsl:stylesheet>
Cheers, -- Abel Braaksma http://www.nuntia.nl
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] 99 bottles of beer, Andrew Welch | Thread | Re: [xsl] 99 bottles of beer, Andrew Welch |
Re: [xsl] Is there a way of obfusca, Mukul Gandhi | Date | Re: [xsl] 99 bottles of beer, Andrew Welch |
Month |