3 ms·
But it is much simpler to write it in XPath (that could then be included in XSLT) for $i in 1 to 100 return if ($i mod 3 = 0 and $i mod 5 = 0) then "F
by benibela 6y ago
But it is much simpler to write it in XPath (that could then be included in XSLT)
for $i in 1 to 100
return if ($i mod 3 = 0 and $i mod 5 = 0) then "FizzBuzz"
else if ($i mod 3 = 0) then "Fizz"
else if ($i mod 5 = 0) then "Buzz"
else $i
Wrap it in string-join, if you need the output as one string with line breaks rather than a sequence list.
Although one can also write horrible clever XPath:
for $i in 1 to 100
return (("Fizz"[$i mod 3 = 0] || "Buzz"[$i mod 5 = 0])[.], $i)[1]
- zmix 6y agoUsing your solution, one may shorten the XSL-T (with XSL-T 3.0) to: <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="xsl:initial-template"> <xsl:sequence select=' for $i in 1 to 100 return (("Fizz"[$i mod 3 = 0] || "Buzz"[$i mod 5 = 0])[.], $i)[1] ' /> </xsl:template> <xsl:stylesheet> While I understand the ratio behind the article and agree, the author does not acknowledge, that XSL-T is not a "programming language" but a "templating language".