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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:56:04+00:00 2026-05-13T07:56:04+00:00

I am currently trying the following xpath //tr[normalize-space(td/text())=’User Name’] to get all the tr

  • 0

I am currently trying the following xpath

//tr[normalize-space(td/text())='User Name']

to get all the tr that contains a td that contain 'User Name' or 'User Name' or ' User Name ' but its not working and I don’t know what is wrong with the query 🙁
the data i want to find is in the following format

<tr><td>User Name</td></tr>
<tr><td>User     Name</td></tr>
<tr><td>  User Name   </td></tr>

So what is the right format to write this xpath query?

Edit:
it seem not work if the data is in the following format

<tr><td>x</td><td>User Name</td></tr>
<tr><td>x</td><td>y</td><td>User     Name</td></tr>
<tr><td>x</td><td>y</td><td>z</td><td>  User Name   </td></tr>

so now how can i write the xpath query?
note: “//tr[normalize-space(td/text()) = ‘User Name’]” wont work
but “//tr/td[normalize-space(text()) = ‘User Name’]” will work (but i want to get the tr and not the td element)

  • 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-05-13T07:56:04+00:00Added an answer on May 13, 2026 at 7:56 am

    Now that you’ve edited the question, it makes sense. Let’s consider this input:

    <tr><td>x</td><td>User Name</td></tr>
    

    and your non-working query:

    //tr[normalize-space(td/text()) = 'User Name']
    

    Now, td/text() means “select all child text nodes of all child td nodes of current node”. In this case this will yield a node-set consisting two text nodes, x and User Name.

    Now you call normalize-space() on that node-set. The type of the sole argument of normalize-space() is string?. Since a node-set is not a string, conversions kick in, per section 3.2 of XPath 1.0 recommendation:

    An argument is converted to type string as if by calling the string() function.

    Now let’s look at the definition of string() in section 4.2:

    A node-set is converted to a string by returning the string-value of the node in the node-set that is first in document order. If the node-set is empty, an empty string is returned.

    In our example, the first node “in document order” is the text node x, so it is the one which will be used; the second node is ignored. Thus, you end up calling normalize-space('x'). Naturally, this won’t compare equal to ‘User Name’. To make this work, use:

    //tr[td[normalize-space(text()) = 'User Name']]
    

    This can be transcribed as “select all tr nodes that have child td nodes, the first child text() node of which has a normalized string value of User Name” – which is what you want. Furthermore, you can simplify this to:

    //tr[td[normalize-space() = 'User Name']]
    

    Since a no-argument normalize-space() will apply to the current node (which will be td), and process all text nodes within.

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

Sidebar

Related Questions

I'm currently trying to do the following: Trigger: click on a name in a
I am currently trying to get the following to compile: class foo { };
I am currently trying to get the following statement to work: SELECT t1.id, t1.row2
I'm currently trying to make some ajax post between cross-domains by following this tutorial
I am currently trying to learn about OpenGL ES for the iPhone and following
I'm currently trying to store images in a psql table and was following this
currently I'm trying to find a regular expression with the following condition: Match: FOO_.*
Currently I'm trying to write my first Python library and I've encountered the following
I'm currently following the third tutorial listed here: here where I'm trying to compile
i'm trying to make the following routes .. and currently i'm going about this

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.