[xsl] Problems with following-sibling

Subject: [xsl] Problems with following-sibling
From: Barret Boombastic <barret@xxxxxxxxxx>
Date: Wed, 4 Jul 2007 18:10:01 +0300 (EEST)
Hi.

I'm working on a project where I have to generate a line graph (using SVG)
from an XML-file generated by a program.
For example the XML-file can look like this (generated by the program):

<cars>
     <cartype>Sports cars</cartype>
     <active>true</active>
      <car>
        <name>Ferrari Enzo</name>
        <price>750000</price>
        <date>2007-05-21</date>
        <volume>15</volume>
      </car>
      <car>
        <name>Ferrari Enzo</name>
        <price>750000</price>
        <date>2007-06-13</date>
        <volume>19</volume>
      </car>
      <car>
        <name>Porsche Carrera GT</name>
        <price>600000</price>
        <date>2007-06-13</date>
        <volume>11</volume>
      </car>
      <car>
        <name>Ferrari Enzo</name>
        <price>750000</price>
        <date>2007-06-22</date>
        <volume>13</volume>
      </car>
      <car>
        <name>Bugatti Veyron</name>
        <price>15000000</price>
        <date>2007-06-22</date>
        <volume>4</volume>
      </car>
</cars>

The graph's y-axis holds the volume amount and the x-axis holds the date.
The idea is that the graph generates different color line graphs based on the
name of the car, so to address this I've written an XSLT-file.

Here is a snippet from the XSL-file:

<g transform="translate(60,400)">
 <xsl:for-each select="car[name = 'Ferrari Enzo']">
 <xsl:variable name="nextVolume" select="following-sibling::car/volume"/>
   <line x1="{position()*15}" y1="-{volume} " x2="{(position()+1)*15}"
y2="-{$nextVolume}" style="stroke: red;"/>
</xsl:for-each>
</g>

Here is the problem: When I try to get the "nextVolume" with
"following-sibling::car/volume" it works fine if the next car is a Ferrari,
but as you can see the cars can be at any order in the xml-file.
I've selected specifically the Ferraris with the "for-each", but how do I
select the following sibling so that it also matches the car name?
The <xsl:variable name="nextVolume" select="following-sibling::car/volume"/>
itself doesn't work since it doesn't seem to skip the Porsche's value, which
is between the Ferraris. Any help is greatly appreciated.

...................................................................
Luukku Plus paketilla pddset eroon tila- ja turvallisuusongelmista.
Hanki Luukku Plus ja helpotat eldmddsi. http://www.mtv3.fi/luukku

Current Thread