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

Grouping with XSL

Subject: Grouping with XSL
From: Thea Burger <thea.burger@xxxxxxxxx>
Date: Thu, 12 May 2005 13:42:08 +0200
thea burger
Hi,

I have an XML document that looks something like this, and as you can
see I get duplicate DIVISIONS, but then different BUNITS and PAREAS
under it.

XML:
<ROWSET>
 <ROW>
  <DIVISIONID>1000</DIVISIONID>
  <DIVDESC>CORPORATE GROUP</DIVDESC>
  <BUNIT>
   <BUNIT_ROW>
    <BUNITID>1076</BUNITID>
    <BUNITDESC>Corporate Division</BUNITDESC>
    <PAREA>
     <PAREA_ROW>
      <PAREAID>7610</PAREAID>
      <PAREADESC>Corporate</PAREADESC>
     </PAREA_ROW>
    </PAREA>
   </BUNIT_ROW>
  </BUNIT>
 </ROW>
 <ROW>
  <DIVISIONID>2000</DIVISIONID>
  <DIVDESC>Corp Com Services</DIVDESC>
  <BUNIT>
   <BUNIT_ROW>
    <BUNITID>2075</BUNITID>
    <BUNITDESC>Pension Fund</BUNITDESC>
    <PAREA>
     <PAREA_ROW>
      <PAREAID>7501</PAREAID>
      <PAREADESC>Pens Fund Exec</PAREADESC>
     </PAREA_ROW>
    </PAREA>
   </BUNIT_ROW>
  </BUNIT>
 </ROW>
 <ROW>
  <DIVISIONID>2000</DIVISIONID>
  <DIVDESC>Corp Com Services</DIVDESC>
  <BUNIT>
   <BUNIT_ROW>
    <BUNITID>2095</BUNITID>
    <BUNITDESC>Corp Com Services</BUNITDESC>
    <PAREA>
     <PAREA_ROW>
      <PAREAID>9501</PAREAID>
      <PAREADESC>Com Executives</PAREADESC>
     </PAREA_ROW>
    </PAREA>
   </BUNIT_ROW>
  </BUNIT>
 </ROW>
 <ROW>
  <DIVISIONID>2000</DIVISIONID>
  <DIVDESC>Corp Com Services</DIVDESC>
  <BUNIT>
   <BUNIT_ROW>
    <BUNITID>2222</BUNITID>
    <BUNITDESC>Testing</BUNITDESC>
    <PAREA>
     <PAREA_ROW>
      <PAREAID>2224</PAREAID>
      <PAREADESC>TestingPA</PAREADESC>
     </PAREA_ROW>
    </PAREA>
   </BUNIT_ROW>
  </BUNIT>
 </ROW>
</ROWSET>


What I would like is to get the following result:
CORPORATE GROUP
-----Corporate Division
-------------Corporate
Corp Com Services
-----Pension Fund
-------------Pens Fund Exec
-----Corp Com Services
-------------Com Executives
-----Testing
-------------TestingPA

But at the moment I get:
CORPORATE GROUP
-----Corporate Division
-------------Corporate
Corp Com Services
-----Pension Fund
-------------Pens Fund Exec

With this XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="
http://www.w3.org/1999/XSL/Format">
 <xsl:key name="row-by-divisionid" match="ROW" use="DIVISIONID"/>
 <xsl:key name="unit-by-bu"
match="ROW/BUNIT/BUNIT_ROW[ancestor::ROW/DIVISIONID]"
use="DIVISIONID"/>
 <xsl:template match="ROWSET">
  <xsl:for-each select="ROW[count(. | key('row-by-divisionid',
DIVISIONID)[1]) = 1]">
   <xsl:sort select="DIVISIONID"/>
   <xsl:value-of select="DIVDESC"/><br/>
   <xsl:variable name="DIVID" select="DIVISIONID"/>
   -----<xsl:value-of
select="BUNIT/BUNIT_ROW/BUNITDESC[ancestor::ROW[DIVISIONID=$DIVID]]"
/><br/>
   -------------<xsl:value-of
select="BUNIT/BUNIT_ROW/PAREA/PAREA_ROW/PAREADESC" /><br/>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

This line (BUNIT/BUNIT_ROW/BUNITDESC[ancestor::ROW[DIVISIONID=$DIVID]])
should change, but so far I could not get the correct result.
The other thing is that I am going to need another key for the
BUNIT_ROW level, as I can get duplicate results of that as well... I
tried a couple of options (you'll see the last one I tried:
"unit-by-bu"), but I'm a bit new to this and it didn't work :( I got a
couple of examples for the Muenchian method, but not one for multiple
levels of groupings.

Can anyone maybe point me in the right direction?

Thanks,
Thea Burger

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.