Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: distinct-values work-around for Xpath 1.0 >Thread Next - Re: distinct-values work-around for Xpath 1.0 Re: distinct-values work-around for Xpath 1.0To: NULL Date: 8/27/2009 4:26:00 AM On 27 Aug, 12:47, Martin Honnen <mahotr...@yahoo.de> wrote: > Barnum wrote: > > I'm using Xpath 1.0, so I can't use 'distinct-values'. Is there a work- > > around? Alternative implementation? > > With the XML being e.g. > > <root> > =A0 =A0<foo>a</foo> > =A0 =A0<foo>b</foo> > =A0 =A0<foo>a</foo> > =A0 =A0<foo>c</foo> > =A0 =A0<foo>c</foo> > =A0 =A0<foo>d</foo> > </root> > > the XPath /root/foo[not(. =3D preceding-sibling::foo)] selects only > distinct 'foo' elements e.g. > > <foo>a</foo> > <foo>b</foo> > <foo>c</foo> > <foo>d</foo> > > If you use XPath 1.0 inside XSLT 1.0 then you can also use Muenchian > grouping to group and process only the first item in each group. > > -- > > =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML > =A0 =A0 =A0 =A0http://msmvps.com/blogs/martin_honnen/ Thanks for your reply! For me, this does not work because the nodes are in a variable, that I selected from another node-set. And my <foo> nodes do not have a common parent. I did something like this: <xsl:variable name=3D"fie" select=3D"root/foo [..some predicate here....]. Maybe I can build a new node set with a root node with the _selected_ foos beneath? And then do the preceding-sibling trick? The Muenchian approach is also difficult (impossible?) to apply, because xsl:key is a top-level node only. Again, thanks very much for your help! | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
