以下是我代码的缩略例子。
I want to calculate the average target_value of each entry in a group (or gid) In a simple pseudocode this would be written in the following way:
total target_value of entries with gid "001" / amount of entries with gid "001"
However, since XML is fairly new to me, I wish to know how to reuse the values already calculated (see the XSL below) for further calculations? Is variables the most effective way to go, and if so, where/how should they be defined?
XML: (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑) (笑)
<root>
<entry gid ="001">
<level_1>
<target_value>50</target_value>
</level_1>
</entry>
<entry gid ="001">
<level_1>
<target_value>30</target_value>
</level_1>
</entry>
</root>
XSL :
<xsl:value-of select="sum(entry[@gid= 001 ]/level_1/target_value)" />
Result: 80
任何帮助都会大受欢迎!