Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Muenchian grouping problem [Thread Next] Re: Muenchian grouping problemTo: NULL Date: 10/12/2007 11:56:00 AM
Thanks to Mukul Ghandi for this solution:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="by-location" match="location" use="./@name" />
<xsl:template match="/partners">
<locations>
<xsl:for-each select="partner/location[../@area = 'Australia']">
<xsl:if test="generate-id(.) = generate-id(key('by-location', ./
@name)[1])">
<xsl:copy-of select="." />
</xsl:if>
</xsl:for-each>
</locations>
</xsl:template>
</xsl:stylesheet>
Rob
Problem solved
On 12 okt, 11:44, "r@face" <rshwebwer...@gmail.com> wrote:
> Hi,
>
> Can someone help me out with the following:>From this XML I want unique locationnames in an area.
>
> So for the USA : Boston, New York, Chigago and Las Vegas.
> My stylesheet result in: Boston, Boston, New York, Chicaco, the
> locations in the first partner in USA.
>
> How can I get the desired result?
> Thanks in advance.
>
> Rob
>
> XML:
> <partners>
> <partner id="A1" name="name1" area="Australia">
> <location name="Adelaide" />
> <location name="Adelaide" />
> <location name="Brisbane" />
> <location name="Melbourne"/>
> </partner>
> <partner id="A2" name="name2" area="Australia">
> <location name="Adelaide" />
> <location name="Brisbane" />
> <location name="Darwin" />
> </partner>
> <partner id="A3" name="name3" area="USA">
> <location name="Boston" />
> <location name="Boston" />
> <location name="New York" />
> <location name="Chigago" />
> </partner>
> <partner id="A4" name="name4" area="USA">
> <location name="Boston" />
> <location name="New York" />
> <location name="Las Vegas" />
> </partner>
> </partners>
>
> Stylesheet:
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output version="1.0" encoding="UTF-8" indent="yes"/>
> <xsl:key name="by-location" match="//partner" use="location/@name" />
> <xsl:template match="/">
> <locations>
> <xsl:for-each select="//partner[@area = 'USA' and generate-id(.) =
> generate-id(key('by-location' , location/@name))]">
> <xsl:copy-of select="location" />
> </xsl:for-each>
> </locations>
> </xsl:template>
> </xsl:stylesheet>
>
> Result output stylesheet:
> <locations>
> <location name="Boston"/>
> <location name="Boston"/>
> <location name="New York"/>
> <location name="Chigago"/>
> </locations>
>
> Desired output:
> <locations>
> <location name="Boston" />
> <location name="New York" />
> <location name="Chigago" />
> <location name="Las Vegas" />
> </locations>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
