XPath selecting elements afer one having a given text

Discussion in 'XML' started by =?ISO-8859-1?Q?Une_B=E9vue?=, Feb 22, 2007.

  1. 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 ???
    --
    Une Bévue
     
    =?ISO-8859-1?Q?Une_B=E9vue?=, Feb 22, 2007
    #1
    1. Advertising

  2. FOUND was (Re: XPath selecting elements afer one having a given text)

    Une Bévue <> wrote:

    > 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
    --
    Une Bévue
     
    =?ISO-8859-1?Q?Une_B=E9vue?=, Feb 22, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alastair Cameron
    Replies:
    1
    Views:
    7,414
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Thomas Schmidt
    Replies:
    7
    Views:
    1,128
    Thomas Schmidt
    Jul 19, 2007
  3. Jeff
    Replies:
    1
    Views:
    2,653
  4. Mario
    Replies:
    0
    Views:
    363
    Mario
    Mar 2, 2009
  5. Phil Grimpo

    Session Variables Cleared afer Server.Execute

    Phil Grimpo, Jan 27, 2005, in forum: ASP General
    Replies:
    5
    Views:
    517
    Phil Grimpo
    Jan 28, 2005
Loading...

Share This Page