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