|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Determining uniqueness based on mulitple element v
Hello Tim,
the error is in your for-each loop. You use the != operator instead of not(). preceding-sibling::car/make != 'Dodge' is true, if there exists *one* <car>, which *is not* a Dodge. not(preceding-sibling::car/make = 'Dodge') is true if there exists *no* car, which *is* a Dodge. Furthermore there is the problem that the comparisons for make, model and year can be done to different cars. In the following example car 3 will be filtered out, because a car exists with the same make and model and another one with the same year: <car> <make>Chevy</make> <model>Malibu</model> <year>1985</year> </car> <car> <make>Dodge</make> <model>Charger</model> <year>1979</year> </car> <car> <make>Chevy</make> <model>Malibu</model> <year>1979</year> </car> Your code corrected and optimized can look like: <xsl:for-each select="carlist/dealership"> <xsl:for-each select="car"> <xsl:if test="not(preceding-sibling::car[make = current()/make and model = current()/model and year = current()/year])"> <tr> <td> <xsl:if test="position() = 1"> <xsl:value-of select="../@name"/> </xsl:if> </td> <td><xsl:value-of select="make"/></td> <td><xsl:value-of select="model"/></td> <td><xsl:value-of select="year"/></td> </tr> </xsl:if> </xsl:for-each> </xsl:for-each> I prefer the grouping via keys: <xsl:key name="cars" match="car" use="concat(../@name, make, model, year)"/> and later in the template: <xsl:for-each select="carlist/dealership">
<xsl:for-each select="car[generate-id() = generate-id(key('cars',
concat(../@name, make, model, year)))]">
<tr>
<td>
<xsl:if test="position() = 1">
<xsl:value-of select="../@name"/>
</xsl:if>
</td>
<td><xsl:value-of select="make"/></td>
<td><xsl:value-of select="model"/></td>
<td><xsl:value-of select="year"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>This is mostly simpler and faster. Regards, Joerg XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








