This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: how to get maximum, minimum values of an element using XSLT ??
- To: "Awasthi, Anand" <Anand_Awasthi at bmc dot com>
- Subject: Re: [xsl] how to get maximum, minimum values of an element using XSLT ??
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 15 Feb 2001 17:55:44 +0000
- CC: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <3DAC9CD31458D411BCE700D0B75D0A13E249AB@ES09-HOU.bmc.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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 >
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 >
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