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: 9/2/2009 7:27:00 AM On 27 Aug, 15:21, Barnum <bar...@bluezone.no> wrote: > On 27 Aug, 14:23, Martin Honnen <mahotr...@yahoo.de> wrote: > > > > > > > Barnum wrote: > > > This is the XML input: > > > <root> > > > =A0 =A0<foo @name=3D"1">a</foo> > > > =A0 =A0<foo @name=3D"1">b</foo> > > > =A0 =A0<foo @name=3D"1">a</foo> > > > =A0 =A0<foo @name=3D"2">c</foo> > > > =A0 =A0<foo @name=3D"2">c</foo> > > > =A0 =A0<foo @name=3D"2">d</foo> > > > </root> > > > I guess > > > <root> > > =A0 =A0 <foo name=3D"1">a</foo> > > =A0 =A0 <foo name=3D"1">b</foo> > > =A0 =A0 <foo name=3D"1">a</foo> > > =A0 =A0 <foo name=3D"2">c</foo> > > =A0 =A0 <foo name=3D"2">c</foo> > > =A0 =A0 <foo name=3D"2">d</foo> > > </root> > > > is more what you have. > > > > I expect to get only these nodes in fum: > > > =A0 =A0<foo @name=3D"1">a</foo> > > > =A0 =A0<foo @name=3D"1">b</foo> > > > You simply need to apply the predicate @name =3D '1' e.g. > > > =A0 =A0/root/foo[@name =3D '1'][not(. =3D preceding-sibling::foo[@name = =3D '1'])] > > > or in that template > > > =A0 =A0 =A0<xsl:variable name=3D"fie" select=3D"$in/foo[@name=3D'1']" /= > > > =A0 =A0 =A0<xsl:variable name=3D"fum" select=3D"$fie[not(. =3D > > preceding-sibling::foo[@name =3D '1'])]" /> > > > Defining a key is also easy: > > =A0 =A0<xsl:key name=3D"k1" match=3D"foo[@name =3D '1']" use=3D"."/> > > then you can use Muenchian grouping with that key. > > > -- > > > =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML > > =A0 =A0 =A0 =A0http://msmvps.com/blogs/martin_honnen/ > > Thanks, that worked! > The thing I missed was to use the predicate [@name =3D '1'] also after > the preceding-sibling::foo. > > Thanks very much, this saved my day!=96 Skjul sitert tekst =96 > > =96 Vis sitert tekst =96 One follow-up, if I would want the distinct attributes (in this example distinct @names) as opposed to elements, how would the preceding-sibling predicate look? Thanks! | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
