RE: RE: [xsl] Unexpected results when creating an SVG pie chart

Subject: RE: RE: [xsl] Unexpected results when creating an SVG pie chart
From: "Christopher Jacob" <chris.jacob@xxxxxxxxxxxxx>
Date: Mon, 7 Jun 2004 12:17:56 -0400
Thank you for your help. I will start working on an implementation not using
the <xsl:for-each>.

To answer your question, I get the following output... (although only the
purple slice is displayed) 

I know this isn't a SVG list, so please nobody take offence. I am just
looking for suggestions.

Thanks

~c

---svg---
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns:xlink="http://www.w3.org/1999/xlink"; viewbox="0 0 500 500"
height="500" width="500">
<path style="fill:RED;stroke:black;stroke-width:1;
fillrule:evenodd;stroke-linejoin:bevel;"
transform="translate(150,150)rotate(270)" d="M 100 0 A 100 100 0 0 1
12.533323356430447 99.21147013144778 L 0 0 Z"/>
<text style="text-anchor:middle" transform="translate(150,150) "
x="46.29183057265562" y="-52.50777487413218">23%</text>23<path
style="fill:YELLOW;stroke:black;stroke-width:1;
fillrule:evenodd;stroke-linejoin:bevel;"
transform="translate(150,150)rotate(270)" d="M 100 0 A 100 100 0 0 1
72.89686274214117 68.45471059286885 L 0 0 Z"/>
<text style="text-anchor:middle" transform="translate(150,150) "
x="25.76871868792744" y="-65.0843540121776">12%</text>12<path
style="fill:GREEN;stroke:black;stroke-width:1;
fillrule:evenodd;stroke-linejoin:bevel;"
transform="translate(150,150)rotate(270)" d="M 100 0 A 100 100 0 0 1
24.868988716485497 96.85831611286311 L 0 0 Z"/>
<text style="text-anchor:middle" transform="translate(150,150) "
x="42.90349375570834" y="-55.31085086629834">21%</text>21<path
style="fill:BLUE;stroke:black;stroke-width:1;
fillrule:evenodd;stroke-linejoin:bevel;"
transform="translate(150,150)rotate(270)" d="M 100 0 A 100 100 0 0 1
36.81245526846781 92.97764858882513 L 0 0 Z"/>
<text style="text-anchor:middle" transform="translate(150,150) "
x="39.345836449649134" y="-57.895640199219336">19%</text>19<path
style="fill:PURPLE;stroke:black;stroke-width:1;
fillrule:evenodd;stroke-linejoin:bevel;"
transform="translate(150,150)rotate(270)" d="M 100 0 A 100 100 0 0 1
0.000000000000006123233995736766 100 L 0 0 Z"/>
<text style="text-anchor:middle" transform="translate(150,150) "
x="49.497474683058314" y="-49.497474683058336">25%</text>25</svg>

--/svg--

-----Original Message-----
From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] 
Sent: Monday, June 07, 2004 12:08 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: RE: [xsl] Unexpected results when creating an SVG pie chart

Taking a look at your XSLT, I thought that the only color you would get is
RED. That's because in a <xsl:for-each> construct, there is exactly one node
for each iteration. That means that the position() of that node will always
be 1. Therefor you should only get the color that matches position()=1.

Look at this stripped-down stylesheet. It doesn't use <xsl:for-each> and
thus preserves the orginal position() values for each SITE.:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="SITES">
    <xsl:apply-templates select="SITE"/>
  </xsl:template>

  <xsl:template match="SITE">
    <xsl:variable name="color">
      <xsl:choose>
        <xsl:when test="position()=1">RED</xsl:when>
        <xsl:when test="position()=2">YELLOW</xsl:when>
        <xsl:when test="position()=3">GREEN</xsl:when>
        <xsl:when test="position()=4">BLUE</xsl:when>
        <xsl:when test="position()=5">PURPLE</xsl:when>
        <xsl:when test="position()=6">SILVER</xsl:when>
        <xsl:otherwise>BLACK</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="position" select="position()"/>
    <path style="fill:{$color}"><xsl:value-of select="@NAME"
/>--<xsl:value-of select="position()" /></path>
  </xsl:template>

</xsl:stylesheet>

Still, that doesn't answer the question of how you are getting PURPLE when
it should be RED. 
When you process your transformation, does the SVG file have the the other
slices and they simply don't appear when viewed with the SVG viewer, or are
they not in the SVG file?

There are probably other things going wrong, but the misuse of
<xsl:for-each> is a hallmark of programmers new to XSLT.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Christopher Jacob <chris.jacob@xxxxxxxxxxxxx>
Sent:     Mon, 7 Jun 2004 11:45:17 -0400
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  RE: [xsl] Unexpected results when creating an SVG pie chart

I am getting a purple slice at 25%



--+------------------------------------------------------------------
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@xxxxxxxxxxxxxxxxxxxxxx>
--+--




Current Thread