-
-
Notifications
You must be signed in to change notification settings - Fork 11
Prefixes and advanced usage
Greg Bowler edited this page Mar 4, 2026
·
2 revisions
By default each translated selector starts with .//. We can customise this by passing prefix.
echo new Translator("h1, p", prefix: "descendant-or-self::");
// descendant-or-self::h1 | descendant-or-self::pThis is useful when integrating into existing XPath strategies.
Both of these are equivalent:
$xpathA = (string)new Translator(".content");
$xpathB = (new Translator(".content"))->asXPath();Use whichever reads better in your codebase.
Complex selectors can stack class, id, attribute, and pseudo predicates together.
main article .content[data-categories~=test]:nth-child(2)Here we can keep selectors readable while still producing a precise XPath query.
This repository is intentionally lightweight and dependency-free. It focuses on a practical subset of CSS selectors commonly used for DOM traversal and querySelector-style APIs.
Return to Home.
PHP.GT/CssXPath is a separately maintained component of PHP.Gt/WebEngine.