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

Re: Multi-level grouping problem. MSXML bug, maybe?

Subject: Re: Multi-level grouping problem. MSXML bug, maybe?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 09 May 2002 08:15:24 -0400
multiple level xml
At 2002-05-08 23:04 -0500, mpfingstler@xxxxxxxxxxxxxxxxxxxx wrote:
Also, is there a better way to do a
multiple "group-by"?

"Better" is difficult to measure not knowing what other criteria you have.


Here is a different solution based on variables instead of keys. Since you don't need a node-set of the groups, you could consider using the solution below.

I find using localized variables of only those candidates of a particular group make multi-level subgrouping easier to write and maintain.

I hope this helps.

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

t:\ftemp>type mark.xml
<?xml version="1.0"?>
<recordset>
   <row>
      <CODE value="000001"/>
      <CATEGORY_CODE value="A"/>
      <SUB_CATEGORY_CODE value="E"/>
      <ID value="ID01"/>
      <TYPE value="F"/>
      <SUB_TYPE value="S"/>
      <D_CODE value="V"/>
      <D_DESC value=""/>
   </row>
   <row>
      <CODE value="000001"/>
      <CATEGORY_CODE value="A"/>
      <SUB_CATEGORY_CODE value="L"/>
      <ID value="ID02"/>
      <TYPE value="F"/>
      <SUB_TYPE value="S"/>
      <D_CODE value="V"/>
      <D_DESC value=""/>
   </row>
   <row>
      <CODE value="000001"/>
      <CATEGORY_CODE value="B"/>
      <SUB_CATEGORY_CODE value="E"/>
      <ID value="ID03"/>
      <TYPE value="F"/>
      <SUB_TYPE value="T"/>
      <D_CODE value="V"/>
      <D_DESC value=""/>
   </row>
   <row>
      <CODE value="000002"/>
      <CATEGORY_CODE value="S"/>
      <SUB_CATEGORY_CODE value="L"/>
      <ID value="ID04"/>
      <TYPE value="F"/>
      <SUB_TYPE value="S"/>
      <D_CODE value="F"/>
      <D_DESC value=""/>
   </row>
</recordset>

t:\ftemp>type mark.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 indent="yes"/>

<xsl:template match="/">
  <CS>
    <xsl:variable name="rows" select="/recordset/row"/>
    <xsl:for-each select="$rows">
      <xsl:if test="generate-id(.)=
                    generate-id($rows[TYPE/@value=current()/TYPE/@value and
                                  SUB_TYPE/@value=current()/SUB_TYPE/@value])">
        <Co Type="{TYPE/@value}" SubType="{SUB_TYPE/@value}">
          <xsl:variable name="types"
                        select="$rows[TYPE/@value=current()/TYPE/@value and
                                  SUB_TYPE/@value=current()/SUB_TYPE/@value]"/>
          <xsl:for-each select="$types">
            <xsl:if test="generate-id(.)=
                   generate-id($types[D_CODE/@value=current()/D_CODE/@value])">
              <DG Code="{D_CODE/@value}"/>
            </xsl:if>
          </xsl:for-each>
        </Co>
      </xsl:if>
    </xsl:for-each>
  </CS>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>saxon -o mark.out mark.xml mark.xsl

t:\ftemp>type mark.out
<?xml version="1.0" encoding="utf-8"?>
<CS>
   <Co Type="F" SubType="S">
      <DG Code="V"/>
      <DG Code="F"/>
   </Co>
   <Co Type="F" SubType="T">
      <DG Code="V"/>
   </Co>
</CS>
t:\ftemp>rem Done!


-- Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO: June 17-21, 2002 - : 3-days XML Information Modeling: July 31-August 2, 2002

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 (Fax:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1               Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training:               2002-05-06,07,09,10,13,15,20,
-                    06-04,07,10,11,13,14,17,20,07-31,08-05,27,30


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



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.