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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:04+00:00 2026-05-26T15:14:04+00:00

I looked at some other articles here and elsewhere but nothing was exactly what

  • 0

I looked at some other articles here and elsewhere but nothing was exactly what I’m trying to implement.

Please take a look at this xpath query (using mozxpath.js file to clone IE functionality)

var XMLObj.selectSingleNode("/Catalog/Albums/Album/Tracks/Track[../../AlbumNo='" + AlbumNo + "' and ./TrackNo = '" + TrackNo + "']");

How can I convert this expression to jquery?

I tried the following to get me started and it only selects the AlbumNo node:

$(XMLObj).find("AlbumNo:contains(" + AlbumNo + ")", "TrackNo:contains(" + TrackNo + ")");

The xpath expression is looking for the Track node where both conditions are met. How can I rewrite the xpath expression to something jQuery friendly?

Thank you.

Edit

Here is the dumbed-down version of the XML structure:

<Catalog>
  <Albums>
    <Album>
      <AlbumNo>1</AlbumNo>
      <Tracks>
        <Track>
          <TrackNo>1</TrackNo>
        <Track>
          <TrackNo>2</TrackNo>
        <Track>
          <TrackNo>3</TrackNo>
        <Track>
          <TrackNo>4</TrackNo>
        <Track>
          <TrackNo>5</TrackNo>
        <Track>
          <TrackNo>6</TrackNo>
        <Track>
          <TrackNo>7</TrackNo>
        <Track>
          <TrackNo>8</TrackNo>
        <Track>
          <TrackNo>9</TrackNo>
        <Track>
          <TrackNo>10</TrackNo>
        <Track>
          <TrackNo>11</TrackNo>
        <Track>
          <TrackNo>12</TrackNo>
      </Tracks>
    </Album>
  </Album>
</Catalog>
  • 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-26T15:14:04+00:00Added an answer on May 26, 2026 at 3:14 pm

    An example of the XML structure would be helpful.

    I don’t think you can achieve the same with a single selector, you have to use a more complex structure:

    $(XMLObj).find('Album').filter(function() { // filter albums by album number
        return !!$(this).find('AlbumNo').filter(function() { 
            return $(this).text() == AlbumNo;
        }).length;
    }).find('Track').filter(function() { // filter tracks by track number
        return !!$(this).find('TrackNo').filter(function() { 
            return $(this).text() == TrackNo;
        }).length;
    });
    

    It would definitely be easier if the numbers were attributes of the elements and not descendants.

    The reason why I use another filter function instead of :contains is that it is the only way you can search for an exact match. :contains will also match if the text you search is only a substring. That is, if you search for track number 1, :contains would also match track number 10, 11, 12, etc.


    If you have to do similar things quite often, it might be useful to extend jQuery with a function which filters elements with certain subelements with certain content.

    For example:

    (function($) {
        $.fn.whichContains = function(element, content) {
            return this.filter(function() {
                return !!$(this).find(element).filter(function() { 
                    return $(this).text() == content;
                }).length;
            });
        };
    }(jQuery));
    

    which can be used as

    $(XMLObj)
      .find('Album').whichContains('AlbumNo', AlbumNo)
      .find('Track').whichContains('TrackNo', TrackNo)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked at some other answers and lots of articles but this simple part
I've looked at several other suggestions on this issue but for some reason my
Ok I'm stuck, I've looked at some other questions on here but no help,
I've looked for some other articles on this problem and even tried some of
I have looked at this page for some time now. Amazing, really. But I
Looked at some other similar answers on stack overflow, but no relevant answer was
So I have seen other articles here on stack about this and a lot
When I looked into Java EE6 doc and some other articles, Java EE6 is
I've looked into some questions here where the best programming books are listed and
I've looked for some help on the reddit site itself, but I still can't

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.