Re: [xsl] How to sort attributes to find min and max?

Subject: Re: [xsl] How to sort attributes to find min and max?
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Sat, 22 Mar 2008 14:26:35 +0100
It has been basically answered previously, but I wanted to test the beauty of Kernow's XSLT playground feature and also train a little bit xsl:function. So with XSLT 2.0 you could create

<xsl:function name="f:extreme" as="xs:integer">
<xsl:param name="context"/>
<xsl:param name="mode"/>
<xsl:param name="label"/>
<xsl:variable name="order" select="if ($mode = 'min') then 'ascending' else 'descending'"/>
<xsl:for-each select="$context/*[@label=$label]">
<xsl:sort select="@time" data-type="number" order="{$order}"/>
<xsl:if test="position() = 1">
<xsl:value-of select="@time"/>
</xsl:if>
</xsl:for-each>
</xsl:function>


The results can then be retrieved using calls like:

 <xsl:value-of select="f:extreme(., 'min', 'Init')"/>
 <xsl:value-of select="f:extreme(., 'max', 'Init')"/>

- Michael

PS: I am sure one could spend less lines.


Am 22.03.2008 um 03:28 schrieb Z W:
Hi


How do I to find min and max of an attribute based on another attribute ? My select below doesn't seem to work and causing jvm to run out of memory. <xsl:value-of select="document($previousJTL)/Results/*[@label = 'Init']/@time" />


Ideally, I like to be able to get min and max for each message. In this case, Init min is 235, max is 2345 Update min is 2043, max is 2043


Seek some help. Any help is appreciated.


Input file <?xml version="1.0" encoding="UTF-8"?> <Results version="1.2">


<sampleResult timeStamp="1205507229423" label="Init" time="2133" responseMessage="OK" responseCode="200" success="true"/> <sampleResult timeStamp="1205507229265" label="Init" time="2345" responseMessage="OK" responseCode="200" success="true"/> <sampleResult timeStamp="1205507229539" label="Update Process" time="2043" responseMessage="OK" responseCode="200" success="true"/> <sampleResult timeStamp="1205507229639" label="Update Process" time="2043" responseMessage="OK" responseCode="200" success="true"/> <sampleResult timeStamp="1205507229765" label="Init" time="235" responseMessage="OK" responseCode="200" success="true"/>

Current Thread