xsl-list
[Top] [All Lists]

[xsl] RE: Filter by id and date

2011-09-05 06:25:04
As usual, the solution came to me after I hit send.

normalize-space(//item[@id=$idref][@date=max(//item[@id=$idref]/@date)])

seemed to be enough to do the trick (putting the "//item[@id=$idref]" into a 
variable would be an improvement, but that's the general principle). Thanks for 
listening to my monologue anyway. :)


-----Original Message-----
From: Emma Burrows [mailto:Emma(_dot_)Burrows(_at_)rpharms(_dot_)com]
Sent: 05 September 2011 10:36
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Filter by id and date

Hopefully a quick question. Using XSLT 2.0, I am filtering entries in an input 
file based on their ids. The only problem is that I've been given an update to 
the original input file which includes many duplicates, some of which are 
identical and some of which have been updated. For any given id, I need to look 
up the item with the most recent date.

So say I have the following input file:

<items>
  <item id='1' date='2011'>Item1</item>
  <item id='2' date='2009'>Item2</item>
  <item id='3' date='2002'>Item3</item>
  <item id='2' date='2011'>Item2</item>
  <item id='3' date='2002'>Item3</item>
</items>

For example, the Xpath in question looks like this right now (long-winded but 
more efficient path-finding syntax simplified to // for this example, and 
$idref obviously contains a valid id):

<xsl:value-of select="normalize-space(//item[@id=$idref])"/>

What is the best way to filter that to return only the item whose @date is the 
highest for all items with @id=$idref?

Thanks!


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>