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

Subject: RE: RE: [xsl] Unexpected results when creating an SVG pie chart
From: cknell@xxxxxxxxxx
Date: Mon, 07 Jun 2004 12:07:33 -0400
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%



Current Thread