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

Removing duplicates after list is sorted

Subject: Removing duplicates after list is sorted
From: Nicole Flaten <nlflaten@xxxxxxxxxxxx>
Date: Wed, 10 May 2006 10:39:01 -0700
remove duplicates from list
Hi,

I am learning XSL and have been struggling with the same question for a 
couple of days.  It is probably a simple question to someone familiar with 
XSL so I was hoping to get some help.  Below are portions of my XSL and 
XML files.  Basically, for each different base (ELS, LAN, KAD) I want to 
display only one record in a html page, the one record is the one with the 
highest CREATIONTIME value.  I have tried many methods and none of them 
has worked.  Below is the latest and almost successful method.  It sorts 
the list in the way I want.  and then in <template match="Report"> I try 
to remove the duplicates so only the first base from the sorted list is 
displayed.  The problem is that I am not able to apply the preceding node 
to the sorted list created in the XSL file, the XSL just applies the 
preceding node test to the XML file.  How can I sort the XML file and the 
apply the preceding node test to the sorted list?  Or is there a better 
method altogether?  Any help would be greatly appreciated.

Thanks, Nicole

<xsl:template match="/">

<html>
        <body>
 
                <table border="1" cellspacing="1" cellpadding="1" 
align="center">
                        <tr class="formtitle" align="center">
                                <td>Base Status</td>
                                <td>Creation Time</td>
                                <td>ASC</td>
                        </tr>
 
 
                        <xsl:apply-templates select="//Document/Report">
                                <xsl:sort order='ascending' 
select='@base'/>
                                <xsl:sort order='descending' 
select='../@CREATIONTIME'/>
                        </xsl:apply-templates> 

                </table>
        </body>
</html>


</xsl:template>

<xsl:template match="Report">
        <xsl:if test="not ((preceding::*[1]/@base)=@base) ">
                <xsl:call-template name="print"/>
        </xsl:if>
</xsl:template>

<xsl:template name="print">
        <tr class="formtext">
                <td class="formtitle">print <xsl:value-of 
select='@base'/></td>
                <td><xsl:value-of select='../@CREATIONTIME'/></td>
        </tr>
        <tr class="formtext">
                <td class="formtitle" align="right">Authorized</td>
                <td align="center"><xsl:value-of 
select="Authorized/@ASC"/></td>
        </tr>
</xsl:template> 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sample XML data

<?xml-stylesheet href="SparesCalc.xsl" type="text/xsl" ?>
<?xml version="1.0" encoding="UTF-8" ?> 
<docs>
<Document CREATIONTIME="200605040811">
<Report ID="759b" base="ELS">
        <Authorized ASC="2"/> 
</Report>
</Document>
<Document CREATIONTIME="20060404115819">
<Report ID="759a" base="LAN">
        <Authorized ASC="0"/> 
</Report>
</Document>
<Document  CREATIONTIME="200605041506">
<Report ID="759c" base="LAN">
        <Authorized ASC="0"/> 
</Report>
</Document>
<Document CREATIONTIME="200605041507">
<Report ID="759d" base="ELS">
        <Authorized ASC="2"/> 
</Report>
</Document>
<Document CREATIONTIME="20060503111352">
<Report ID="759e" base="KAD">
        <Authorized ASC="4"/> 
</Report>
</Document>
</docs>

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.