xsl-list
[Top] [All Lists]

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

2007-03-14 11:30:15
I tried the following 2.0 stylesheet, and it works:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                      xmlns:xs="http://www.w3.org/2001/XMLSchema";
                      version="2.0">

<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 ." />
     <xsl:text>&#10;</xsl:text>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

The input XML is:

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

On 3/14/07, M. David Peterson <m(_dot_)david(_at_)mdptws(_dot_)com> 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.

http://dev.aol.com/blog/mdavidpeterson/2007/03/14/fizz-buzz-in-xslt-1.0

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!

[1] http://blogs.msdn.com/mfussell/archive/2004/05/13/130969.aspx#131098

"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:D

M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | 
http://dev.aol.com/blog/3155


--
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--