Improve xpath
This commit is contained in:
parent
657ff90fd1
commit
5badb60ca2
48
xpath.md
48
xpath.md
|
@ -127,21 +127,6 @@ You can use nodes inside predicates.
|
|||
//ul[li]
|
||||
```
|
||||
|
||||
### Nesting predicates
|
||||
This returns `<section>` if it has an `<h1>` descendant with `id='hi'`.
|
||||
|
||||
```
|
||||
//section[//h1[@id='hi']]
|
||||
```
|
||||
|
||||
### Predicate order
|
||||
Order is significant, these two are different.
|
||||
|
||||
```sh
|
||||
a[1][@href='/']
|
||||
a[@href='/'][1]
|
||||
```
|
||||
|
||||
### Indexing
|
||||
Use `[]` with a number, or `last()` or `position()`.
|
||||
|
||||
|
@ -152,25 +137,47 @@ Use `[]` with a number, or `last()` or `position()`.
|
|||
//ol/li[position()=2] # ...same as above
|
||||
```
|
||||
|
||||
### Predicate order
|
||||
Order is significant, these two are different.
|
||||
|
||||
```sh
|
||||
a[1][@href='/']
|
||||
a[@href='/'][1]
|
||||
```
|
||||
|
||||
### Nesting predicates
|
||||
This returns `<section>` if it has an `<h1>` descendant with `id='hi'`.
|
||||
|
||||
```
|
||||
//section[//h1[@id='hi']]
|
||||
```
|
||||
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
### Node functions
|
||||
|
||||
text() # button[text()="Submit"]
|
||||
name() # *[name()='div']
|
||||
```sh
|
||||
name() # //[starts-with(name(), 'h')]
|
||||
text() # //button[text()="Submit"]
|
||||
# //button/text()
|
||||
lang(str)
|
||||
namespace-uri()
|
||||
|
||||
count() # table[count(tr)=1]
|
||||
position() # ol/li[position()=2]
|
||||
count() # //table[count(tr)=1]
|
||||
position() # //ol/li[position()=2]
|
||||
```
|
||||
|
||||
### Boolean functions
|
||||
|
||||
```sh
|
||||
not(expr) # button[not(text()="Submit")]
|
||||
```
|
||||
|
||||
### String functions
|
||||
|
||||
```sh
|
||||
contains() # font[contains(@class,"head")]
|
||||
starts-with() # font[starts-with(@class,"head")]
|
||||
ends-with() # font[ends-with(@class,"head")]
|
||||
|
@ -182,12 +189,15 @@ Functions
|
|||
translate()
|
||||
normalize-space()
|
||||
string-length()
|
||||
```
|
||||
|
||||
### Type conversion
|
||||
|
||||
```sh
|
||||
string()
|
||||
number()
|
||||
boolean()
|
||||
```
|
||||
|
||||
Axes
|
||||
----
|
||||
|
|
Loading…
Reference in New Issue