• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xpath expression

 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just ".." in the value-of stmt will do.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be .. or ../*? One of those should do it.
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John and Neetha,
.. works. Thanks very much.
-Shoba
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic