如何取出xml中属性相同的节点数据????????高手帮帮忙!!!!!!
xml文件是这样的:
<units>
<unit>
<unitCode> FIT2028 </unitCode>
<student id= "s12233441 ">
<firstname> Bilbo </firstname>
<surname> Baggins </surname>
<assignments>
<assignment assNo= "1 "> 80 </assignment>
<assignment assNo= "2 "> 90 </assignment>
<unitTest> 75 </unitTest>
</assignments>
</student>
<student id= "s12233442 ">
<firstname> Bilbo </firstname>
<surname> Baggins </surname>
<assignments>
<assignment assNo= "1 "> 80 </assignment>
<assignment assNo= "2 "> 90 </assignment>
<unitTest> 75 </unitTest>
</assignments>
</student>
</unit>
<unit>
<unitCode> FIT3043 </unitCode>
<student id= "s12233441 ">
<firstname> Bilbo </firstname>
<surname> Baggins </surname>
<assignments>
<assignment assNo= "1 "> 45 </assignment>
<assignment assNo= "2 "> 40 </assignment>
<unitTest> 50 </unitTest>
</assignments>
</student>
</unit>
</units>
要在网页上显示成是这样的:
ID Name FIT2028 FIT3043
---------------------
s12233441 Bilbo Baggins 81.67 45.00
如果在两个unit中student的属性id相同,就取出id,name,与平均值.
其中:FIT2028这一列是在第一个unit中的平均值,FIT3043这一列是在第二个unit中的平均值.
现在不知道xsl怎么写!!!请高手帮帮忙啊!!!!!!!先谢了.
[解决办法]
只写了平均值那部分功能。
<?xml version= "1.0 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:template match= "/ ">
<xsl:for-each select= "//unit ">
<xsl:for-each select= "student[@id=preceding::student/@id] ">
<xsl:variable name= "id " select= "@id "/>
<xsl:value-of select= "@id "/>
<xsl:text> </xsl:text>
<xsl:value-of select= "firstname "/>
<xsl:text> </xsl:text>
<xsl:value-of select= "surname "/>
<xsl:text> </xsl:text>
<xsl:value-of
select= "sum(preceding::student[@id=$id]/assignments/assignment) div 2 "/>
<xsl:text> </xsl:text>
<xsl:value-of select= "sum(assignments/assignment) div 2 "/>
</xsl:for-each> <br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>