[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Only first rows (after the sort)
Dennis,
As you say, this is a de-duplicating problem; I'd use keys to achieve it (an approach that has the virtue of scalability). In this case it has to be a "compound key" constituted of two values, namely the category and year of each example, but that's not too hard: <xsl:key name="unique-examples" match="example" use="concat(category, year)"/> Then iterate through your examples: <xsl:apply-templates select="//example"> <xsl:sort select="category"/> <xsl:sort select="year"/> <!-- if your data is already sorted, or you don't care, you can skip this --> </xsl:apply-templates/> and for each one, test to see if it's the first one with its category-year combination: <xsl:template match="example"> <xsl:if test="generate-id() = generate-id(key('unique-examples',concat(category,year)))"> <!-- this idiom is called 'Muenchian grouping', after Steve Muench, who first figured out how to use keys to de-duplicate --> do your stuff here </xsl:if> </xsl:template> As you might guess by noticing that de-duplicating subsumes grouping, in XSLT 2.0 you can use grouping constructs to achieve the same thing much more nicely. Cheers, Wendell At 10:22 AM 8/15/2006, you wrote: Hi,
|
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
|