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

Re: Sort list based on matching equal to another eleme

Subject: Re: Sort list based on matching equal to another element
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 27 Sep 2001 17:12:28 +0100
shipment_gid
Hi Linda,

> The list I have displays the LOCATION_NAME sorted by
> LOCATION_NAME & START_TIME.
>
> I need the COST to display in the next table cell, by
> matching the SHIPMENT_GID from the REPORT_CUSTOMER
> element to the REPORT_COST element.
>
> This is what I have for the list of the SHIPMENT_GID
> from the REPORT_CUSTOMER - which works great but I
> can't figure out how to display the associated cost
> for the matching SHIPMENT_GID.

I think from what you've described you want to take the SHIPMENT_GID
from the current REPORT_CUSTOMER and use that to access the
COST element that has that particular value for its sibling
SHIPMENT_GID.

Whenever you want to repeatedly access a set of elements by their
value on a particular child (or attribute), you should use a key to
make the search more efficient. So you should set up a key that
indexes the COST elements by their SHIPMENT_GID like so:

<xsl:key name="costs-by-gid"
         match="COST"
         use="parent::ROW/parent::REPORT_COST/ROW/SHIPMENT_GID" />

Now if you have a GID of '123' you could get the COST for that
shipment with:

  key('costs-by-gid', '123')

If the GID is held in the SHIPMENT_GID child element of the current
ROW then you can display the value with:

  <xsl:value-of select="key('costs-by-gid', SHIPMENT_GID)" />

or if you're iterating over elements that have the SHIPMENT_GID
elements as their children then you can sort on that value with:

  <xsl:value-of select="key('costs-by-gid', SHIPMENT_GID)" />

Note that you need something a little bit more complicated given the
XML that you describe because the ROW elements that you're iterating
over are not the ROW elements that contain the SHIPMENT_GID for a
particular REPORT_CUSTOMER.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.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.