Subject: RE: [xsl] Complex double group & sort on basis of date From: Emmanuel Begue <eb@xxxxxxxxxx> Date: Mon, 13 Jul 2009 09:57:17 +0200 |
Hello, There appears to be three grouping / sorting operations in your request; XSLT 2.0 handles grouping quite efficiently. This stylesheet produces the requested output: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:variable name="line-break" select="'
'"/> <xsl:template match="StmtList"> <xsl:for-each-group select="Stmt" group-by="ReceiptType"> <xsl:sort order="descending"/> <xsl:value-of select="current-grouping-key()"/> <xsl:value-of select="$line-break"/> <xsl:for-each-group select="current-group()" group-by="substring(StmtDate,1,4)"> <xsl:sort order="descending"/> <xsl:value-of select="current-grouping-key()"/> <xsl:value-of select="$line-break"/> <xsl:for-each select="current-group()/StmtDate"> <xsl:sort order="descending"/> <xsl:value-of select="concat(.,$line-break)"/> </xsl:for-each> </xsl:for-each-group> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> (You'll have to add the required HTML markup you need). Regards, EB > -----Original Message----- > From: Kannan, Jai Ganesh [mailto:JKannan@xxxxxxxxxxxxx] > Sent: Monday, July 13, 2009 9:01 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Complex double group & sort on basis of date > > > 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> > 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 > > XSLT code that I have now: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs" version="2.0"> > > <xsl:output method="html"/> > > <xsl:template match="/"> > <HTML> > <BODY> > <xsl:for-each select="//ReceiptType[not(. = > following::ReceiptType)]" > > <H1><xsl:value-of select="."/></H1> > <xsl:for-each > select="//Stmt[ReceiptType=current()]"> > > <xsl:sort select="substring(StmtDate,1,4)" > order="descending" data-type="number" /> > <xsl:sort select="substring(StmtDate,6,2)" > order="descending" data-type="number" /> > <xsl:sort select="substring(StmtDate,9,2)" > order="descending" data-type="number" /> > > <P><xsl:value-of select="StmtDate"/></P> > </xsl:for-each> > </xsl:for-each> > </BODY> > </HTML> > </xsl:template> > </xsl:stylesheet> > > Notice: All email and instant messages (including attachments) sent to > or from Franklin Templeton Investments (FTI) personnel may be retained, > monitored and/or reviewed by FTI and its agents, or authorized > law enforcement personnel, without further notice or consent.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Complex double group & so, Michael Müller-Hille | Thread | [xsl] RE: Complex double group & so, Kannan, Jai Ganesh |
Re: [xsl] Complex double group & so, Michael Müller-Hille | Date | [xsl] RE: Complex double group & so, Kannan, Jai Ganesh |
Month |