Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to use XSL to do a multi-layer lookup

Status
Not open for further replies.

TheAggie

Programmer
Aug 27, 2002
48
0
0
US
Here is an example of the XML input file I will receive: Note: The example is fictious but illustrates the point
Note: The flat structure is something I can't change
Note: Hopefully not too many typos since I am making this up
<OrderData>
<Vendor>
<ID>1</ID>
<Name>Vendor X</Name>
</Vendor>
<Vendor>
<ID>2</ID>
<Name>Vendor Y</Name>
</Vendor>
...
<Product>
<ID>1</ID>
<Name>Product X</Name>
<VendorID>1</VendorID>
</Product>
...
<Order>
<ID>1</ID>
<OrderItem>
<ProductID>1</ProductID>
<Quantity>10</Quantity>
</OrderItem>
<OrderItem>
<ProductID>2</ProductID>
<Quantity>12</Quantity>
</OrderItem>
...
</Order>
...
</OrderData>

How could I use XSL to list all the order IDs grouped for each vendor? That is, iterate through each vendors/products then scan each OrderItem to see if the order includes a product made by that vendor.

It looks like a nested for-each each with the node set being the root. But, can I do that? Can the inside for-each of a nested set process a node set that is larger than the current node set?

Thanks,
Mark (XML/XSL Newbie)
 
Hi Mark,

You are looking for grouping.

Are you using XSL 1.0 or XSL 2.0?

Grouping is easier in XSL 2, but it is doable in XSL 1. See my FAQ at faq426-6585.

Each for-each iterates over a node-set. The only complication is that, within a for-each, the context is that of the node. This may make the select clause of the inner for-each a bit more complicated.

(PS given your handle, are you in/from Texas?)

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top