Last active
September 30, 2016 10:02
-
-
Save JustinPealing/6f619a23729720a9c14d9917201028c8 to your computer and use it in GitHub Desktop.
FizzBuzz in XSLT - run against any XML file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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
</xsl:when> | |
<xsl:when test="$i mod 3 = 0">Fizz
</xsl:when> | |
<xsl:when test="$i mod 5 = 0">Buzz
</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$i" /><xsl:text>
</xsl:text></xsl:otherwise> | |
</xsl:choose> | |
<xsl:if test="$i < 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