XPATH Question on Filtering / Condition

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 1
Reputation: hangon is an unknown quantity at this point 
Solved Threads: 0
hangon hangon is offline Offline
Newbie Poster

XPATH Question on Filtering / Condition

 
0
  #1
32 Days Ago
I have an xml like below
<PO>
<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>
<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>
<ITEM>
<ID>1001</ID>
<PRICE>10</PRICE>
</ITEM>
<ITEM>
<ID>1001</ID>
<PRICE>10</PRICE>
</ITEM>
</PO>

I want an xpath that will get only ID = 1000 and the output should be like below
<PO>
<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>
<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>
</PO>

I tried /PO/ITEM[ID="1000"] but it gives the following but I need even the root "PO" also...

<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>
<ITEM>
<ID>1000</ID>
<PRICE>10</PRICE>
</ITEM>

Thanks for the help
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 95
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 5
fpmurphy fpmurphy is offline Offline
Junior Poster in Training
 
0
  #2
23 Days Ago
As far as I know you cannot use an XPath expression to do what you want to do.

Here is how I get the result you are looking for
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.  
  4. <xsl:output method="xml" indent="yes" />
  5.  
  6. <xsl:template match="/" >
  7. <xsl:element name="PO">
  8. <xsl:copy-of select="//ITEM[ID='1000']" />
  9. </xsl:element>
  10. </xsl:template>
  11.  
  12. </xsl:stylesheet>
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC