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 2:24:00 PM Barnum wrote:
> This is the XML input:
> <root>
> <foo @name="1">a</foo>
> <foo @name="1">b</foo>
> <foo @name="1">a</foo>
> <foo @name="2">c</foo>
> <foo @name="2">c</foo>
> <foo @name="2">d</foo>
> </root>
I guess
<root>
<foo name="1">a</foo>
<foo name="1">b</foo>
<foo name="1">a</foo>
<foo name="2">c</foo>
<foo name="2">c</foo>
<foo name="2">d</foo>
</root>
is more what you have.
> I expect to get only these nodes in fum:
> <foo @name="1">a</foo>
> <foo @name="1">b</foo>
You simply need to apply the predicate @name = '1' e.g.
/root/foo[@name = '1'][not(. = preceding-sibling::foo[@name = '1'])]
or in that template
<xsl:variable name="fie" select="$in/foo[@name='1']" />
<xsl:variable name="fum" select="$fie[not(. =
preceding-sibling::foo[@name = '1'])]" />
Defining a key is also easy:
<xsl:key name="k1" match="foo[@name = '1']" use="."/>
then you can use Muenchian grouping with that key.
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
