Given the following structure, in XPATH, I want to select the entire tree but only include the first date thus excluding all of the other dates. The number of dates after the first date is not constant. Any ideas? My apologies is the format isn’t correct.
<A>
<B>
<DATE>04272011</DATE>
<C>
<D>
<DATE>02022011</DATE>
</D>
<D>
<DATE>03142011</DATE>
</D>
</C>
</B>
</A>
My appologies.
A better example
<NOTICES>
<SNOTE>
<DATE>01272011</DATE>
<ZIP>35807</ZIP>
<CLASSCOD>A</CLASSCOD>
<EMAIL>
<ADDRESS>address 1</ADDRESS>
</EMAIL>
<CHANGES>
<MOD>
<DATE>02022011</DATE>
<MODNUM>12345</MODNUM>
<EMAIL>
<ADDRESS>address 2</ADDRESS>
</EMAIL>
</MOD>
<MOD>
<DATE>03022011</DATE>
<MODNUM>56789</MODNUM>
<EMAIL>
<ADDRESS>address 3</ADDRESS>
</EMAIL>
</MOD>
</CHANGES>
</SNOTE>
</NOTICES>
I’m breaking up one large xml file into individual XML files. My original XPATH statement is
/NOTICES/SNOTE
Each individual xml file looks fine except it pulls in all of the dates: This is my desired output.
<SNOTE>
<DATE>01272011</DATE>
<ZIP>35807</ZIP>
<CLASSCOD>A</CLASSCOD>
<EMAIL>
<ADDRESS>address 1</ADDRESS>
</EMAIL>
<CHANGES>
<MOD>
<MODNUM>12345</MODNUM>
<EMAIL>
<ADDRESS>address 2</ADDRESS>
</EMAIL>
</MOD>
<MOD>
<MODNUM>56789</MODNUM>
<EMAIL>
<ADDRESS>address 3</ADDRESS>
</EMAIL>
</MOD>
</CHANGES>
</SNOTE>
XPath is a query language for XML documents and as such it cannot alter the structure of the document (such as insert/delete/rename nodes).
What you need is an XSLT transformation — as simple as this:
When this transformation is applied on the provided XML document:
the wanted, correct result is produced: