[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Keys and select distinct - is that the solution ?
Dear Christian,
XSLT 2.0 has a distinct-values() function, which is useful for this kind of thing, along with its native grouping constructs. In XSLT 1.0, it's a fairly standard grouping problem. Usually we de-duplicate a set of nodes by determining which members of the set are the first (in document order) with a given value. In your case, you have to decide whether the value you want to check is the code value, or the name (if they're in a strict one-to-one relation it doesn't matter, and the value is more convenient). Keys are a very convenient way to de-duplicate when your data set is large. You can use brute XPath if not. So: <xsl:key name="manure-type-codes" match="gr:ManureTypeCode" use="."/> <xsl:key name="manure-type-names" match="gr:ManureTypeName" use="../gr:ManureTypeCode"/> <xsl:template match="gr:ManureTypeCode"> <xsl:if test="generate-id() = generate-id(key('manure-type-codes',.)[1])"> <!-- tests true only if the ManureTypeCode is the first with this value, more or less the equivalent of 'select distinct' --> <xsl:copy-of select="key('manure-type-names',.)"/> </xsl:if> </xsl:template> If the codes and names are in a one-to-many or many-to-many relation, we have to think harder. I hope this helps! Wendell At 05:55 PM 6/2/2006, you wrote: Hi experts,
|
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
|