|
| How to sort attributes to find min and max? |
 |
Fri, 21 Mar 2008 14:15:15 -070 |
Hi
I'm new to XSL.
I have an xml file in a network folder which contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<Results version="1.2">
<sampleResult timeStamp="1203298892146" dataType="text"
threadName="No
1" label="C Initialization" time="190"
responseMessage="OK"
responseCode="200" success="true"/>
<sampleResult timeStamp="1203298892102" dataType="text"
threadName="Mo
1-1" label="P Update" time="209"
responseMessage="OK"
responseCode="200" success="true"/>
<sampleResult timeStamp="1203298892193" dataType="text"
threadName="Sric 3-1" label="C Initialization"
time="215"
responseMessage="OK" responseCode="200"
success="true"/>
<sampleResult timeStamp="1203298892234" dataType="text"
threadName="Sam 4" label="P Update" time="199"
responseMessage="OK"
responseCode="200" success="true"/>
</Results>
I like to sort and find the min and max of time based on label type.
So in this case, for labels "C Initialization" I like to sort their
times to find the min and max after
sorting.
Any help is appreciated.
|
| Post Reply
|
| Re: How to sort attributes to find min and max? |
 |
Sat, 22 Mar 2008 13:16:16 +010 |
zw wrote:
> I like to sort and find the min and max of time based on label type.
> So in this case, for labels "C Initialization" I like to sort
their
> times to find the min and max after
> sorting.
I did already post an XSLT 1.0 solution.
Here is an XSLT 2.0 solution:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each-group select="Results/sampleResult"
group-by="@label">
<xsl:value-of select="current-grouping-key()"/>
<xsl:text> min is </xsl:text>
<xsl:value-of select="min(current-group()/@time)"/>
<xsl:text>, max is </xsl:text>
<xsl:value-of select="max(current-group()/@time)"/>
<xsl:text> </xsl:text>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
|
| Post Reply
|
|
|
|
|
|
|
|
|
|