Basic Selectors
Select All Nodes
Select by Node Type
Path Expressions
Absolute vs Descendant Paths
| Selector | Description |
|---|---|
//paragraph | All paragraphs anywhere in document |
/document/paragraph | Direct child paragraphs of root |
//section/paragraph | Paragraphs that are direct children of any section |
//section//paragraph | Paragraphs anywhere under any section |
Content Filtering
Contains Function
Starts-With and Ends-With
Tag Filtering
Select Tagged Nodes
Get Tagged Node Details
Position Filtering
Index-Based Selection
Variables in Selectors
Parameterized Queries
Common Selector Patterns
Quick Reference
| Pattern | Selector | Description |
|---|---|---|
| All nodes | //* | Every node in document |
| By type | //paragraph | All paragraphs |
| Direct children | //section/paragraph | Paragraphs under sections |
| Any depth | //section//paragraph | Paragraphs anywhere in sections |
| First of type | //paragraph[1] | First paragraph |
| By tag | //*[@tag='important'] | Tagged nodes |
| By content | //paragraph[contains(@content, 'text')] | Content search |
| Multiple conditions | //paragraph[@tag='x'][contains(@content, 'y')] | Combined filters |
Real-World Examples
Working with Results
Iterating Results
Chaining Selections
Performance Tips
For large documents, optimize your selectors:
- Be specific with paths (
//table/row/cellvs//*) - Use
select_first()when you only need one result - Combine conditions in one selector vs multiple queries
- Cache selector results when iterating multiple times
