如何在3个数字中找到最大的2个数字并对它们执行一些算术运算,如下例所示?
<root> <num>10</num> <num>12</num> <num>8</num> </root>
对于上面的输入,xslt代码应显示“10 12 = 22”和“average = 11”.
这个样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/root"> <xsl:variable name="max1" select="num[not(../num > .)]"/> <xsl:variable name="max2" select="num[not(../num[count(.|$max1)!=1] > .)]"/> <xsl:value-of select="concat($max1,' + ',$max2,' = ',$max1 + $max2,'
','average = ',($max1 + $max2) div 2,'
')"/> </xsl:template> </xsl:stylesheet>
输出:
12 + 10 = 22 average = 11
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。