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 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] how to get maximum, minimum v, Awasthi, Anand | Thread | [xsl] XSL rule for sorting the elem, Awasthi, Anand |
RE: [xsl] syntax sugar for call-tem, Clark C. Evans | Date | RE: [xsl] Converting &, >, <, ", an, Kevin Duffey |
Month |