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

Re[2]: Aggregate

Subject: Re[2]: Aggregate
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 12 Nov 2000 18:12:38 +0000
Re[2]: Aggregate
Nagesh,

> I would like to know if we can find out Maximum and Minumum of a element in
> a xml file using xsl or any other XML technologes.

The best way involves an XPath: the minimum value is the value of the
node such that there are no other nodes that have a value less than
that value; the maximum is the value of the node such that there are
no other nodes with a value *more* than that value.

So, to find the maximum of the 'in' elements, use:

  in[not(parent::TIME/in &gt; .)]

[in English: "the 'in' element(s) for which it is *not* the case that
there is a 'in' element (child of the 'in' element's parent, 'TIME')
that has a value less than the value of this one"]

and to find the minimum:

  out[not(parent::TIME/out &lt; .)]

For some reason, I've also done this by sorting the elements, in
either ascending or descending order, and picking out the first in the
list. If you sort in ascending order, you'll get the minimum; if in
descending order, the maximum.

So, to find the maximum of the 'in' elements, use:

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

I don't know why I've done it like this when the XPath is simpler and
quicker - it probably just didn't occur to me at the time :)
  
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.