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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:00:02+00:00 2026-06-06T08:00:02+00:00

How do I use the and operator ‘|’ to compute 2 node sets? In

  • 0

How do I use the and operator ‘|’ to compute 2 node sets? In other words, compute data of 2 siblings with different tag names. In this case : I want data from both edition and edition2 tags. I tried ‘| and it didn’t work.

XML :

<?xml version="1.0" encoding="utf-8"?>
<wikimedia>
  <projects>
    <project name="Wikipedia" launch="2001-01-05">
      <editions>
        <edition language="English">en.wikipedia.org</edition>
        <edition language="German">de.wikipedia.org</edition>
        <edition language="French">fr.wikipedia.org</edition>
        <edition language="Polish">pl.wikipedia.org</edition>
        <edition language="Spanish">es.wikipedia.org</edition>
        <edition2 language="Spanglish">egs.wikipedia.org</edition2>
        <img src="hello.gif">hello</img>
      </editions>
    </project>
    <project name="Wiktionary" launch="2002-12-12">
      <editions>
        <edition language="English">en.wiktionary.org</edition>
        <edition language="French">fr.wiktionary.org</edition>
        <edition language="Vietnamese">vi.wiktionary.org</edition>
        <edition language="Turkish">tr.wiktionary.org</edition>
        <edition language="Spanish">es.wiktionary.org</edition>
        <edition2 language="Spanglish">egs.wiktionary.org</edition2>
        <img src="hello.gif">hello</img>
      </editions>
    </project>
  </projects>
</wikimedia>

Python :

>>> wikixml.xpath('//edition/text() | edition2/text()')
['en.wikipedia.org', 'de.wikipedia.org', 'fr.wikipedia.org', 'pl.wikipedia.org', 'es.wikipedia.org', 'en.wiktionary.org', 'fr.wiktionary.org', 'vi.wiktionary.org', 'tr.wiktionary.org', 'es.wiktionary.org']

EDIT

I got it working after the answer but I also want to select the value of img/@src
I managed to do this using the union operator |

>>> wikixml.xpath('//edition/text() | //edition2/text() | //img/@src')
['en.wikipedia.org', 'de.wikipedia.org', 'fr.wikipedia.org', 'pl.wikipedia.org', 'es.wikipedia.org', 'egs.wikipedia.org', 'hello.gif', 'en.wiktionary.org', 'fr.wiktionary.org', 'vi.wiktionary.org', 'tr.wiktionary.org', 'es.wiktionary.org', 'egs.wiktionary.org', 'hello.gif']

How to do this using a single predicate and the self notation like it’s done here with two elements

/wikimedia/projects/project/editions/ *[self::edition or self::edition2]/text()

now that we have @src and text()?

  • 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-06T08:00:15+00:00Added an answer on June 6, 2026 at 8:00 am

    Use

    wikixml.xpath('//edition/text() | //edition2/text()')
    

    or more efficiently

    wikixml.xpath('//*[self::edition or self::edition2]/text()]
    

    or even better

    wikixml.xpath('/wikimedia/projects/project/editions/*[self::edition or self::edition2]/text()]
    

    As for the question update

    I also want img’s @src too. How to do this with the self notation now
    that we have @src and text()?

    Honestly, I don’t know if there’s a way to select from both the element and attribute axes at the same time using the above notation. I doubt it.

    You can either do it with a single XPath, but giving up the self::notation (at least for the attribute):

    /wikimedia/projects/project/editions/ *[self::edition or self::edition2]
    |
    /wikimedia/projects/project/editions/img/@src
    

    or select edition, edition2 and all elements containing an src attribute

    /wikimedia/projects/project/editions/ *[self::edition or self::edition2 or attribute::src]
    

    and then process the result to fetch the value of src

    That’s about as much as you can do in XPath 1.0
    As per Dimitre Novatchev’s suggestion, XPath 2.0 allows you to write it this way:

    /wikimedia/projects/project/editions/(*[self::edition or self::edition2] | img/@src )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use operator() as a subscript operator this way: double CVector::operator() (int i) const
When must we use this operator by events? What is its usage?
How to use ternary operator with System::Boolean? This sample code always returns true: bool
In this question , I use xor operator between enum with [Flags] attribute as
I'm trying to use operator overloading to define the basic operations (+,-,*,/) for my
When must we use checked operator in C#? Is it only suitable for exception
I know that we cant use assignment operator in if statements in java as
While using the vector why do we sometime use the operator[] like homework[mid] but
I want to derive a stringstream so that I can use the operator<< to
I'm wondering if you can overload an operator and use it without changing the

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.