[xsl] Obtaining sums

Subject: [xsl] Obtaining sums
From: michael.s.eberhart@xxxxxxxxxxx
Date: Mon, 16 Aug 2004 14:00:05 -0400
I can't seem to figure out how to get a list of sums for each state.

The data looks like this:

<LEVEL name="AB">
      <TYPE name="MK001">
            <STATE name="MAINE">91</STATE>
            <STATE name="ALASKA">73</STATE>
            <STATE name="OHIO">128</STATE>
      </TYPE>
      <TYPE name="MK002">
            <STATE name="MAINE">123</STATE>
            <STATE name="ALASKA">56</STATE>
            <STATE name="OHIO">0</STATE>
      </TYPE>
      <TYPE name="MK003">
            <STATE name="MAINE">5</STATE>
            <STATE name="ALASKA">29</STATE>
            <STATE name="OHIO">48</STATE>
      </TYPE>
</LEVEL>

The code I have looks like this:

<xsl:key name="LEVLE-KEY" match="LEVEL" use="@name"/>
<xsl:key name="TYPE-KEY" match="TYPE" use="@name"/>
<xsl:key name="STATE-KEY" match="STATE" use="STATE"/>

<xsl:for-each select="LEVEL/TYPE[count(. | key('STATE-KEY',STATE)[1])=1]">
   <xsl:sort select="STATE" data-type="text"/>
   <xsl:variable name="st" select="STATE"/>
   <td align="center" bgcolor="#BDBDBD">
      <font color="#000000">
      <b>
         <font size="2">

            <xsl:value-of select="sum(LEVEL/TYPE/STATE[STATE=$st])"/>
</font>
</b>
</font>
</td>
</xsl:for-each>

The output should appear as:

MAINE ALASKA      OHIO
219   158         176

I know this should be simple, but I can't get it.  HELP!!

Thanks

Current Thread