Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Wed, 20 Aug 2008 06:21:38 -0700 (PDT),    group: microsoft.public.xsl        back       


Is this the best way to operate on a specific data item?   
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?
date: Wed, 20 Aug 2008 06:21:38 -0700 (PDT)   author:   Brian Kendig

Re: Is this the best way to operate on a specific data item?   
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/
date: Wed, 20 Aug 2008 15:33:12 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us