Re: [xsl] FizzBuzz in XSLT 1.0. Help with a 2.0/FXSL solution?

Subject: Re: [xsl] FizzBuzz in XSLT 1.0. Help with a 2.0/FXSL solution?
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 14 Mar 2007 23:59:06 +0530
I tried the following 2.0 stylesheet, and it works:

<xsl:stylesheet xmlns:xsl="";

<xsl:output method="text" />

<xsl:template match="fizzbuzz">
   <xsl:variable name="range.start"
select="xs:integer(substring-before(range,'-'))" />
   <xsl:variable name="range.end"
select="xs:integer(substring-after(range,'-'))" />
   <xsl:variable name="t" select="test" />
   <xsl:for-each select="$range.start to $range.end">
     <xsl:value-of select="if (((. mod $t/mod[1]/@value) =
$t/mod[1]/@test) and ((. mod $t/mod[2]/@value) = $t/mod[2]/@test))
then concat($t/mod[1], $t/mod[2]) else if ((. mod $t/mod[1]/@value) =
$t/mod[1]/@test) then $t/mod[1] else if ((. mod $t/mod[2]/@value) =
$t/mod[2]/@test) then $t/mod[2] else ." />


The input XML is:

<?xml version="1.0" encoding="UTF-8"?>
   <mod value="3" test="0">Fizz</mod>
   <mod value="5" test="0">Buzz</mod>

On 3/14/07, M. David Peterson <m.david@xxxxxxxxxx> wrote:
Hey All,

Building upon the theme provided by Dr. Kay a while back[1], I recently wrote a post that showcased how one could not only use XSLT to solve the problem, but do so in a way that provides for dynamic data evaluation in regards to the variables used, and what those variables should print out when the test evaluates to true.

My question to you all is this: Using this same premise, how would one solve this in XSLT 2.0, and in particular, given that this touches smack-dab center on the benefits that FXSL provides the XSLT developer, how one could use FXSL to solve this same problem?

I been bouncing around different ideas in my head all morning as to the best way to optimize this in XSLT 2.0/FXSL, but as of yet, haven't come up with something that I think really takes advantage of what XSLT 2.0/FXSL bring to the table. Ideas from the community at large?

Thanks in advance!


"It's a little bit odd to try and prove your point with an example that makes no use of XML input or XML output..."


M. David Peterson | |

Mukul Gandhi

Current Thread