XPath selecting elements afer one having a given text

  • Thread starter =?ISO-8859-1?Q?Une_B=E9vue?=
  • Start date
?

=?ISO-8859-1?Q?Une_B=E9vue?=

my xml fragment :

<select id='aId'>
<option>option 1</option>
<option>option 2</option>
[...]
<option>---?---</option>
<option>option n + 1</option>
<option>option n + 2</option>
[...]
</select>

and i want to set the class attribute of all the options to :

add if text() = '---?---' (the easiest case allready done) ;
odd if the position() of option is odd and the element is before the one
having text() = '---?---'
even if the position() is even and before '---?---'
odd_edited if position is odd and the element is after '---?---'
even_edited if position is even and after '---?---'


i did the easiest case like that :

add for xhtml://select[@id = 'aId']/xhtml:eek:ption[text() = '---?---']

i'm also able to choose odd/even position :

xhtml://select[@id = 'aId']/xhtml:eek:ption[not(text() = '---?---') and
((position mod 2) = 0)]

i knwo that to choose the elements before the element '---?---' i have
to do something like :

following-sibling::xhtml:eek:ption[text() = '---?---']

for the elements before '---?---' and preceeding-sibling for the
elements after.

BUT what i don't know exactly is how to add this rule to the firsts
above ???
 
?

=?ISO-8859-1?Q?Une_B=E9vue?=

Une Bévue said:
i knwo that to choose the elements before the element '---?---' i have
to do something like :

following-sibling::xhtml:eek:ption[text() = '---?---']

for the elements before '---?---' and preceeding-sibling for the
elements after.

BUT what i don't know exactly is how to add this rule to the firsts
above ???


this is as simple as :

....xhtml:eek:ption[not(text() = '--?--']) and ((position() mod 2) = 0) and
not(preceding::xhtml:eek:ption[text() = '--?--'])]

for those before '--?--' and even position
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top