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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:56:38+00:00 2026-06-17T07:56:38+00:00

I would like to get to most inner div in a html document that

  • 0

I would like to get to most inner div in a html document that has the id or class containing “content”.

What I have tried:

//div[@id[contains(.,'content') and not(*)]]

This works for getting the most inner div with an id containing “content”.

Now I want to get the most inner div by id or class (depends on whats the most inner is) containing the id or class “content”.

Sample data:

<body>
<div class="outerContent">
    <div id="moreContent">
        <div class="anotherContent">
            This is what I am looking for.
        </div>
    </div>
</div>
</body>

or

<body>
<div class="outerContent">
    <div id="moreContent">
        <div id="anotherContent">
            This is what I am looking for.
        </div>
    </div>
</div>
</body>

Note that “This is what I am looking for” could be inside a div class conainting “content” or a div id containing “content”.

Thank you!

  • 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-17T07:56:39+00:00Added an answer on June 17, 2026 at 7:56 am

    This answer uses only XPath 1.0 expressions. My understanding is that XPath 2.0 isn’t available.

    Use:

    //div[contains(@id, 'Content') or contains(@class, 'Content')]
           [not(descendant::div[contains(@id, 'Content') or contains(@class, 'Content')])]
    

    This selects any div element whose id attribute has string value that contains the string "content", or whose class attribute has string value that contains the string "content", and that has no descendant div elements with this properties.

    Do note, that such thing as “the most inner div” may not be singular — that is, many div elements may exist such that they fulfill the conditions set in the question.

    If this is the case, and you need just one such div element (say, the 1st), you can use:

    (//div[contains(@id, 'content') or contains(@class, 'content')]
            [not(descendant::div[contains(@id, 'content') or contains(@class, 'content')])]
    )[1]
    

    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=
         "//div[contains(@id, 'Content') or contains(@class, 'Content')]
           [not(descendant::div[contains(@id, 'Content') or contains(@class, 'Content')])]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the first provided XML document:

    <body>
        <div class="outerContent">
            <div id="moreContent">
                <div class="anotherContent">
                This is what I am looking for.
                </div>
            </div>
        </div>
    </body>
    

    the Xpath expression is evaluated and the result of this evaluation is copied to the output:

    <div class="anotherContent">
                This is what I am looking for.
                </div>
    

    With the second document, again the correct result is produced:

    <div id="anotherContent">
                This is what I am looking for.
            </div>
    

    Finally, in case the comparisson for “Content” should be case-independet, use:

      //div[contains(translate(@id,'CONTE','conte'), 'content')
          or contains(translate(@class,'CONTE','conte'), 'content')
           ]
             [not(descendant::div
                   [contains(translate(@id,'CONTE','conte'), 'content')
                   or contains(translate(@class,'CONTE','conte'), 'content')
                   ]
                  )
             ] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lab values table that I would like to query and get
I would like to get the most out of working in cch or tcsh
I would like to get View instance that is used to display specific Preference
I would like to get the generic information ( Counter class) of my CounterPersistence
I would like to get the dimensions (coordinates) for all the HTML elements of
I have a MySQL table with data, and would like to select the most
How do I get the first element that has an inner text (plain text,
I would like to get started with developing NFC apps for android. I have
I would like to get a regexp that will extract out the following. I
I have a system that tracks what documents users view. Each document has its

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.