Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 30th, 2005, 12:06 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Min / Max followup

I've reviewed a previous thread about determining the minmum and maximum values in a node-set. I have an interesting related question:

How do you retrieve the minimum or maximum values ONLY ONCE assuming that there are multiple equl values?

For instance, in the follwoing xml file, there are several equal date values:

<?xml version="1.0"?>
<?xml-stylesheet href="sortdates.xsl" type="text/xsl"?>
<timesheet>
<user name="employee name" id="001" />
<projects>
<project name="Project 1" number="23" interval="minutes">
<pending>
<entry date="01/01/2005" duration="20000"/>
<entry date="01/01/2005" duration="3000"/>
<entry date="01/02/2005" duration="36"/>
</pending>
</project>
<project name="Project 2" number="36" interval="hours">
<pending>
<entry date="01/01/2005" duration="20000" />
<entry date="01/01/2005" duration="3000"/>
<entry date="01/02/2005" duration="30"/>
</pending>
</project>
<project name="Project 3" number="45" interval="minutes">
<pending>
<entry date="01/02/2005" duration="20000"/>
<entry date="01/01/2005" duration="1000"/>
<entry date="01/03/2005" duration="2"/>
</pending>
</project>
</projects>

</timesheet>

And the stylesheet to go with it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:output method="html"/>

    <xsl:variable name="entries" select=".//entry"/>

    <xsl:template match="/">
    <xsl:for-each select="$entries">


        <xsl:if test="not(//entry/@date &lt; ./@date)">
                lowdate = <xsl:value-of select="./@date"/><br/>
        </xsl:if>


        <xsl:if test="not(//entry/@date &gt; ./@date)">
                highdate = <xsl:value-of select="./@date"/><br/>
        </xsl:if>

    </xsl:for-each>

    <html>
            <head>
                <title>Greeting</title>
                <style type="text/css" media="all">@import "timesheet.css";</style>
            </head>
            <body>
                <h1>
                    testing...<br/>

                </h1>
            </body>
        </html>

    </xsl:template>

</xsl:stylesheet>

which basically prints out the low and high dates in the node set, except that the matching equal values are repeated as follows:

lowdate = 01/01/2005
lowdate = 01/01/2005
lowdate = 01/01/2005
lowdate = 01/01/2005
lowdate = 01/01/2005
highdate = 01/03/2005

testing...


Can anyone suggest something? Thanks...

Reply With Quote
  #2 (permalink)  
Old August 31st, 2005, 09:11 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could use the standard Munchian methods to remove duplicates. However, this is an inefficient way of getting min and max anyway. A better approach is to do a sort and take the first/last in the sorted sequence - this won't give you any duplicates.

<xsl:for-each select="xxx">
  <xsl:sort .../>
  <xsl:if test="position()=1">
    <first>...</first>

  <xsl:if test="position()=last()">
    <last>...</last>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 31st, 2005, 12:02 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael, it works like a charm...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one get the Max or Min Filename? crabjoe ASP.NET 1.0 and 1.1 Basics 4 January 15th, 2008 04:48 PM
MAX/MIN Value Help slbibs SQL Server 2005 4 November 6th, 2007 04:00 AM
MIN( MAX( UPDATE Stuart Stalker SQL Language 3 February 21st, 2007 07:10 AM
MAX and MIN ON TD cleytonjordan XSLT 7 July 27th, 2005 12:39 PM
How to use Min,Max,Abs functions braindog_43 XSLT 0 February 7th, 2005 06:04 AM



All times are GMT -4. The time now is 11:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.