Clarify axes
This commit is contained in:
parent
c71d3f9d1a
commit
9565d413aa
33
xpath.md
33
xpath.md
|
@ -254,27 +254,14 @@ Steps of an expression are separated by `/`, usually used to pick child nodes. T
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
//ul/li # $('ul > li')
|
//ul/li # $('ul > li')
|
||||||
|
//ul/child::li # $('ul > li') - same
|
||||||
|
//ul/descendant-or-self::li # $('ul li')
|
||||||
//ul/ancestor-or-self::li # $('ul').closest('li')
|
//ul/ancestor-or-self::li # $('ul').closest('li')
|
||||||
```
|
```
|
||||||
{:.light}
|
{:.light}
|
||||||
|
|
||||||
### Descendant-or-self axis
|
|
||||||
When you use `//` for descendants, this is short for the `descendant-or-self::` axis.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# both the same
|
|
||||||
//div//h4
|
|
||||||
//div/descendant-or-self::h4
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# both the same
|
|
||||||
//ul//[last()]
|
|
||||||
//ul/descendant-or-self::[last()]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Child axis
|
### Child axis
|
||||||
When axis is not specified, a `name` is short for `child::name`. This is what makes `//a/b/c` work.
|
When axis is not specified, a `name` is short for `child::name`. This makes `//a/b/c` work.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# both the same
|
# both the same
|
||||||
|
@ -295,17 +282,19 @@ When axis is not specified, a `name` is short for `child::name`. This is what ma
|
||||||
//ul[count(child::li) > 2]
|
//ul[count(child::li) > 2]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Attribute axis
|
### Descendant-or-self axis
|
||||||
When you use `@` for attributes, that's short for the `attribute::` axis.
|
When you use `//` for descendants, this is short for the `descendant-or-self::` axis.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# both the same
|
# both the same
|
||||||
//a/@href
|
//div//h4
|
||||||
//a/attribute::href
|
//div/descendant-or-self::h4
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
# both the same
|
# both the same
|
||||||
//div[@id="box"]
|
//ul//[last()]
|
||||||
//div[attribute::id="box"]
|
//ul/descendant-or-self::[last()]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Other axes
|
### Other axes
|
||||||
|
|
Loading…
Reference in New Issue