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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:33:51+00:00 2026-06-05T12:33:51+00:00

This question is a continuation of Can XPath return only nodes that have a

  • 0

This question is a continuation of Can XPath return only nodes that have a child of X? .

I want to find all “pets” that have foo, where some pets have a namespace and other pets do not.

Is it possible to use XPath to select only the nodes that have a particular child elements? For example, from this XML I only want the elements in pets that have a child of ‘bar’. So the resulting dataset would contain the lizard and pig elements.

<pets xmlns="urn:cat-org:v1">
  <cat>
    <foo>don't care about this</foo>
  </cat>
  <dog xmlns:v1="urn:cat-org:v1">
     <v1:foo>not this one either</foo>
  </dog>
  <lizard>
     <bar>lizard should be returned, because it has a child of bar</bar>
  </lizard>
  <pig xmlns:v55="urn:cat-org:v1">
     <v55:bar>return pig, too</bar>
  </pig>
</pets>

Any advice would rock.

  • 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-05T12:33:52+00:00Added an answer on June 5, 2026 at 12:33 pm

    For example, from this XML I only want the elements in pets that have
    a child of ‘bar’.

    Use:

    /*/*[*[local-name() = 'bar']]
    

    This selects all children of the top element that have at least one child with local name "bar" (regardless of prefixes if such exist).

    XSLT – based verification:

    <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="/">
         <xsl:copy-of select="/*/*[*[local-name() = 'bar']]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document (corrected to be made well-formed):

    <pets xmlns="urn:cat-org:v1">
      <cat>
        <foo>don't care about this</foo>
      </cat>
      <dog xmlns:v1="urn:cat-org:v1">
         <v1:foo>not this one either</v1:foo>
      </dog>
      <lizard>
         <bar>lizard should be returned, because it has a child of bar</bar>
      </lizard>
      <pig xmlns:v55="urn:cat-org:v1">
         <v55:bar>return pig, too</v55:bar>
      </pig>
    </pets>
    

    the XPath expression is evaluated and the selected elements are copied to the output:

    <lizard xmlns="urn:cat-org:v1">
       <bar>lizard should be returned, because it has a child of bar</bar>
    </lizard>
    <pig xmlns="urn:cat-org:v1" xmlns:v55="urn:cat-org:v1">
       <v55:bar>return pig, too</v55:bar>
    </pig>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation of the question here: JBoss - does app have to
Possible Duplicate: Continue Execution Only After .each() Completes This question is actually a continuation
This is a continuation of my previous question: Could not find an implementation of
This is a continuation of a previous question . I have: var X =
This is sort of a continuation of this question . I have a file
This is a continuation of my previous question: In Perl, how can I check
This a continuation of this question. I have an Address class which contains basic
This is a continuation of the project outlined in this question. I have the
This is a continuation of another question I have. Consider the following code: char
As a continuation of this question I'm wondering if I can get some simple

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.