我有一个xml文件,其中包含多个类型为' advert'的元素。最后一个包含作为子元素的价格。
我想使用浏览所有项目的xsl:sort
和xsl:for-each
提取最高价格值。
答案 0 :(得分:2)
As stated in the comments for other members, max simply could be used as is without the need of xslt sort and xslt for-each.
To be able to use the xsl in xsl as is, here is a simple piece of code to try:
<xsl:variable name="the_max">
<xsl:for-each select="Node/Item/year">
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$the_max"/>
using XSL values as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Node>
<Item><year>1985</year></Item>
<Item><year>1986</year></Item>
<Item><year>1987</year></Item>
<Item><year>1988</year></Item>
<Item><year>1989</year></Item>
<Item><year>1909</year></Item>
<Item><year>1991</year></Item>
<Item><year>1992</year></Item>
<Item><year>1993</year></Item>
<Item><year>1994</year></Item>
<Item><year>1995</year></Item>
<Item><year>1996</year></Item>
</Node>