在有关计数之前已经发布了问题;我正在寻找一种如何提出国际平均高度的方法,以及高低功能,显示从最高到最小的高度...
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="soccer.xslt"?>
<footballclub>
<player>
<based>international</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>international</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>7.5</height >
<build>medium</build>
<age>34</age>
</player>
<player>
<based>international</based>
<height>5.9</height >
<build>large</build>
<age>26</age>
</player>
</footballclub>
此转换:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="vInter" select="/*/*[based='international']"/>
<xsl:template match="/">
Average height: <xsl:copy-of select="sum($vInter/height) div count($vInter)"/>
Height high to low:<xsl:text/>
<xsl:for-each select="$vInter/height">
<xsl:sort data-type="number" order="descending"/>
<xsl:value-of select="concat('
 ', .)"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
应用于提供的XML文档:
<footballclub>
<player>
<based>international</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>international</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>5.5</height >
<build>medium</build>
<age>24</age>
</player>
<player>
<based>local</based>
<height>7.5</height >
<build>medium</build>
<age>34</age>
</player>
<player>
<based>international</based>
<height>5.9</height >
<build>large</build>
<age>26</age>
</player>
</footballclub>
产生想要的,正确的结果:
Average height: 5.633333333333333
Height high to low:
5.9
5.5
5.5