This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
Joined: Mar 29, 2001
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