Subject: [xsl] Grouping with XSL From: Thea Burger <thea.burger@xxxxxxxxx> Date: Thu, 12 May 2005 13:42:08 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] test for grandparent, Ragulf Pickaxe | Thread | Re: [xsl] Grouping with XSL, JBryant |
Re: [xsl] Finding a String and addi, David Carlisle | Date | Re: [xsl] Time for an exslt for 2.0, M. David Peterson |
Month |