[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Grouping problem - Duplicates

Subject: RE: Grouping problem - Duplicates
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 30 Apr 2004 13:37:53 +0100
xsl sort duplicates
> Thanks for the info, I have read that article before asking 
> my question.

OK, you said you were a beginner, and I made the mistake of believing you.

I'm afraid this now fails my one-minute test: if I don't understand the
problem after staring at it for a minute, I leave it to someone else. Sorry!

Michael Kay


> Still, I need help. I am not sure that what I want to get as 
> output can be 
> done in one stylesheet (without first creating a sorted XMl 
> output to be 
> processed with a different stylesheet).
> 
> The structure of the XML file is of two "foreign"groups, <Area> and 
> <SalesPeople>, yet the grouping of the 2nd level sort, from 
> <salesPeople>, 
> depends on the node names from <Area>.
> 
> Sarah
> 
> Here is the question again:
> 
> ---- Company.xml ------
> 
> <Company>
>          <Suppliers>
>                  <Area>
>                          <North>Supp 1 Nor</North>
>                          <South>Supp 1 Sou</South>
>                          <Center>Supp 1 Cntr</Center>
>                          <North>Supp 2 Nor</North>
>                          <North>Supp 3 Nor</North>
>                          <South>Supp 2 Sou</South>
>                          <South>Supp 3 Sou</South>
>                          <Center>Supp 2 Cntr</Center>
>                          <Center>Supp 3 Cntr</Center>
>                          <North>Smith Suppliers LTD.</North>
>                          <South>Smith Suppliers LTD.</South>
>                          <Center>Sundance suppliers Cntr</Center>
>                  </Area>
>                  <SalesPeople>
>                          <SalesPerson>
>                                  <Name>
>                                          <LastName>lName Supp 
> 1</LastName>
>                                          <FirstName>John</FirstName>
>                                  </Name>
>                                  <Title>Manager</Title>
>                                  <Supplier>Supp 1 Nor</Supplier>
>                                  <Supplier>Supp 1 Sou</Supplier>
>                                  <Supplier>Supp 1 Cntr</Supplier>
>                                  <Supplier>Supp 2 Cntr</Supplier>
>                                  <Supplier>Supp 3 Cntr</Supplier>
>                                  <Supplier>Smith Suppliers 
> LTD.</Supplier>
>                                  <Supplier>Smith Suppliers 
> LTD.</Supplier>
>                                  <Supplier>Sundance suppliers 
> Cntr</Supplier>
>                          </SalesPerson>
>                          <SalesPerson>
>                                  <Name>
>                                          <LastName>lName Supp 
> 2</LastName>
>                                          <FirstName>Kathy</FirstName>
>                                  </Name>
>                                  <Title>CEO</Title>
>                                  <Supplier>Supp 2 Nor</Supplier>
>                                  <Supplier>Supp 2 Sou</Supplier>
>                                  <Supplier>Supp 2 Cntr</Supplier>
>                                  <Supplier>Supp 1 Cntr</Supplier>
>                                  <Supplier>Supp 2 Cntr</Supplier>
>                                  <Supplier>Supp 3 Cntr</Supplier>
>                                  <Supplier>Smith Suppliers 
> LTD.</Supplier>
>                          </SalesPerson>
>                          <SalesPerson>
>                                  <Name>
>                                          <LastName>lName Supp 
> 3</LastName>
>                                          <FirstName>Dan</FirstName>
>                                  </Name>
>                                  <Title>Dr.</Title>
>                                  <Supplier>Supp 3 Nor</Supplier>
>                                  <Supplier>Supp 3 Sou</Supplier>
>                                  <Supplier>Supp 3 Cntr</Supplier>
>                                  <Supplier>Supp 1 Cntr</Supplier>
>                                  <Supplier>Supp 2 Cntr</Supplier>
>                                  <Supplier>Supp 3 Cntr</Supplier>
>                                  <Supplier>Smith Suppliers 
> LTD.</Supplier>
>                                  <Supplier>Smith Suppliers 
> LTD.</Supplier>
>                                  <Supplier>Sundance suppliers 
> Cntr</Supplier>
>                          </SalesPerson>
>                          <SalesPerson>
>                                  <Name>
>                                          <LastName>lName 
> Apprentice</LastName>
>                                          <FirstName>George</FirstName>
>                                  </Name>
>                                  <Title>Apprentice</Title>
>                                  <Supplier>Supp 3 Nor</Supplier>
>                          </SalesPerson>
>                          <SalesPerson>
>                                  <Name>
>                                          <LastName>lName 
> Samuel</LastName>
>                                          <FirstName>Dave</FirstName>
>                                  </Name>
>                                  <Title>Developer</Title>
>                                  <Supplier>Supp 3 Nor</Supplier>
>                                  <Supplier>Supp 3 Sou</Supplier>
>                                  <Supplier>Supp 3 Cntr</Supplier>
>                                  <Supplier>Supp 1 Cntr</Supplier>
>                                  <Supplier>Supp 2 Cntr</Supplier>
>                          </SalesPerson>
>                  </SalesPeople>
>          </Suppliers>
> </Company>
> 
> 
> I would like to see the following output:
> 
> 
> 
> Sales People by Areas
> 
> 
> 
> 
> Center
> 
> Dave lName Samuel
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> 
> 
> 
> North
> 
> John lName Supp 1
> Kathy lName Supp 2
> George lName Apprentice
> Dave lName Samuel
> Dan lName Supp 3
> 
> 
> 
> South
> 
> John lName Supp 1
> Kathy lName Supp 2
> Dave lName Samuel
> Dan lName Supp 3
> 
> 
> But I get:
> 
> 
> 
> 
> Sales People by Areas
> 
> 
> 
> 
> 
> Center
> 
> Dave lName Samuel
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> Dave lName Samuel
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> Dave lName Samuel
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> John lName Supp 1
> Dan lName Supp 3
> 
> 
> 
> North
> 
> John lName Supp 1
> Kathy lName Supp 2
> George lName Apprentice
> Dave lName Samuel
> Dan lName Supp 3
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> 
> 
> 
> South
> 
> John lName Supp 1
> Kathy lName Supp 2
> Dave lName Samuel
> Dan lName Supp 3
> John lName Supp 1
> Kathy lName Supp 2
> Dan lName Supp 3
> 
> This is the stylesheet I used (called: sales_by_area.xsl):
> 
> <xsl:key name="areas" match="//Area/*" use="name()"/>
> <xsl:key name="supplier-list" match="SalesPerson" use="Supplier"/>
> <xsl:key name="fullName" match="SalesPerson" use="Name"/>
> 
> <xsl:template match="/">
>          <html>
>          <head>
>                  <meta http-equiv="content-type" 
> content="text/html" />
>                  <meta name="description" content="Suppliers by Sales 
> People" />
>                  <link  href="text.css" rel="stylesheet" 
> type="text/css" />
>                  <title>Your company</title>
>          </head>
>          <body>
>                  <h1>Sales People by Areas <br /></h1>
>                  <xsl:for-each 
> select="//Area/*[generate-id(.)=generate-id(key('areas', name()))]">
>                          <xsl:sort select="key('areas', name())"/>
>                          <h2><xsl:value-of select="name()"/></h2>
>                          <xsl:for-each select="key('areas', name())">
>                                  <xsl:sort 
> select="key('areas', text())"/>
>                                  <xsl:variable name="supplier_name" 
> select="text()">
>                                  </xsl:variable>
>                                  <xsl:variable name="area_name" 
> select="name()">
>                                  </xsl:variable>
> 
>                                  <xsl:for-each 
> select="//SalesPerson[generate-id()=generate-id(key('fullName'
> , Name))]">
>                                          <xsl:sort 
> select="key('fullName', 
> Name)"/>
>                                          <xsl:apply-templates 
> select="Name">
>                                          <xsl:with-param 
> name="curr_supp" 
> select="$supplier_name"/>
>                                          <xsl:with-param 
> name="curr_area" 
> select="$area_name"/>
>                                          </xsl:apply-templates>
>                                  </xsl:for-each>
> 
>                          </xsl:for-each>
>                  </xsl:for-each>
> 
>          </body>
>          </html>
> </xsl:template>
> 
> <xsl:template match="Name">
>          <xsl:param name="curr_supp"/>
>          <xsl:param name="curr_area"/>
> 
>          <xsl:variable name="fName" select=".">
>          </xsl:variable>
> 
>          <xsl:for-each 
> select="//SalesPerson[generate-id()=generate-id(key('supplier-list', 
> Supplier))]">
>                  <xsl:sort select="key('supplier-list', Supplier)"/>
>                  <xsl:for-each select="key('supplier-list', 
> $curr_supp)">
>                          <xsl:if test="$fName = Name">
>                          <xsl:if test="Supplier = $curr_supp">
>                                  <p class="textenglish">
>                                  <xsl:value-of 
> select="Name/FirstName"/>
>                                  <xsl:text> </xsl:text>
>                                  <xsl:value-of 
> select="Name/LastName"/> <br />
>                                  </p>
>                          </xsl:if>
>                          </xsl:if>
>                  </xsl:for-each>
>          </xsl:for-each>
> 
> </xsl:template>
> </xsl:stylesheet>  

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.