I have an xml file like this :
<products>
<cars>
<car>
<brand>Audi</brand>
<type>S3</type>
<attribs>
<attrib>
<color>1</color>
<price>45000</price>
</attrib>
<attrib>
<color>2</color>
<price>75000</price>
</attrib>
<attrib>
<color>4</color>
<price>35000</price>
</attrib>
</attribs>
</car>
<!-- Many cars following -->
</cars>
<colors>
<color>
<id>1</id>
<shortdesc>Blue</shortdesc>
<description>Blue Lagoon</description>
</color>
<color>
<id>2</id>
<shortdesc>Red</shortdesc>
<description>Red Sport</description>
</color>
<color>
<id>3</id>
<shortdesc>Green</shortdesc>
<description>Green Forest</description>
</color>
<color>
<id>4</id>
<shortdesc>Yellow</shortdesc>
<description>Yellow</description>
</color>
<!-- many colors -->
</colors>
</products>
I am converting this XML in an excel cross-sheet where I have the cars on the vertical and the colors in horizontal like this:
Brand / Model 1/Blue 2/Red 3/Green 4/Yellow
Audi S3 45000 75000 - 35000
Audi S6 66000 68000 59000 -
Jaguar x-type 98000 - 99500 -
and the xslt looks like:
<ss:Table>
<ss:Row>
<!-- This is the header row -->
<ss:Cell>
<ss:Data ss:Type="String">Brand / Model</ss:Data>
</ss:Cell>
<xsl:for-each select="colors/color">
<ss:Cell>
<ss:Data ss:Type="String">
<xsl:value-of select="id"/>/<xsl:value-of select="shortdesc"/>
</ss:Data>
</ss:Cell>
</xsl:for-each>
</ss:Row>
<xsl:for-each select="cars/car">
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">
<xsl:value-of select="brand"/> <xsl:value-of select="type"/>
</ss:Data>
</ss:Cell>
<xsl:for-each select="attribs/attrib">
<!-- I Know this is incorrect, but what to put in the if ? -->
<xsl:if test="color = /colors/color/id">
<ss:Cell>
<ss:Data ss:Type="String">
<xsl:value-of select="price"/>
</ss:Data>
</ss:Cell>
</xsl:if>
<xsl:if test="color != /colors/color/id">
<ss:Cell>
<ss:Data ss:Type="String">-</ss:Data>
</ss:Cell>
</xsl:if>
</xsl:for-each>
</ss:Row>
</xsl:for-each>
</ss:Table>
I am looking for the way to compare / write the price in the right column.
The template is referencing the node /products in order to be able to access both cars and colors. A possible way is to create an array in the same time I write the colors in the header and to compare with it when I process the cars; Is this a possible way or something better is possible?
Another detail: I cannot change the XML as it is already designed like this (in fact it is not cars I am processing, but just to make it simpler)