Re[2]: Aggregate

Subject: Re[2]: Aggregate
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 12 Nov 2000 18:12:38 +0000
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