[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: RE: Unexpected results when creating an SVG pie ch

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

I am getting a purple slice at 25%



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.