| Author |
Xpath expression
|
Shoba Ramachandran
Ranch Hand
Joined: Mar 29, 2001
Posts: 68
|
|
Hi, I have a xml like this..... <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="order.xsl"?> <order number="312597"> <date>2000/1/1</date> <customer id="216A">Company A</customer> <item> <part-number warehouse="Warehouse 11">E16-25A</part-number> <description>Production-class widget</description> <quantity>16</quantity> </item> <customer id="216B">Company B</customer> <item> <part-number warehouse="Warehouse 12">E16-25B</part-number> <description>Production-class widgetA</description> <quantity>20</quantity> </item> </order> and a xsl like this.... <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:for-each select="/order/customer[@id='216B']"> <xsl:value-of select="."/> </xsl:for-each> </xsl:template> </xsl:stylesheet> I want to print all the order elements that has an element customer whose id = 216B. But /order/customer[@id='216B'] gives the customer element whose id = 216B. Please let me know what is the correct expression. Thanks shoba
|
 |
John Wetherbie
Rancher
Joined: Apr 05, 2000
Posts: 1441
|
|
When you say you want to print the order elements do you mean you just want to print the order number? Could you give an example of the output you want? If the order number is what you want then substituting ../@number for . in your xsl:value-of element should get it (since . selects the current context node and .. selects its parent). Hope that helps.
|
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
|
 |
Shoba Ramachandran
Ranch Hand
Joined: Mar 29, 2001
Posts: 68
|
|
Hi, Thanks for your replies. ../@number works if I want to print only the number attribute of order. what if I want to print everything (all child elments like data, customer, item etc) of order, what would be the expression? Thanks Shoba
|
 |
Neetha Kasuganti
Greenhorn
Joined: Oct 15, 2001
Posts: 24
|
|
|
just ".." in the value-of stmt will do.
|
Neetha<br />IBM certified developer - XML and related technologies<br />SCJP2
|
 |
John Wetherbie
Rancher
Joined: Apr 05, 2000
Posts: 1441
|
|
|
Would it be .. or ../*? One of those should do it.
|
 |
Shoba Ramachandran
Ranch Hand
Joined: Mar 29, 2001
Posts: 68
|
|
Thanks John and Neetha, .. works. Thanks very much. -Shoba
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Xpath expression
|
|
|