[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] 3 level Muenchian Grouping ?


Subject: Re: [xsl] 3 level Muenchian Grouping ?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Jan 2004 17:59:00 -0500

At 2004-01-20 22:12 +0000, Manish Rambabu wrote:
Thanks much for the quick response. I realised the solution below ignores the group with Order Date "02/01/03" for category "1" and Type "AX".

So I see ... I was missing a for-each in my haste. The design pattern is repetitive and I just missed a step in my typing. Revision below.


Sorry for the mistake.

................ Ken

T:\ftemp>type manish.xml
<?xml version="1.0" ?>
<ORDER_DETAILS>
<CUSTOMER>
 <NAME>John Smith</NAME>
 <SITE>
  <ADDRESS>
   <STREET>111 Freedom Drive</STREET>
   <CITY>Chicago</CITY>
   <STATE>IL</STATE>
   <ZIP>60111</ZIP>
  </ADDRESS>
  <ACCOUNT_NUMBER>12222</ACCOUNT_NUMBER>
  <CATEGORY>1</CATEGORY>
  <TYPE>AX</TYPE>
  <ORDER_DATE>01/01/03</ORDER_DATE>
  <PRICE>21.99</PRICE>
 </SITE>
</CUSTOMER>

<CUSTOMER>
 <NAME>Mary Jane</NAME>
 <SITE>
 <ADDRESS>
  <STREET>16 Penn Ave NW</STREET>
  <CITY>Washington DC</CITY>
  <STATE>DC</STATE>
  <ZIP>20333</ZIP>
 </ADDRESS>
 <ACCOUNT_NUMBER>67889</ACCOUNT_NUMBER>
 <CATEGORY>1</CATEGORY>
 <TYPE>AX</TYPE>
 <ORDER_DATE>02/01/03</ORDER_DATE>
 <PRICE>11.98</PRICE>
 </SITE>
</CUSTOMER>

<CUSTOMER>
 <NAME>Mark Anderson</NAME>
 <SITE>
 <ADDRESS>
  <STREET>175 Commerce Park</STREET>
  <CITY>San Francisco</CITY>
  <STATE>CA</STATE>
  <ZIP>93311</ZIP>
 </ADDRESS>
 <ACCOUNT_NUMBER>66145</ACCOUNT_NUMBER>
 <CATEGORY>1</CATEGORY>
 <TYPE>BX</TYPE>
 <ORDER_DATE>01/31/03</ORDER_DATE>
 <PRICE>11.98</PRICE>
 </SITE>
</CUSTOMER>

<CUSTOMER>
 <NAME>Chris Dewalt</NAME>
 <SITE>
 <ADDRESS>
  <STREET>1344 Washington Park</STREET>
  <CITY>San Francisco</CITY>
  <STATE>CA</STATE>
  <ZIP>93344</ZIP>
 </ADDRESS>
 <ACCOUNT_NUMBER>000234</ACCOUNT_NUMBER>
 <CATEGORY>1</CATEGORY>
 <TYPE>BX</TYPE>
 <ORDER_DATE>01/31/03</ORDER_DATE>
 <PRICE>41.00</PRICE>
 </SITE>
</CUSTOMER>

<CUSTOMER>
 <NAME>Sam Dewar</NAME>
 <SITE>
 <ADDRESS>
  <STREET>123 Hunington Way</STREET>
  <CITY>Mclean</CITY>
  <STATE>VA</STATE>
  <ZIP>20121</ZIP>
 </ADDRESS>
 <ACCOUNT_NUMBER>100988</ACCOUNT_NUMBER>
 <CATEGORY>2</CATEGORY>
 <TYPE>BX</TYPE>
 <ORDER_DATE>01/31/03</ORDER_DATE>
 <PRICE>11.00</PRICE>
 </SITE>
</CUSTOMER>
 <CUSTOMER>
 <NAME>Peter Henderson</NAME>
 <SITE>
 <ADDRESS>
  <STREET>421 RidgeTop Place</STREET>
  <CITY>Sarosota</CITY>
  <STATE>MI</STATE>
  <ZIP>10121</ZIP>
 </ADDRESS>
 <ACCOUNT_NUMBER>800223</ACCOUNT_NUMBER>
 <CATEGORY>1</CATEGORY>
 <TYPE>AX</TYPE>
 <ORDER_DATE>01/01/03</ORDER_DATE>
 <PRICE>83.00</PRICE>
 </SITE>
</CUSTOMER>
</ORDER_DETAILS>

T:\ftemp>type manish.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="ORDER_DETAILS">

 <xsl:variable name="custs" select="CUSTOMER/SITE"/>
 <xsl:for-each select="$custs">
   <xsl:if test="generate-id(.)=
                 generate-id($custs[CATEGORY=current()/CATEGORY])">
     <xsl:text/>Category: <xsl:value-of select="CATEGORY"/><xsl:text>
</xsl:text>
     <xsl:variable name="cats" select="$custs[CATEGORY=current()/CATEGORY]"/>
     <xsl:for-each select="$cats">
       <xsl:if test="generate-id(.)=
                     generate-id($cats[TYPE=current()/TYPE])">
         <xsl:text/>Type: <xsl:value-of select="TYPE"/><xsl:text>
</xsl:text>
         <xsl:variable name="types" select="$cats[TYPE=current()/TYPE]"/>
         <xsl:for-each select="$types">
           <xsl:if test="generate-id(.)=
                         generate-id($types[ORDER_DATE=current()/ORDER_DATE])">
             <xsl:text/>Order Date: <xsl:value-of select="ORDER_DATE"/>
             <xsl:text>
</xsl:text>
             <xsl:for-each select="$types[ORDER_DATE=current()/ORDER_DATE]">
               <xsl:if test="position()>1">,</xsl:if>
                 <xsl:value-of select="../NAME"/>
               </xsl:for-each><xsl:text>
</xsl:text>
           </xsl:if>
         </xsl:for-each>
       </xsl:if>
     </xsl:for-each>
   </xsl:if>
 </xsl:for-each>
</xsl:template>

</xsl:stylesheet>



T:\ftemp>saxon manish.xml manish.xsl
<?xml version="1.0" encoding="utf-8"?>Category: 1
Type: AX
Order Date: 01/01/03
John Smith,Peter Henderson
Order Date: 02/01/03
Mary Jane
Type: BX
Order Date: 01/31/03
Mark Anderson,Chris Dewalt
Category: 2
Type: BX
Order Date: 01/31/03
Sam Dewar

T:\ftemp>rem Done!


-- North America (Washington, DC): 3-day XSLT/2-day XSL-FO 2004-03-15 - (San Francisco, CA): 3-day XSLT/2-day XSL-FO 2004-03-22 Asia (Hong Kong, China): 3-day XSLT/2-day XSL-FO 2004-05-17 Europe (Bremen, Germany): 3-day XSLT/2-day XSL-FO 2004-05-24 Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords