Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Filtering on Unique ID [Thread Next] Re: Filtering on Unique IDTo: NULL Date: 6/7/2004 9:57:00 AM Jeroen Hoekemeijer wrote:
> I need to convert this to the following
> <person>
> <childeren>
> <child id="1"/>
> <child id="2"/>
> </childeren>
> </person>
>
> As you can see I want to filter on ID and discard any doubles.
> Has anybody have an idea to solve this without using JavaScript within the
> XSL?
There is a classical Muenchian grouping solution:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="childKey" match="childeren/child" use="id"/>
<xsl:template match="xmlrootnode">
<person>
<childeren>
<xsl:apply-templates
select="person/childeren/child[generate-id()=generate-id(key('childKey',
id)[1])]"/>
</childeren>
</person>
</xsl:template>
<xsl:template match="child">
<child id="{id}"/>
</xsl:template>
</xsl:stylesheet>
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
