At 2004-02-24 23:28 -0700, Kent Seegmiller wrote:
I want to group 3-4 levels down. I get the 1-2 levels working from reading
Jeni's postings but I can't get the 3rd level and so on to work.
...
I am trying to group by vendor name then vendor code and finally load
number. The first 2 levels work out but the third doesn't. Any help
please.
I find that multi-level grouping is most easily achieved by using the
variable method of grouping rather than the key method of grouping. The
design pattern is to set up a variable with everything that has to be
grouped, then successfully whittle down the set in grouped collections
always doing the grouping on the set of nodes just extracted from the
bigger group.
You didn't supply much data so I mocked some up changing the purchase order
numbers to be from "1" to "5" so that you can distinguish the records in
the result.
I hope this helps.
....................... Ken
T:\ftemp>type kent.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<claims>
<claim claimable="no">
<vendorcode>01H0012</vendorcode>
<vendorname>TYCO PLASTICS</vendorname>
<vendorontime> 50 </vendorontime>
<cons> 101 </cons>
<carrier>GODFREY TRUCKING</carrier>
<carrierontime> 100 </carrierontime>
<loadnum>163678</loadnum>
<po>1</po>
<due>1/27/03 </due>
<original>1/28/03 8:30:00 AM </original>
<scheduled>1/28/03 8:30:00 AM </scheduled>
<actual>1/28/03 9:27:00 AM </actual>
<vendstat>On Time</vendstat>
<carrierstat>On Time</carrierstat>
</claim>
<claim claimable="no">
<vendorcode>01H0011</vendorcode>
<vendorname>TYCO PLASTICS</vendorname>
<vendorontime> 50 </vendorontime>
<cons> 101 </cons>
<carrier>GODFREY TRUCKING</carrier>
<carrierontime> 100 </carrierontime>
<loadnum>163678</loadnum>
<po>2</po>
<due>1/27/03 </due>
<original>1/28/03 8:30:00 AM </original>
<scheduled>1/28/03 8:30:00 AM </scheduled>
<actual>1/28/03 9:27:00 AM </actual>
<vendstat>On Time</vendstat>
<carrierstat>On Time</carrierstat>
</claim>
<claim claimable="no">
<vendorcode>01H0011</vendorcode>
<vendorname>XYZ PLASTICS</vendorname>
<vendorontime> 50 </vendorontime>
<cons> 101 </cons>
<carrier>GODFREY TRUCKING</carrier>
<carrierontime> 100 </carrierontime>
<loadnum>163678</loadnum>
<po>3</po>
<due>1/27/03 </due>
<original>1/28/03 8:30:00 AM </original>
<scheduled>1/28/03 8:30:00 AM </scheduled>
<actual>1/28/03 9:27:00 AM </actual>
<vendstat>On Time</vendstat>
<carrierstat>On Time</carrierstat>
</claim>
<claim claimable="no">
<vendorcode>01H0011</vendorcode>
<vendorname>TYCO PLASTICS</vendorname>
<vendorontime> 50 </vendorontime>
<cons> 101 </cons>
<carrier>GODFREY TRUCKING</carrier>
<carrierontime> 100 </carrierontime>
<loadnum>163678</loadnum>
<po>4</po>
<due>1/27/03 </due>
<original>1/28/03 8:30:00 AM </original>
<scheduled>1/28/03 8:30:00 AM </scheduled>
<actual>1/28/03 9:27:00 AM </actual>
<vendstat>On Time</vendstat>
<carrierstat>On Time</carrierstat>
</claim>
<claim claimable="no">
<vendorcode>01H0011</vendorcode>
<vendorname>TYCO PLASTICS</vendorname>
<vendorontime> 50 </vendorontime>
<cons> 101 </cons>
<carrier>GODFREY TRUCKING</carrier>
<carrierontime> 100 </carrierontime>
<loadnum>1234567</loadnum>
<po>5</po>
<due>1/27/03 </due>
<original>1/28/03 8:30:00 AM </original>
<scheduled>1/28/03 8:30:00 AM </scheduled>
<actual>1/28/03 9:27:00 AM </actual>
<vendstat>On Time</vendstat>
<carrierstat>On Time</carrierstat>
</claim>
</claims>
T:\ftemp>type kent.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="claims" select="/claims/claim"/>
<xsl:for-each select="$claims">
<xsl:if test="generate-id(.)=
generate-id($claims[vendorname=current()/vendorname])">
<xsl:value-of select="vendorname"/><xsl:text>
</xsl:text>
<xsl:variable name="vendors"
select="$claims[vendorname=current()/vendorname]"/>
<xsl:for-each select="$vendors">
<xsl:if test="generate-id(.)=
generate-id($vendors[vendorcode=current()/vendorcode])">
<xsl:text> </xsl:text>
<xsl:value-of select="vendorcode"/><xsl:text>
</xsl:text>
<xsl:variable name="codes"
select="$vendors[vendorcode=current()/vendorcode]"/>
<xsl:for-each select="$codes">
<xsl:if test="generate-id(.)=
generate-id($codes[loadnum=current()/loadnum])">
<xsl:text> </xsl:text>
<xsl:value-of select="loadnum"/><xsl:text>
</xsl:text>
<xsl:for-each select="$codes[loadnum=current()/loadnum]">
<xsl:text> </xsl:text>
<xsl:value-of select="po"/><xsl:text>
</xsl:text>
</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 kent.xml kent.xsl
TYCO PLASTICS
01H0012
163678
1
01H0011
163678
2
4
1234567
5
XYZ PLASTICS
01H0011
163678
3
T:\ftemp>rem Done!
--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
United States: Washington, DC March 15; San Francisco, CA March 22
Finland April 26; Hong Kong May 17; Germany May 24; London June 07
World-wide on-site corporate, government & user group XML training
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
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