I've got some XML that looks a little like this.
<Dealer>
<Vehicle>
<Model>KA</Model>
<Series>Type A</Series>
<Price>1000.00</Price>
</Vehicle>
<Vehicle>
<Model>KA</Model>
<Series>Type C</Series>
<Price>1400.00</Price>
</Vehicle>
<Vehicle>
<Model>KA</Model>
<Series>Type A</Series>
<Price>1100.00</Price>
</Vehicle>
<Vehicle>
<Model>FOCUS</Model>
<Series>Type B</Series>
<Price>5000.00</Price>
</Vehicle>
<Vehicle>
<Model>FIESTA</Model>
<Series>Type A</Series>
<Price>6000.00</Price>
</Vehicle>
</Dealer>
What I'm trying to do is select 1 specific Model (EG: KA) then group Series into a distinct list (no duplicates), count how many there are within the Series, but only display the cheapest, using XSLT 1.0.
EG. My out put would look something like this:
KA Type A 2 in stock starting from 1000.00
KA Type C 1 in stock starting from 1400.00
I've been looking at the Muenchian Method of grouping, but can't seem to marry it up with the other things I'm trying to achieve.
This is my attempt below. My thinking was to then just display the first item in each group, IE. the cheapest, and somehow do a count of each group.
<xsl:strip-space elements="*"/>
<xsl:template match="/Dealer">
<xsl:apply-templates select="Vehicle[Model = 'KA']"/>
</xsl:template>
<xsl:key name="fSeries" match="Vehicle" use="Series" />
<xsl:template match="Vehicle">
<xsl:for-each select="Vehicle[count(. | key('fSeries', Series)[1]) = 1]">
<xsl:sort select="Price" />
<xsl:for-each select="key('fSeries', Series)">
<xsl:sort select="Price" />
<xsl:value-of select="Model" /> <xsl:value-of select="Series" /> <xsl:value-of select="Price" /><br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
Would be very great of any help. Thanks.