M
Michael Hamm
I have the following XML file (simplified from the actual):
<r>
<o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o>
<o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o>
<o><n>3</n><si>s</si><v1>7</v1><v2>8</v2><v3>9</v3></o>
<o><n>5</n><si>i</si><v1>10</v1><v2>11</v2><v3>12</v3></o>
<o><n>6</n><si>i</si><v1>13</v1><v2>14</v2><v3>15</v3></o>
</r>
and the following stylesheet (again simplified):
<xsl:template match="/"><html><body><table>
<xsl:for-each select="r/o"><tr>
<td><xsl:value-of select="n" /></td>
<td><xsl:value-of select="si" /></td>
<td><xsl:value-of select="v1" /></td>
<td><xsl:value-of select="v2" /></td>
<td><xsl:value-of select="v3" /></td>
<td><xsl:value-of
select="(v1 + (2 * v2) + (3 * v3)) div (v1 + v2 + v3)" /></td>
</tr></xsl:for-each>
<tfoot>
<tr><th scope="row" colspan="5">Average when "s"</th>
<td> [...] </td></tr>
<tr><th scope="row" colspan="5">Average when "i"</th>
<td> [...] </td></tr></tfoot></table></body></html>
In place of the '[...]' I wish to have the weighted averages, as follows.
In place of the first '[...]' I want
( 1 + 2*2 + 3*3 + 7 + 2*8 + 3*9 ) / ( 1 + 2 + 3 + 7 + 8 + 9 )
(which is the same as the weighted average of the various weighted
averages already computed), and in place of the second '[...]' I want
( 4 + 2*5 + 3*6 + 10 + 2*11 + 3*12 + 13 + 2*14 + 3* 15 ) divided
by ( 4+ 5+ 6+ 10 + 11 + 12 + 13 + 14 + 15 ).
Is there a way to do this in XSLT?
Thanks,
Michael Hamm It's not who you know, it's whom.
AM, Math, Wash. U. St. Louis Joan Rivers
(e-mail address removed) Fine print:
http://www.math.wustl.edu/~msh210/ ... legal.html
<r>
<o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o>
<o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o>
<o><n>3</n><si>s</si><v1>7</v1><v2>8</v2><v3>9</v3></o>
<o><n>5</n><si>i</si><v1>10</v1><v2>11</v2><v3>12</v3></o>
<o><n>6</n><si>i</si><v1>13</v1><v2>14</v2><v3>15</v3></o>
</r>
and the following stylesheet (again simplified):
<xsl:template match="/"><html><body><table>
<xsl:for-each select="r/o"><tr>
<td><xsl:value-of select="n" /></td>
<td><xsl:value-of select="si" /></td>
<td><xsl:value-of select="v1" /></td>
<td><xsl:value-of select="v2" /></td>
<td><xsl:value-of select="v3" /></td>
<td><xsl:value-of
select="(v1 + (2 * v2) + (3 * v3)) div (v1 + v2 + v3)" /></td>
</tr></xsl:for-each>
<tfoot>
<tr><th scope="row" colspan="5">Average when "s"</th>
<td> [...] </td></tr>
<tr><th scope="row" colspan="5">Average when "i"</th>
<td> [...] </td></tr></tfoot></table></body></html>
In place of the '[...]' I wish to have the weighted averages, as follows.
In place of the first '[...]' I want
( 1 + 2*2 + 3*3 + 7 + 2*8 + 3*9 ) / ( 1 + 2 + 3 + 7 + 8 + 9 )
(which is the same as the weighted average of the various weighted
averages already computed), and in place of the second '[...]' I want
( 4 + 2*5 + 3*6 + 10 + 2*11 + 3*12 + 13 + 2*14 + 3* 15 ) divided
by ( 4+ 5+ 6+ 10 + 11 + 12 + 13 + 14 + 15 ).
Is there a way to do this in XSLT?
Thanks,
Michael Hamm It's not who you know, it's whom.
AM, Math, Wash. U. St. Louis Joan Rivers
(e-mail address removed) Fine print:
http://www.math.wustl.edu/~msh210/ ... legal.html