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

Re: Multi level Grouping using xslt1.0

Subject: Re: Multi level Grouping using xslt1.0
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 23 Feb 2009 19:33:13 +0100
Re:  Multi level Grouping using xslt1.0
Bafna, Kamlesh wrote:

The requirement is to group by Company, then by Business, then by
Department & finally the Account.

The output expected is -

<Message>
<Company>
<Code>491</Code>
<Business>
<Code>0000</Code>
<Department>
<Code>0000</Code>
<Account>30010</Account> </Department>
<Department>
<Code>0001</Code>
<Account>30010</Account> </Department>
</Business>
</Company>
<Company>
<Code>498</Code>
<Business>
<Code>0000</Code>
<Department>
<Code>0000</Code>
<Account>30010</Account>
</Department>
</Business>
<Business>
<Code>0001</Code>
<Department>
<Code>0000</Code>
<Account>30011</Account>
</Department>
</Business>
</Company>
</Message>

This should do:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:output indent="yes"/>

  <xsl:key name="by-company"
           match="Row"
           use="Company"/>

  <xsl:key name="by-business"
           match="Row"
           use="concat(Company, '|', Business)"/>

  <xsl:key name="by-department"
           match="Row"
           use="concat(Company, '|', Business, '|', Department)"/>

<xsl:key name="by-account"
match="Row"
use="concat(Company, '|', Business, '|', Department, '|', Account)"/>


<xsl:template match="Data">
<Message>
<xsl:apply-templates select="Rows/Row[generate-id() = generate-id(key('by-company', Company)[1])]" mode="company"/>
</Message>
</xsl:template>


<xsl:template match="Row" mode="company">
<Company>
<Code>
<xsl:value-of select="Company"/>
</Code>
<xsl:apply-templates select="key('by-company', Company)[generate-id() = generate-id(key('by-business', concat(Company, '|', Business))[1])]" mode="business"/>
</Company>
</xsl:template>


<xsl:template match="Row" mode="business">
<Business>
<Code>
<xsl:value-of select="Business"/>
</Code>
<xsl:apply-templates select="key('by-business', concat(Company, '|', Business))[generate-id() = generate-id(key('by-department', concat(Company, '|', Business, '|', Department))[1])]" mode="department"/>
</Business>
</xsl:template>


<xsl:template match="Row" mode="department">
<Department>
<Code>
<xsl:value-of select="Department"/>
</Code>
<xsl:apply-templates select="key('by-department', concat(Company, '|', Business, '|', Department))[generate-id() = generate-id(key('by-account', concat(Company, '|', Business, '|', Department, '|', Account))[1])]" mode="account"/>
</Department>
</xsl:template>


  <xsl:template match="Row" mode="account">
    <Account>
      <xsl:value-of select="Account"/>
    </Account>
  </xsl:template>

</xsl:stylesheet>


--


	Martin Honnen
	http://JavaScript.FAQTs.com/

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.