|
Subject: Re: [xsl] Sort list based on matching equal to another element From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 27 Sep 2001 17:12:28 +0100 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Sort list based on matching e, Linda Zammit | Thread | [xsl] Re: Re: loop in creation of t, Dimitre Novatchev |
| RE: [xsl] SAXON and UTF-8, Michael Kay | Date | RE: [xsl] SAXON and UTF-8, Julian Reschke |
| Month |