Skip to content

/descendant::span[1] should not be equivalent to //span[1] #93

@yayuyokitano

Description

@yayuyokitano

Note: I have experienced this issue using htmlquery, but it seems to not be fixed here either, so I am raising issue here.

By xpath spec, /descendant::span[1] and //span[1] are not the same.

/descendant::span[1] should get the first span descendant matched within the current ancestor, while //span[1] should get the first span descendant matched within the parent of each respective span element. This package seems to currently be treating both like //span[1]

Example:

<div id="wrapper">
  <span>span one</span>
  <div>
    <span>span two</span>
  </div>
</div>

In this case, //div[@id='wrapper']//span[1] should be matching both span one and span two, because both are the first child of their respective parents. However, //div[@id='wrapper']/descendant::span[1] should only match span one, as it goes by the position within div[@id='wrapper'], not position within direct parent.

See xpath spec 2.5

NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions