@@ -1373,15 +1373,36 @@ <h3 id=structure><span class=secno>3.1. </span> Structure and Terminology</h3>
13731373 < h3 id =evaluating-selectors > < span class =secno > 3.2. </ span > Evaluating a
13741374 Selector</ h3 >
13751375
1376+ < p > This section describes how to < dfn data-export =data-export
1377+ id =evaluate-a-selector > evaluate a selector</ dfn > against a set of
1378+ elements.
1379+
13761380 < p > A < a href ="#selector "> < i > selector</ i > </ a > is evaluated against some
13771381 initial list of elements, as determined by the context that the selector
13781382 is evaluated in: the < dfn data-export =data-export
1379- id =selector-match-list > selector match list</ dfn > . The selector is
1380- processed from left to right in order, with < a href ="#simple "> < i > simple
1383+ id =selector-match-list > selector match list</ dfn > . If the selector is < a
1384+ href ="#scope-contained "> < i > scope-contained</ i > </ a > , the < a
1385+ href ="#selector-match-list "> < i > selector match list</ i > </ a > is immediately
1386+ filtered to contain only elements that are either the < a
1387+ href ="#scoping-root "> < i > scoping root</ i > </ a > or descendants of the < a
1388+ href ="#scoping-root "> < i > scoping root</ i > </ a > . The selector is processed
1389+ from left to right in order, with < a href ="#simple "> < i > simple
13811390 selectors</ i > </ a > filtering the < i > selector match set</ i > , and < a
13821391 href ="#combinator0 "> < i > combinators</ i > </ a > changing the < i > selector match
1383- set</ i > into something new. When this process is done, the elements in the
1384- < i > selector match set</ i > are the elements said to match the selector.
1392+ set</ i > into something new. If the selector is < a
1393+ href ="#scope-contained "> < i > scope-contained</ i > </ a > then after each < a
1394+ href ="#combinator0 "> < i > combinator</ i > </ a > the < a
1395+ href ="#selector-match-list "> < i > selector match list</ i > </ a > must be
1396+ filtered to contain only elements that are either the < a
1397+ href ="#scoping-root "> < i > scoping root</ i > </ a > or descendants of the < a
1398+ href ="#scoping-root "> < i > scoping root</ i > </ a > . If the selector is < a
1399+ href ="#scope-filtered "> < i > scope-filtered</ i > </ a > , then after the selector
1400+ is finished processing, the < a href ="#selector-match-list "> < i > selector
1401+ match list</ i > </ a > must be filtered to contain only elements that are
1402+ either the < a href ="#scoping-root "> < i > scoping root</ i > </ a > or descendants
1403+ of the < a href ="#scoping-root "> < i > scoping root</ i > </ a > . When this process
1404+ is done, the elements in the < i > selector match set</ i > are the elements
1405+ said to match the selector.
13851406
13861407 < p > For example, to evaluate the selector "div > i.name" against a document,
13871408 the < a href ="#selector-match-list "> < i > selector match list</ i > </ a > is first
@@ -4383,48 +4404,25 @@ <h3 id=parse-a-relative-selector><span class=secno>17.2. </span> Parse A
43834404 < h3 id =match-a-selector > < span class =secno > 17.3. </ span > Match A Selector</ h3 >
43844405
43854406 < p > This section describes how to < dfn id =match-a-selector0 > match a
4386- selector</ dfn > < var title =""> selector</ var > against a tree of nodes
4407+ selector</ dfn > < var title =""> selector</ var > . Optionally, a tree of nodes
4408+ < var > nodes</ var > to be matched against may be provided; if not, the
4409+ default < a href ="#initial-selector-match-list "> < i > initial selector match
4410+ list</ i > </ a > for selectors in the given context is used as
43874411 < var > nodes</ var > . Optionally, a < a href ="#scoping-root "> < i > scoping
4388- root</ i > </ a > and scoping method (< a
4412+ root</ i > </ a > and < a href =" # scoping-methods " > < i > scoping method</ i > </ a > (< a
43894413 href ="#scope-contained "> < i > scope-contained</ i > </ a > or < a
43904414 href ="#scope-filtered "> < i > scope-filtered</ i > </ a > ) may be provided.
43914415 Optionally, an explicit < a href ="#reference-element-set "> < i > reference
43924416 element set</ i > </ a > < var > element set</ var > (which may be empty) may be
43934417 provided. It returns a list of zero or more elements.
43944418
4395- < p > If an explicit < a href ="#reference-element-set "> < i > reference element
4396- set</ i > </ a > is given, this algorithm may be called without specifying a
4397- tree of nodes. (The tree will be inferred from each element in the set;
4398- this makes it easier to invoke the algorithm for a relative selector.)
4399-
4400- < ol >
4401- < li > If no explicit < a href ="#reference-element-set "> < i > reference element
4402- set</ i > </ a > was given, return the result of matching < var
4403- title =""> selector</ var > against < var > nodes</ var > , with the < a
4404- href ="#scoping-root "> < i > scoping root</ i > </ a > and scoping method if they
4405- were provided.
4406-
4407- < li > Otherwise, let < var > result</ var > initially be the empty list.
4408-
4409- < li > For each element < var > reference element</ var > in < var > element
4410- set</ var > :
4411- < ol >
4412- < li > If < var > nodes</ var > was not given, let < var > nodes</ var > be all the
4413- nodes in the same tree as < var > reference element</ var > .
4414-
4415- < li > Let < var > single result</ var > be the result of matching < var
4416- title =""> selector</ var > against < var > nodes</ var > , with the < a
4417- href ="#scoping-root "> < i > scoping root</ i > </ a > and scoping method if they
4418- were provided, and < var > reference element</ var > as the < a
4419- href ="#reference-element-set "> < i > reference element set</ i > </ a > .
4420-
4421- < li > Append each element in < var > single result</ var > to
4422- < var > result</ var > , unless the element is already present in
4423- < var > result</ var > .
4424- </ ol >
4425-
4426- < li > Return < var > result</ var > .
4427- </ ol >
4419+ < p > < a href ="#evaluate-a-selector "> < i > Evaluate a selector</ i > </ a > < var
4420+ title =""> selector</ var > against < var > nodes</ var > with the < a
4421+ href ="#scoping-root "> < i > scoping root</ i > </ a > , < a
4422+ href ="#scoping-methods "> < i > scoping method</ i > </ a > , and < a
4423+ href ="#reference-element-set "> < i > reference element set</ i > </ a > if they
4424+ were provided, and return the elements that match the selector. Return the
4425+ nodes matched by the selector.
44284426
44294427 < h2 id =changes > < span class =secno > 18. </ span > Changes</ h2 >
44304428
0 commit comments