This traverses a DOMDocument and attempts to find
matches to the provided selector.
\b How this works
This performs a bottom-up search. On the first pass,
it attempts to find all of the matching elements for the
last simple selector in a selector.
Subsequent passes attempt to eliminate matches from the
initial matching set.
Example:
Say we begin with the selector foo.bar baz. This is processed
as follows:
- First, find all baz elements.
- Next, for any baz element that does not have foo as an ancestor,
eliminate it from the matches.
- Finally, for those that have foo as an ancestor, does that foo
also have a class baz? If not, it is removed from the matches.
\b Extrapolation
Partial simple selectors are almost always expanded to include an
element.
Examples:
- :first is expanded to *:first
- .bar is expanded to *.bar.
- .outer .inner is expanded to *.outer *.inner
The exception is that IDs are sometimes not expanded, e.g.:
- #myElement does not get expanded
- #myElement .class \i may be expanded to *#myElement *.class
(which will obviously not perform well).