Skip to content

Instantly share code, notes, and snippets.

@JustinPealing
Last active September 30, 2016 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinPealing/6f619a23729720a9c14d9917201028c8 to your computer and use it in GitHub Desktop.
Save JustinPealing/6f619a23729720a9c14d9917201028c8 to your computer and use it in GitHub Desktop.
FizzBuzz in XSLT - run against any XML file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:call-template name="FizzBuzz">
<xsl:with-param name="i" select="1" />
</xsl:call-template>
</xsl:template>
<xsl:template name="FizzBuzz">
<xsl:param name="i" />
<xsl:choose>
<xsl:when test="($i mod 3) = 0 and ($i mod 5) = 0">FizzBuzz&#xa;</xsl:when>
<xsl:when test="$i mod 3 = 0">Fizz&#xa;</xsl:when>
<xsl:when test="$i mod 5 = 0">Buzz&#xa;</xsl:when>
<xsl:otherwise><xsl:value-of select="$i" /><xsl:text>&#xa;</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:if test="$i &lt; 100">
<xsl:call-template name="FizzBuzz">
<xsl:with-param name="i" select="$i + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment