Subject: RE: RE: RE: [xsl] Unexpected results when creating an SVG pie chart From: cknell@xxxxxxxxxx Date: Mon, 07 Jun 2004 14:16:53 -0400 |
Make this small change to the stylesheet below, run it against the original XML document, and tell me what value is selected for the style attribute. Change this: <xsl:template match="SITES"> <xsl:apply-templates select="SITE"/> </xsl:template> To this: <xsl:template match="SITES"> <xsl:for-each select="SITE"> <xsl:apply-templates select="."/> </xsl:for-each> </xsl:template> Make this small change to the XSLT below and run it against the original XML. Tell me what value you get for the style attribute. -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Josh Canfield <Josh.Canfield@xxxxxxxxxxxx> Sent: Mon, 7 Jun 2004 10:57:40 -0700 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: RE: RE: [xsl] Unexpected results when creating an SVG pie chart Your description of how position works in a for-each element appears to be incorrect. You seem to be saying that inside of a for-each you will always get position()=1 because you are only evaluating one node. In reality, you have selected several nodes, and the position reflects where the context node is in that list. ** From - http://www.w3.org/TR/xslt#for-each ** When the result has a known regular structure, it is useful to be able to specify directly the template for selected nodes. The xsl:for-each instruction contains a template, which is instantiated for each node selected by the expression specified by the select attribute. The select attribute is required. The expression must evaluate to a node-set. The template is instantiated with the selected node as the current node, and with a list of all of the selected nodes as the current node list. The nodes are processed in document order, unless a sorting specification is present (see [10 Sorting]). **** Josh -----Original Message----- From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] Sent: Monday, June 07, 2004 9:08 AM 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> --+-- --+------------------------------------------------------------------ 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: RE: [xsl] Unexpected results wh, Josh Canfield | Thread | RE: RE: RE: [xsl] Unexpected result, Josh Canfield |
RE: RE: [xsl] Unexpected results wh, Josh Canfield | Date | RE: RE: RE: [xsl] Unexpected result, Josh Canfield |
Month |