XPath by style?

P

Phil

<div width="123"></div>
<div style="foo: doo; width: 123px; bar: gar;"></div>
<div width="124"></div>
<div style="foo: doo; width: 124px; bar: gar;"></div>

I know how to construct an XPath expression that'll select the first
<div>, but is there one that'll select the first two but not the others?
 
D

David Mark

<div width="123"></div>
<div style="foo: doo; width: 123px; bar: gar;"></div>
<div width="124"></div>
<div style="foo: doo; width: 124px; bar: gar;"></div>

I know how to construct an XPath expression that'll select the first
<div>, but is there one that'll select the first two but not the others?

Yes. I mailed you an example.
 
M

Martin Honnen

Phil said:
<div width="123"></div>
<div style="foo: doo; width: 123px; bar: gar;"></div>
<div width="124"></div>
<div style="foo: doo; width: 124px; bar: gar;"></div>

I know how to construct an XPath expression that'll select the first
<div>, but is there one that'll select the first two but not the others?

Use a predicate to select the first and second element by position e.g.
div[position() < 3]
 
P

Phil

Martin said:
Use a predicate to select the first and second element by position e.g.
div[position() < 3]

Sorry if I wasn't clear - the elements aren't necessarily in that order.
What I need to do is select all elements with a width of 123px,
regardless of whether the width is specified as a style or an attribute.
 
D

David Mark

Martin said:
Use a predicate to select the first and second element by position e.g.
  div[position() < 3]

Sorry if I wasn't clear - the elements aren't necessarily in that order.
  What I need to do is select all elements with a width of 123px,
regardless of whether the width is specified as a style or an attribute.

Ah, I see. Check your inbox.
 
T

Thomas 'PointedEars' Lahn

Phil said:
Martin said:
Use a predicate to select the first and second element by position e.g.
div[position() < 3]

Sorry if I wasn't clear - the elements aren't necessarily in that order.
What I need to do is select all elements with a width of 123px,
regardless of whether the width is specified as a style or an attribute.

XPath is off-topic here (as it is *not* a JS-dependent technology), and your
From header constitutes a violation of Internet standards and disregard of
Netiquette. RTFM.


PointedEars
 
M

Martin Honnen

Phil said:
What I need to do is select all elements with a width of 123px,
regardless of whether the width is specified as a style or an attribute.

XPath (at least version 1.0) has only basic string manipulation
functions so parsing the CSS properties in the inline style attribute is
rather difficult. I think in that case it is better not to use XPath to
try to check the CSS width but rather use element.style.width (or even
window.getComputedStyle depending on what kind of CSS value you are
looking for).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,123
Messages
2,570,740
Members
47,295
Latest member
riya007

Latest Threads

Top