3 ms·
The XSLT FizzBuzz example doesn't seem written "in jest", except perhaps in the loose sense of making a point about Turing completeness. It's as straightforwar
by HelloNurse 6y ago
The XSLT FizzBuzz example doesn't seem written "in jest", except perhaps in the loose sense of making a point about Turing completeness.
It's as straightforward and readable as XSLT allows, leaving only a small refactoring on the table (putting "
" into an unconditional output instead of repeating it in the four cases).
- benibela 6y agoBut 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".