XML文件如下:
<Item>
<Status>Pass</Status>
</Item>
<Item>
<Status>Pass</Status>
</Item>
<Item>
<Status>Fail</Status>
</Item>
怎样使用xsl统计出Pass和Fail的次数?以及Pass和Fail占总数的百分比?
------解决方案--------------------
- XML code
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:value-of select="count(//Item/Status[.='Pass'])"/><br/> <xsl:value-of select="count(//Item/Status[.='Fail'])"/><br/> <xsl:value-of select="count(//Item/Status[.='Fail'])*100 div count(//Item/Status)"/> </xsl:template> </xsl:stylesheet>
------解决方案--------------------
稍加改动即可,保留2位用 10000, 保留1位用 1000 ,以此类推
- XML code
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:value-of select="count(//Item/Status[.='Pass'])"/> <br/> <xsl:value-of select="count(//Item/Status[.='Fail'])"/> <br/> <xsl:value-of select="concat(string(round(count(//Item/Status[.='Pass'])*10000 div count(//Item/Status)) div 100),'%')"/> </xsl:template> </xsl:stylesheet>