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 8390725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:04:38+00:00 2026-06-09T19:04:38+00:00

I have an XML Like the following, and i want select just the elements

  • 0

I have an XML Like the following, and i want select just the elements “b” and “c” childrens of “a” using xpath filtering in xslt

<a>
  <b>data_1</b>
  <c>data_1</c>
  <d>data_1</d>
  <e>data_1</d>
</a>
<a>
  <b>data_2</b>
  <c>data_2</c>
  <d>data_2</d>
  <e>data_2</d>
</a>
<a>
  <b>data_3</b>
  <c>data_3</c>
  <d>data_3</d>
  <e>data_3</d>
</a>

Suggestions?

  • 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-09T19:04:39+00:00Added an answer on June 9, 2026 at 7:04 pm

    First, do notice that you haven’t provided a well-formed XML document. By definition a well-formed XML document must have a single top element.

    I assume in this answer, that all a elements are children of this single top element, that isn’t shown in the question.


    Use:

    /*/a/*[self::b or self::c]
    

    This selects any element that is either b or c and that is a child of any aelement that is a child of the top element of the XML document.

    Do note that the currently-accepted answer is incorrect:

    /a/*[self::a or self::b or self::c]
    

    Not only it supposes that there is a single a top element (and there isn’t such), but given a specific XML document, it would select, besides the wanted elements, also any a element that is a child of the top element a.

    The XPath expression that I recommend above:

    /*/a/*[self::b or self::c]
    

    is more efficient than another, correct XPath expression that is proposed in one of the other answers:

    /a/b | /a/c
    

    This requires evaluatiing separately /a/b/ and /a/c and then performing the set-union of the results of the two evaluations.

    The XPath expression that I recommend needs only a single scan of the document, requires no union and can be used even in streaming mode over an unlimited in size, huge XML document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a xslt stylesheet like the following: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
I have an XML File with Elements that look like the following: <level> <name>Name
I have an xml like the following <DataCollection> <Data> <Name>John</Name> <Age>30</Age> </Data> ... more
I have an XML document which contains nodes like following:- <a class=custom>test</a> <a class=xyz></a>
If I have some xml containing things like the following mediawiki markup: ...collected in
i have the following question: I have a XML file with some elements that
I have XML like <A> <B> <C> Hello World </C> </B> </A> I want
Say I have an XML file like the following: <holidays> <holiday1 val=New Years, 01/01,
I have the following XML document: <root someAttribute=someValue /> Now I want to add
I have a bunch of xml elements formatted like so: <WP featured=yes player=no dancers=no

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.