1<?xml version="1.0"?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3  <xsl:output encoding="utf-8"/>
4  <xsl:template match="val">
5    <val>
6      <current>
7        <xsl:value-of select="."/>
8      </current>
9      <smooth>
10        <xsl:value-of select="floor(sum(preceding-sibling::val[position() &lt; 4] | following-sibling::val[position() &lt; 4]) div count(preceding-sibling::val[position() &lt; 4] | following-sibling::val[position() &lt; 4]))"/>
11
12      </smooth>
13      <delta>
14        <xsl:value-of select=". - preceding-sibling::val[1]"/>
15      </delta>
16    </val>
17  </xsl:template>
18
19</xsl:stylesheet>
20