[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Node Selection

Subject: Re: Node Selection
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 14 Jun 2001 21:52:23 -0700 (PDT)
xsl sort last node
Decarli, Jim wrote:
> 
> I am using Xalan for xsl transformations.  I have some xml with multiple
> <Activity> nodes in it for each part that is processed.  The activity nodes
> are not sorted in any way in the xml.  I want to select only the latest
> activity (by Date, Time) to process in the transform for my output to show
> the last activity scan on this part and ignore all other activity scans.
> Here is an example of the xml.
> <Part> 
> 	<PartNumber>978599</PartNumber> 
> 	<Activity> 
> 		<ActivityLocation> 
> 			<DepartmentNumber>07</DepartmentNumber> 
> 			<DepartmentName>Grinding</DepartmentName> 
> 		</ActivityLocation> 
> 		<Status> 
> 			<Code>I</Code> 
> 			<Description>In-Process</Description> 
> 		</Status> 
> 		<Date>20010521</Date> 
> 		<Time>180800</Time> 
> 	</Activity>
> 	<Activity> 
> 		<ActivityLocation> 
> 			<DepartmentNumber>07</DepartmentNumber> 
> 			<DepartmentName>Grinding</DepartmentName> 
> 		</ActivityLocation> 
> 		<Status> 
> 			<Code>R</Code> 
> 			<Description>Received</Description> 
> 		</Status> 
> 		<Date>20010520</Date> 
> 		<Time>081800</Time> 
> 	</Activity>
> 	<Activity> 
> 		<ActivityLocation> 
> 			<DepartmentNumber>05</DepartmentNumber> 
> 			<DepartmentName>Shipping</DepartmentName> 
> 		</ActivityLocation> 
> 		<Status> 
> 			<Code>S</Code> 
> 			<Description>Shipped</Description> 
> 		</Status> 
> 		<Date>20010523</Date> 
> 		<Time>073300</Time> 
> 	</Activity>
> 	<Activity> 
> 		<ActivityLocation> 
> 			<DepartmentNumber>05</DepartmentNumber> 
> 			<DepartmentName>Shipping</DepartmentName> 
> 		</ActivityLocation> 
> 		<Status> 
> 			<Code>R</Code> 
> 			<Description>Received</Description> 
> 		</Status> 
> 		<Date>20010523</Date> 
> 		<Time>060700</Time> 
> 	</Activity>
> </Part>

Hi Jim,

This problem is solved best using a generic max() template. Or you can use my
generic sort() template, which allows only the highest k out of N nodes to be
produced -- in your case k=1.

The other alternatives -- xsl:sort on the full node-set and using only the
first/last node from the nodelist; using a custom-made max() template -- these are
wasting both space and time.

The code of the generic templates for:
 generic max(), 
 generic min(),
 generic binSearch(),
 generic sort()

can be downloaded at 
http://www.vbxml.com/downloads/default.asp?id=v2001611171627

Some more detailed explanation of the concept of generic templates and their
implementation using template references can be found at:

http://lists.fourthought.com/pipermail/exslt/2001-May/000169.html


Cheers,
Dimitre.

__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.