I have an XML file containing news items, each of which has a date associated with it. I want to display only the news item with the most recent date. This is the approach I'm using: <xsl:for-each select="//newsItem"> <xsl:sort select="date" order="descending"/> <xsl:if test="position() = 1"> ... </xsl:if> </xsl:for-each> Is there a more sophisticated solution?
Brian Kendig wrote: > I have an XML file containing news items, each of which has a date > associated with it. I want to display only the news item with the most > recent date. > > This is the approach I'm using: > > <xsl:for-each select="//newsItem"> > <xsl:sort select="date" order="descending"/> Make sure the date element has content in a sortable format like YYYY-MM-DD or YYYYMMDD. > <xsl:if test="position() = 1"> > ... > </xsl:if> > </xsl:for-each> > > Is there a more sophisticated solution? With XSLT 2.0 you can also use the max function e.g. <xsl:value-of select="max(date)"/> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/