Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 获取xsl中元素值的平均值_Xml_Variables_Xslt_Average - Fatal编程技术网

Xml 获取xsl中元素值的平均值

Xml 获取xsl中元素值的平均值,xml,variables,xslt,average,Xml,Variables,Xslt,Average,今天我第一次处理xsl。我拥有的XML文件如下所示: <student_course> <students> <student num=""> <name gender=""></name> <course cid="1"></course> <course cid="2"></course> <course cid="3"></c

今天我第一次处理xsl。我拥有的XML文件如下所示:

<student_course>
<students>
    <student num="">
    <name gender=""></name>
    <course cid="1"></course>
    <course cid="2"></course>
    <course cid="3"></course>
    <course cid="4"></course>
    <comments></comments>
    </student>  
</students>
<courses>
    <course cid="1"></course>
    <course cid="2"></course>
    <course cid="3"></course>
    <course cid="4"></course>
</courses>
</student_course>

有10多名学生,我需要打印每个学生每门课程的所有成绩。我已经用过了。我需要做的是,在列的底部,显示该课程(学生/课程)的平均分数。我认为应该使用一个变量,然后在for each中增加它,然后除以它或其他什么,但这似乎不起作用,每次我尝试创建一个变量时,我只能在设置后立即调用它,我一定是做错了什么。如何获得
学生课程/学生/学生/课程[@cid]
下所有值的平均值

目前,我的xsl显示了一个表,其中有4列11行(标题为1行,学生成绩为10行),然后第12行显示平均值


提前感谢

我明白了。要获得平均值,最简单的方法是对each和sum()和count()函数使用a。我所需要的只是在我想要显示平均值的地方添加以下内容:

<xsl:value-of select="sum(/student_course/students/student/course[@cid='1']) div count(/student_course/students/student/course[@cid='1'])"/>


只需更改不同课程的cid值。

如果您的示例数据包含您想要平均的成绩值,并且如果您向我们展示了您想要输出的结果,这将对我们有所帮助。很好,我只是想知道我需要什么,所以我将发布我自己的答案。您也可以在
xsl:for each
之外使用相同的代码行,这样它就只显示一次。