Re: [xsl] Complex double group & sort on basis of date

Subject: Re: [xsl] Complex double group & sort on basis of date
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Mon, 13 Jul 2009 09:52:33 +0200
As far as I can see, your input is very well prepared for this task.
See my XSLT idea below. The only thing missing is the descending order
according to the most recent StmtDate for each ReceptType; currently
it is sorting for the first StmtDate in document order (I guess).

- Michael

Am 13.07.2009 um 09:01 schrieb Kannan, Jai Ganesh:

Dear Group,

I am new to XSL technology. I have a quite difficult doubt.

I was working on an XSLT code that will group based on an element and
sort their corresponding dates below them.

I am unable to find a way/solution to achieve it in XSLT 2.0.

What I am trying to do?

1) To sort the <ReceiptType> whose date is most recent (descending)
and
keep the order.

2) To get the corresponding dates <StmtDate> below the grouped
<ReceiptType> and sort them.

3) Also, based on the year, another grouping to be done just above the
dates <StmtDate> and below the <ReceiptType>.

4) The output should be like below.

5) As of now, I am able to get the random <ReceiptType> and sorted
dates
below them. I have posted my half baked XSLT code, most below.

Any help in guiding me to achieve this will be much appreciated.

Regards,

Jai

Sample input XML:

<?xml version=3D"1.0"?>
<StmtHitList>
           <StmtList>
               <Stmt>
                   <StmtDate>2010-04-02</StmtDate>
                   <ReceiptType>Tapestry</ReceiptType>
               </Stmt>
               <Stmt>
                   <StmtDate>2009-12-29</StmtDate>
                   <ReceiptType>Tapestry</ReceiptType>
               </Stmt>
              <Stmt>
                   <StmtDate>2008-07-02</StmtDate>
                   <ReceiptType>Quotential</ReceiptType>
               </Stmt>
               <Stmt>
                   <StmtDate>2009-12-30</StmtDate>
                   <ReceiptType>Retail</ReceiptType>
               </Stmt>
               <Stmt>
                   <StmtDate>2009-04-03</StmtDate>
                   <ReceiptType>Tapestry</ReceiptType>
               </Stmt>
               <Stmt>
                   <StmtDate>2008-07-29</StmtDate>
                   <ReceiptType>Quotential</ReceiptType>
                </Stmt>
               <Stmt>
                   <StmtDate>2009-11-30</StmtDate>
                   <ReceiptType>Quotential</ReceiptType>
               </Stmt>
               <Stmt>
                   <StmtDate>2008-07-02</StmtDate>
                   <ReceiptType>Tapestry</ReceiptType>
               </Stmt>
           </StmtList>
</StmtHitList>


<xsl:template match="StmtList">
  <html>
    <body>
      <xsl:for-each-group select="Stmt" group-by="ReceiptType">
        <xsl:sort select="../StmtDate" order="descending"/>
   	<h1><xsl:value-of select="ReceiptType"/></h1>
        <xsl:for-each-group select="current-group()" group-
by="substring(StmtDate, 1, 4)">
          <xsl:sort select="current-grouping-key()"
order="descending"/>
          <h2><xsl:value-of select="current-grouping-key()"/></h2>
          <xsl:for-each select="current-group()">
            <xsl:sort select="StmtDate" order="descending"/>
            <p><xsl:value-of select="StmtDate"/></p>
          </xsl:for-each>
        </xsl:for-each-group>
      </xsl:for-each-group>
    </body>
  </html>
</xsl:template>


Expected Output HTML after applying XSLT to the above XML:


Tapestry



2010


2010-04-02

2009

2009-12-29

2009-04-03

2008

2008-07-02


Retail



2009


2009-12-30


Quotential



2009


2009-11-30

2008

2008-07-29

2008-07-02


-- _______________________________________________________________ Michael M|ller-Hillebrand: Dokumentations-Technologie Adobe Certified Expert, FrameMaker Lvsungen und Training, FrameScript, XML/XSL, Unicode Blog: http://cap-studio.de/ - Tel. +49 (9131) 28747

Current Thread