This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Selecting distinct values based on an attribute
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Re: Selecting distinct values based on an attribute
- From: "Yang" <sfyang at unisvr dot net dot tw>
- Date: Wed, 26 Sep 2001 11:14:03 +0800
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi, Perry,
For selecting distinct values , key and Muenchian method is one of reliable
approachs, especially when dealing with a large set of data in xml file.
Something like these;
<!-- define key using facilitytype attribute -->
<xsl:key name="facilityAtrr" match="facilities" use="@facilitytype"/>
<!-- define distinct set of facilities based on facility attributes -->
<xsl:variable name="facilityList"
select="//facilities[count(.|key('facilityAtrr', @facilitytype)[1]) = 1]"/>
<!-- data processing such as sorting,ouput...-->
<xsl:template match="/">
<xsl:for-each select="$facilityList">
<xsl:sort select="@facilitytype"/>
<xsl:value-of select="@facilitytype"/>
</xsl:for-each>
</xsl:template>
Hope it is useful to your applications.
Cheers,
Sun-fu Yang,
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list