Home > front end >  Xpath Position() function
Xpath Position() function

Time:02-19

I want to match specific elements by their position. This is the code

<div >
  <p><strong>*** Due to the large need for nurses during the coronavirus outbreak, many of the nursing jobs listed below have flexible start dates and assignment lengths. Even if you are unable to start on the designated Start Date, please apply and discuss your availability with a Fastaff recruiter. ***</strong></p>
  <p>The Estimated Weekly Total is based on working the listed number hours per week and includes available stipend amounts; eligibility may vary subject to company policy and applicable law. Please contact a recruiter for full details.</p>
  <h2>Medical Surgical / Telemetry Travel Registered Nurse Job</h2>
  <p>We are seeking an experienced and self-motivated medical surgical / telemetry travel registered nurse to join our growing team of registered nursing professionals.</p>
  <h3>Medical Surgical / Telemetry RN Qualifications:</h3>
  <ul>
    <li>Active RN license in specified state</li>
    <li>RN degree from an accredited registered nurse program</li>
    <li>BLS and ACLS required</li>
    <li>One year of recent experience as an RN in a medical surgical / telemetry environment and two years of RN experience</li>
  </ul>
  <h3>Medical Surgical / Telemetry Registered Nurse Duties &amp; Responsibilities:</h3>
  <ul>
    <li>Manage the care of adult patients experiencing cardiac problems requiring moderately complex assessment, therapies and interventions</li>
    <li>Communicate and educate patients and families</li>
    <li>Assess and coordinate patients’ discharge planning needs with members of the healthcare team</li>
    <li>May require interpretation of cardiac rhythm strips and provision of appropriate nursing treatment</li>
  </ul>
  <h3>Benefits of Being a Fastaff® Travel Nursing Employee</h3>
  <ul>
    <li>Premium pay</li>
    <li>Prestigious facilities</li>
    <li>Flexible scheduling</li>
    <li>Immediate access to the industry’s best RN recruiters and healthcare facilities</li>
    <li>Fastaff will provide costs for housing during the length of your assignment, as well as airfare or mileage to and from the city of the assignment at the start and end of the assignment.</li>
    <li>Group health insurance benefits</li>
    <li>$10,000 Company-paid Life/ADD Insurance</li>
    <li>Matching 401(k)</li>
  </ul>
  <h3>About Fastaff® Travel Nursing:</h3>
  <p>More than two decades ago, Fastaff pioneered the practice of Rapid Response<strong>®</strong>&nbsp;travel nurse staffing. Since then, the company has grown to become the leading provider of urgent and crucial temporary registered nurses to help hospitals
    provide continuous, high-quality patient care, while offering premium pay to registered nurses. In partnering with many of the nation’s largest and most prestigious healthcare facilities as well as small community hospitals, Fastaff provides enriching
    employment opportunities to RNs while also providing the highest pay in the industry to meet acute staffing needs and provide unparalleled patient care.</p>
  <p><em>Fastaff Travel Nursing is an equal employment opportunity employer. Fastaff’s policy is not to unlawfully discriminate against any applicant or employee on the basis of race, color, sex, religion, national origin, age, military status, disability, genetic information or any other consideration made unlawful by applicable federal, state, or local laws. Fastaff also prohibits harassment of applicants and employees based on any of these protected categories. It is also Fastaff’s policy to comply with all applicable state and federal laws respecting consideration of unemployment status in making hiring decisions.</em></p>
</div>

I want to select elements that are less then or equal to 8 something like this //div [contains (@class, "field-content")]//following-sibling::*[position() <=8] but it gives me the same result as this //div [contains (@class, "field-content")]//following-sibling::*[position() >=8] expression is giving.

<div >
  <p><strong>*** Due to the large need for nurses during the coronavirus outbreak, many of the nursing jobs listed below have flexible start dates and assignment lengths. Even if you are unable to start on the designated Start Date, please apply and discuss your availability with a Fastaff recruiter. ***</strong></p>
  <p>The Estimated Weekly Total is based on working the listed number hours per week and includes available stipend amounts; eligibility may vary subject to company policy and applicable law. Please contact a recruiter for full details.</p>
  <h2>Medical Surgical / Telemetry Travel Registered Nurse Job</h2>
  <p>We are seeking an experienced and self-motivated medical surgical / telemetry travel registered nurse to join our growing team of registered nursing professionals.</p>
  <h3>Medical Surgical / Telemetry RN Qualifications:</h3>
  <ul>
    <li>Active RN license in specified state</li>
    <li>RN degree from an accredited registered nurse program</li>
    <li>BLS and ACLS required</li>
    <li>One year of recent experience as an RN in a medical surgical / telemetry environment and two years of RN experience</li>
  </ul>
  <h3>Medical Surgical / Telemetry Registered Nurse Duties &amp; Responsibilities:</h3>
  <ul>
    <li>Manage the care of adult patients experiencing cardiac problems requiring moderately complex assessment, therapies and interventions</li>
    <li>Communicate and educate patients and families</li>
    <li>Assess and coordinate patients’ discharge planning needs with members of the healthcare team</li>
    <li>May require interpretation of cardiac rhythm strips and provision of appropriate nursing treatment</li>

These are the elements in HTML that I want to select but the expression doesn't match with them. I am writing XPath expression in Chrome Devtools

CodePudding user response:

You're using following-siblings when the nodes you want are children.

Instead select all children of certain position:

//div[contains (@class, "field-content")]/*[position() >= 8]

this select any direct child of this div node that are of position >=8.

For more see this interactive xpath tester

  • Related