0

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by fpmurphy
0

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 version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes" />

  <xsl:template match="/" >
    <xsl:element name="PO">
    <xsl:copy-of select="//ITEM[ID='1000']" />
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.