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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:06+00:00 2026-05-25T14:39:06+00:00

I have an XML document similar to the following: <tt> <a text=1/> <a text=2/>

  • 0

I have an XML document similar to the following:

<tt>
  <a text="1"/>
  <a text="2"/>
  ...
  <a text="n"/>

  <b text="14">data</b>
  <b text="2">data</b>
  ...
</tt>

How can I select all <b> elements that have text attribute not equal to the text attribute of any of the <a> elements? I’m using XPath 1.0.

I’ve thinking about something like tt/b[not (tt/a[@text = xxx::@text])], where xxx should refer to the tt/b element being examined. I don’t know how exactly it may be done.

  • 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-25T14:39:07+00:00Added an answer on May 25, 2026 at 2:39 pm

    An answer such as /tt/b[@text != ../a/@text] is wrong and selects the wrong set of nodes:

    <b text="14">data</b>
    <b text="2">data</b>
    

    As we see, the second selected node’s text attribute is 2 and there is an a element whose text attribute is 2.

    Here is a correct XPath expression:

    /tt/b[not(@text = ../a/@text)]
    

    When evaluated against the provided XML document:

    <tt>
      <a text="1"/>
      <a text="2"/>
      ...
      <a text="n"/>
    
      <b text="14">data</b>
      <b text="2">data</b>
      ...
    </tt>
    

    it correctly selects only one node:

    <b text="14">data</b>
    

    Explanation:

    By definition the XPath != operator has a very unintuitive behavior whenever at least one of its arguments is a node-set:

    From the W3C XPath 1.0 Recommendation:

    “If one object to be compared is a node-set and the other is a number,
    then the comparison will be true if and only if there is a node in the
    node-set such that the result of performing the comparison on the
    number to be compared and on the result of converting the string-value
    of that node to a number using the number function is true. If one
    object to be compared is a node-set and the other is a string, then
    the comparison will be true if and only if there is a node in the
    node-set such that the result of performing the comparison on the
    string-value of the node and the other string is true”

    In this particular case for the element:

    <b text="2">data</b>
    

    The comparison:

    @text != ../a/@text
    

    is true() even though there exists:

    <a text="2"/> 
    

    because there exist at least one ../a element (and actually more than one), the string (or numeric) value of whose text attribute isn’t equal to "2".

    This is a well-known fact and a FAQ: Always avoid using the != operator unless you absolutely know what you are doing!

    The correct solution of this problem is to use the not() function like this:

    not(@text = ../a/@text)
    

    This expression evaluates to true() only if @text = ../a/@text is false() — that is only if there isn’t even a single ../a/@text whose string value is equal to the string value of the text attribute of the context node.

    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:template match="/">
      <xsl:copy-of select="/tt/b[not(@text = ../a/@text)]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document (above), the correct result is produced:

    <b text="14">data</b>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML/XML document similar to the following. There can be one or
I have an XML document with a section similar to the following: <release_list> <release>
I have a XML Document (LessonData.xml) with lesson data in it, with the following
I have an XML document (an InfoPath form) that looks similar to this: <my:ClientMaintenance
I have a Stored Procedure that takes an XML document as a parameter similar
I have xml that looks somewhat similar to the following. I need to get
I have an Xml document that looks similar too <Reports xmlns=> <Report> <ReportID>1</ReportID> <ParameterTemplate
I have an xml document that contains some Item elements with ids. I want
I have an XML document that I generate from an Entity Framework object. The
I have a XML document with my data in it, multiple entries for 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.