Re: [xsl] how to get maximum, minimum values of an element using XSLT ??

Subject: Re: [xsl] 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
Hi again Anand,

> i am using XSLT for transsormation and i want to show the maximum ,
> minuimum values of SessionSartupTime , PageTime etc using
> 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;

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" />

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"
                            [SessionStartupTime &gt;
                             current()/SessionStartupTime]" />
      <xsl:when test="$next">
         <xsl:apply-templates select="$next" mode="find-max" />
         <xsl:value-of select="SessionStartupTime" />

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 Tennison

 XSL-List info and archive:

Current Thread