[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Statistics - Calculating Standard Deviation

Subject: RE: [xsl] Statistics - Calculating Standard Deviation
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Fri, 13 Jun 2003 14:46:47 +0100
calculating standard deviation
> The performance is the thing that is worrying me most.  Ideally the
> target processor is MSXML 4.0, but that is open to negotiation...
 
Well using saxon 7.x (use the latest) and exslt/math you could use the following simple stylesheet.  Im just wondering how much of this can be done using straight xslt 2 now... Is there a square root function? I had a quick look but didn’t see anything.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 	xmlns:exsl="http://exslt.org/math">
 
<xsl:variable name="mean" select="sum(/root/node) div count(/root/node)"/>

<xsl:variable name="diffs">
  <root>
    <xsl:for-each select="/root/node">
      <node squaredDiff="{exsl:power($mean - .,2)}">
         <xsl:copy-of select="."/>
      </node>
    </xsl:for-each>
  </root>
</xsl:variable>

<xsl:variable name="mean.Of.Sum.Of.Diffs">
  <xsl:for-each select="$diffs">
    <xsl:value-of select="sum(/root/node/@squaredDiff) div (count (/root/node)-1)"/>
  </xsl:for-each>
</xsl:variable>
 
<xsl:template match="/">
  standard deviation: <xsl:value-of select="exsl:sqrt(number($mean.Of.Sum.Of.Diffs))"/>
</xsl:template>

</xsl:stylesheet>

Use on xml like:

<root>
  <node>1</node>
  ...
  <node>9</node>
  <node>10</node>
</root>

cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.483 / Virus Database: 279 - Release Date: 19/05/2003
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.