[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: select-distinct in for-each ?
> As you guess, I have duplicates that need to > be removed -- I'm looking for a select-distinct. This is a pretty common requirement and it may be interesting to contemplate if xsl 1+n could offer some help for that. At first glance it may seem that xsl:sort could have an option that said to discard duplicates while sorting, but it probably isn't that simple. if you do <xsl:apply-templates select="x"/> <xsl:sort select="@foo"/> </xsl:apply-templates> then you get the x elements handed to you in the order controlled by their foo attribute. So, what to do if two <x foo="y">...</x> appear? The `following::x' tests as used on this thread can fairly easily give you either the first or the last such node, which means that only one <x foo="y"> gets handled, but the important thing to note is that _it makes a difference_ which one you use. The sort key may be the same but the actual x node may have different content (or different attributes) so the result tree fragment constructed will depend on which node you choose, unless the template is written to _only_ use the data that is used for xsl:sort. If their really is a requirement for finer level control over what to do in the case of repeated sort keys, it may be that there is not much more that can be done than the current method of programming the algorithm to be used. On the other hand if it turns out that in 99% of the cases, just taking the first node would be sufficient, then perhaps <xsl:sort select="@foo" discard-duplicates="true()"/> (or something) might be of help. David 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
|