Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Complex grouping based on date sort and sub elements date sort

From: jai <jaiganesh.kannan@-----.--->
To: NULL
Date: 7/3/2009 1:16:00 AM
Hi Everybody,

I am newbie in XSLT. Just wanted to know if my requirement is possible
using XSLT.

(To be clear) algorithm in words:

1)       Select one <ReceiptType> whose <StmtDate> is most recent and
display that as first element in HTML output.

2)       Below that displayed <ReceiptType>, sort the <StmtDate> of
corresponding <ReceiptType> inside XML in descending order.

3)       Repeat step #1) and #2) until unique <ReceiptType> is
available.

So far, I am able to fetch the <ReceiptType> element randomly and its
corresponding <StmtDate> elements in a sorted order.


Any help or directions to acheive will be very much appreciated.

Kindly mail me for more clarifications if any.

Thanks in advance!!

Jai

jaiganesh.kannan@g...


My XSLT:

<?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>




Sample XML:

<?xml version="1.0"?>
<StmtHitList>
            <StmtList>

                <Stmt>
                    <StmtDate>2010-04-02</StmtDate>
                    <ID1>001</ID1>
                    <ID2>001</ID2>
                    <ReceiptType>Tapestry</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2009-12-29</StmtDate>
                    <ID1>001</ID1>
                    <ID2>001</ID2>
                    <ReceiptType>Tapestry</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2008-07-02</StmtDate>
                    <ID1>002</ID1>
                    <ID2>002</ID2>
                    <ReceiptType>Quotential</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2009-12-30</StmtDate>
                    <ID1>004</ID1>
                    <ID2>004</ID2>
                    <ReceiptType>Retail</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2009-04-03</StmtDate>
                    <ID1>003</ID1>
                    <ID2>003</ID2>
                    <ReceiptType>Tapestry</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2008-07-29</StmtDate>
                    <ID1>002</ID1>
                    <ID2>002</ID2>
                    <ReceiptType>Quotential</ReceiptType>
                 </Stmt>

                <Stmt>
                    <StmtDate>2009-11-30</StmtDate>
                    <ID1>002</ID1>
                    <ID2>002</ID2>
                    <ReceiptType>Quotential</ReceiptType>
                </Stmt>

                <Stmt>
                    <StmtDate>2008-07-02</StmtDate>
                    <ID1>002</ID1>
                    <ID2>002</ID2>
                    <ReceiptType>Tapestry</ReceiptType>
                </Stmt>

            </StmtList>
</StmtHitList>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent