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
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<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/@value) = $t/mod/@test) and ((. mod $t/mod/@value) = $t/mod/@test)) then concat($t/mod, $t/mod) else if ((. mod $t/mod/@value) = $t/mod/@test) then $t/mod else if ((. mod $t/mod/@value) = $t/mod/@test) then $t/mod else ." /> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template>
<?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>
Building upon the theme provided by Dr. Kay a while back, 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 http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155
-- Regards, Mukul Gandhi