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

Re: how to get maximum, minimum values of an element u

Subject: Re: how to get maximum, minimum values of an element using XSLT ??
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 17:55:44 +0000
xpath select maximum
Hi again Anand,

> i am using XSLT for transsormation and i want to show the maximum ,
> minuimum values of SessionSartupTime , PageTime etc using XSLT...how
> can i do that ??

Three ways:

1. Through an XPath: select the SessionStartupTime for which there is
no higher (or lower) value:

   JartaXmlReport[not(../JartaXmlReport/SessionStartupTime &gt;
                      SessionStartupTime)]/SessionStartupTime

2. Through a sort-and-pick-first approach, sorting in descending (or
ascending) order:

   <xsl:for-each select="JartaXmlReport">
      <xsl:sort select="SessionStartupTime" data-type="number"
                orders="descending" />
      <xsl:if test="position() = 1">
         <xsl:value-of select="SessionStartupTime" />
      </xsl:if>
   </xsl:for-each>

3. Through a recursive template that walks through from higher to
higher SessionStartupTime.  Apply it only to the first JartaXmlReport:

  <xsl:apply-templates select="JartaXmlReport[1]" mode="find-max" />

The template is something like:
  
<xsl:template match="JartaXmlReport" mode="find-max">
   <xsl:variable name="next"
                 select="following-sibling::JartaXmlReport
                            [SessionStartupTime &gt;
                             current()/SessionStartupTime]" />
   <xsl:choose>
      <xsl:when test="$next">
         <xsl:apply-templates select="$next" mode="find-max" />
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="SessionStartupTime" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

The first is generally best for small sets, the second for medium ones
and the third for large ones. You'll need to test it with your
particular source XML to find which works best for you.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.