Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:57+00:00 2026-06-12T10:14:57+00:00

Given the following structure, in XPATH, I want to select the entire tree but

  • 0

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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:14:59+00:00Added an answer on June 12, 2026 at 10:14 am

    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:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="DATE[preceding::DATE]"/>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <A>
        <B>
            <DATE>04272011</DATE>
            <C>
                <D>
                    <DATE>02022011</DATE>
                </D>
                <D>
                    <DATE>03142011</DATE>
                </D>
            </C>
        </B>
    </A>
    

    the wanted, correct result is produced:

    <A>
       <B>
          <DATE>04272011</DATE>
          <C>
             <D/>
             <D/>
          </C>
       </B>
    </A>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following tree structure in Haskell: data Tree = Leaf Int | Node
Given the following structure: City Area User Every Area has 1 and only 1
Given the following simple table structure (SQL Server 2008), I want to be able
Given the following structure, how to copy the first and the second nodes with
Given the following XML structure: <root> <data>x</data> <details> <some_other_element>...</some_other_element> <collection> <element><a>1</a></element> <element><a>2</a></element> <element><a>3</a></element> <collection>
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have a necessity to sort a given HTML table of the following structure,
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
Given the following structure typedef struct { float3 position; float8 position1; } MyStruct; I'm
Given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.