Subject: Re: Nested Grouping problem [with links] From: "Steve Muench" <Steve.Muench@xxxxxxxxxx> Date: Wed, 29 Nov 2000 01:06:00 -0800 |
| This is a grouping problem. In fact its a nested grouping problem. Given your fundlist.xml file at [http://64.50.6.166/a/asdren/fundlist.xml] The following stylesheet produces the nested, grouped text output below. By inserting appropriate HTML tags at the right level, you can get it to produce fancier HTML output, but this shows the basics... Cash MoneyMarket Sarah's MoneyMarket Fund Bob's MoneyMarket Fund Domestic Equity Growth Will's Fund John's Fund Value Patrick's Fund Aggressive Growth Alex's Fund International Equity Growth Pablo's Fund Pierre's Fund Value Bharat's Fund Onikaru's Fund Aggressive Growth Gunther's Fund <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <!-- Used for distinct allocation categories --> <xsl:key name="cat" match="allocCategory" use="."/> <!-- Used for distinct asset classes for an alloc category --> <xsl:key name="ucls" match="assetClass" use="concat(.,'::',../allocCategory)"/> <!-- Used to find (not-distinct) asset classes for an alloc cat --> <xsl:key name="cls" match="assetClass" use="../allocCategory"/> <!-- Used to find funds in a (allocCat,assetClass) combination --> <xsl:key name="fnd" match="Fund" use="concat(allocCategory,'::',assetClass)"/> <xsl:template match="/"> <xsl:for-each select="/FundList/Fund/allocCategory[generate-id(.)= generate-id(key('cat',.)[1])]"> <xsl:variable name="curcat" select="string(.)"/> <xsl:value-of select="$curcat"/> <xsl:text>
</xsl:text> <xsl:for-each select="key('cls',$curcat)[generate-id(.)= generate-id(key('ucls', concat(.,'::',$curcat))[1])]"> <xsl:variable name="curclass" select="string(.)"/> <xsl:text> </xsl:text> <xsl:value-of select="$curclass"/> <xsl:text>
</xsl:text> <xsl:for-each select="key('fnd',concat($curcat,'::',$curclass))"> <xsl:text> </xsl:text> <xsl:value-of select="fundName"/> <xsl:text>
</xsl:text> </xsl:for-each> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> ______________________________________________________________ Steve Muench, Lead XML Evangelist & Consulting Product Manager BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG Author "Building Oracle XML Applications", O'Reilly http://www.oreilly.com/catalog/orxmlapp/ | | I've gone through your Jennison's helpful article | [http://www.jenitennison.com/xslt/grouping/muenchian.html]on the Muenchian | key technique and searched through the newsgroup messages and the XSLT FAQ | [http://www.dpawson.co.uk/xsl/sect21.html] but haven't found anything | similar. | | From a flat XML structure like: | | <FundList> | <Fund rowid="1"> | <fundName>Sarah's MoneyMarket Fund</fundName> | <assetClass>MoneyMarket</assetClass> | <capitalization/> | <id>12845</id> | <percent>0</percent> | <risk>4</risk> | </Fund> | <Fund rowid="2"> | <fundName>Will's Fund</fundName> | <allocCategory>Domestic Equity</allocCategory> | <assetClass>Growth</assetClass> | <capitalization>Small Cap</capitalization> | <id>12345</id> | <percent>0</percent> | <risk>4</risk> | </Fund> | <Fund rowid="6"> | <fundName>Alex's Fund</fundName> | <allocCategory>Domestic Equity</allocCategory> | <assetClass>Aggressive Growth</assetClass> | <capitalization>Medium Cap</capitalization> | <id>17378</id> | <percent>0</percent> | <risk>5</risk> | </Fund> | </FundList> | | | I want to create a nice looking page that looks like this | [http://64.50.6.166/a/asdren/fundlist.htm]. I used to have it | [http://64.50.6.166/a/asdren/fundlistold.xml] working in XSL but then we | found out there wasn't an easy way to get the database to return a nice | hierarchical XML like the one I had designed ;-( | | My problem is I'm relatively new to XSL and am not sure as to the best way | to go about creating keys to accommodate four levels of nested grouping. As | I stated XML cannot be modified. It has to be processed in this flat format. | I'm able to get up to one level but once I start nesting for-each loops | inside each other I don't get the desired results. | | I was thinking of perhaps hardcoding the four top level categories (Cash, | Domestic Fixed, Domestic Equity and International Equity). The only thing I | don't like about that is that if ever another allocation category were added | then someone has to make a change to the XSL. Is there a way to perhaps a | make a robust XSL so that no matter how many categories are added the XSL | would still handle it? | | To be honest, I'm kind of tired of spinning my wheels on this one and am | willing to monetarily compensate someone to help me solve this one. | | Here are some reference files: | | FundList.xml [http://64.50.6.166/a/asdren/fundlist.xml]- file containing | the current flat XML structure | FundList.xsl [http://64.50.6.166/a/asdren/fundlist.xsl]- my feeble | attempt | FundList.xls [http://64.50.6.166/a/asdren/fundlist.xls]- an Excel file | outlining the category structure | | If anyone is interested, please contact me off the list at alex@xxxxxxxxxxxx | | thanks, | Alex Aguilar | | | | | | | | | XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list | XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Nested Grouping problem [with links, Alex Aguilar | Thread | Matching braches without a certain , Theodore Weatherly |
Stylesheet listing elements and at, Miloslav Nic | Date | DTD or XML Schema editor recommenda, MarkH |
Month |