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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:55:40+00:00 2026-06-05T16:55:40+00:00

This popular Stack Overflow question explained why CSS selectors are parsed right to left.

  • 0

This popular Stack Overflow question explained why CSS selectors are parsed right to left. Are XPath queries evaluated in the same way? If this is dependent on implementation I’d appreciate knowing how libxml2 does it.

  • 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-05T16:55:41+00:00Added an answer on June 5, 2026 at 4:55 pm

    You should take another careful read at the accepted answer for that question you reference.

    CSS selectors are evaluated right-to-left as an implementation detail for the specific scenario where a browser has a single element and is trying to determine which selectors in a CSS stylesheet apply to it. The reason browsers evaluate right-to-left in this case is because candidate selectors can be eliminated more quickly.

    There is nothing inherent to CSS selectors that demands they be evaluated right-to-left or left-to-right. In fact, jQuery or querySelectorAll will evaluate from left-to-right, as the answer notes.

    In other words:

    1. if you have one element and you are testing whether a selector matches it, it is usually faster to evaluate right-to-left as an optimization;
    2. but if you want all matching elements, it is usually faster to evaluate left-to-right.

    Scenario 1 fits best where you have an element to style (CSS) or an XSL stylesheet’s template match="??" (XPath) and you have a large number of selectors or XPaths to test. Scenario 2 fits best when you have a single selector or XPath and you want all matching elements, as when you use querySelectorAll or query a DOM.

    XPath expressions can be much more complex than CSS selectors, so there are probably XPaths where a right-to-left short-circuit evaluation is not possible or easy, but conceptually an XSLT engine could certainly try to do that. I don’t know if any do.

    The most important thing to understand is, however a CSS selector or XPath is evaluated, it must give the same answer as if it were evaluated left-to-right over the entire document tree. So you don’t need to evaluate left-to-right, but you must act as if you did because the specifications define them this way.

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

Sidebar

Related Questions

I know this question is overly popular, but I find nothing that addresses rewriting
In this popular question about why substring takes O(n) in C# , one of
I have this quite popular problem, but have failed to find a solution that
Often with very popular videos I see a ridiculous view count. See this video
I'm referring to this popular marked answer: Lazy load of images in ListView Perhaps,
I recently posted a question on stackoverflow about the less popular js function document.captureEvents()
mybatis' homepage has this quote mybatis, the world's most popular sql mapping framework There
Hi This is a pretty specific question, so I hope StackOverflow is meant for
You may think this question is like this question asked on StackOverflow earlier. But
This question is similar to the Remove html character entities in a string question

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.