"//form[...]//input | //form[...]//select" or can I combine them?

Discussion in 'XML' started by yawnmoth, Aug 18, 2008.

  1. yawnmoth

    yawnmoth Guest

    //form[@name='$id' or @id='$id']//input
    //form[@name='$id' or @id='$id']//select//option

    I can combine those with an or (|), but to make my code more concise,
    would it be possible to reuse the //form[@name='$id' or @id='$id']
    bit? Could I maybe do something like this, instead?:

    //form[@name='$id' or @id='$id']//(input or select//option)

    That doesn't work, but is there something similar that would? Or am I
    going to have to duplicate the //form[...] part for each one?

    Thanks!
    yawnmoth, Aug 18, 2008
    #1
    1. Advertising

  2. yawnmoth

    yawnmoth Guest

    On Aug 18, 12:48 pm, yawnmoth <> wrote:
    > //form[@name='$id' or @id='$id']//input
    > //form[@name='$id' or @id='$id']//select//option
    >
    > I can combine those with an or (|), but to make my code more concise,
    > would it be possible to reuse the //form[@name='$id' or @id='$id']
    > bit?  Could I maybe do something like this, instead?:
    >
    > //form[@name='$id' or @id='$id']//(input or select//option)
    >
    > That doesn't work, but is there something similar that would?  Or am I
    > going to have to duplicate the //form[...] part for each one?
    >
    > Thanks!


    "//form//*[name()='input' or name()='textarea']" work, but "//form//
    *[name()='input' or name()='select//option']" doesn't...
    yawnmoth, Aug 18, 2008
    #2
    1. Advertising

  3. yawnmoth

    Peter Flynn Guest

    yawnmoth wrote:
    > On Aug 18, 12:48 pm, yawnmoth <> wrote:
    >> //form[@name='$id' or @id='$id']//input
    >> //form[@name='$id' or @id='$id']//select//option


    I think that should probably be @name=$id unless you really are testing
    for the literal string "$id".

    >> I can combine those with an or (|), but to make my code more concise,
    >> would it be possible to reuse the //form[@name='$id' or @id='$id']
    >> bit? Could I maybe do something like this, instead?:
    >>
    >> //form[@name='$id' or @id='$id']//(input or select//option)


    It would be useful if XPath had that ability.

    >> That doesn't work, but is there something similar that would? Or am I
    >> going to have to duplicate the //form[...] part for each one?


    I think //form[@name=$id or @id=$id]//input | /form[@name=$id or
    @id=$id]//select/option will work/

    > "//form//*[name()='input' or name()='textarea']" work, but "//form//
    > *[name()='input' or name()='select//option']" doesn't...


    name() is unimodal: it returns just the name of a single node, not the
    path to it.

    In XHTML, the option element type can only occur as the child of select
    or optgroup, so unless you really want to rule out optgroups, just using
    option on its own may be enough.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/


    ///Peter
    Peter Flynn, Aug 18, 2008
    #3
    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. pjbates
    Replies:
    1
    Views:
    4,530
    Dan Vogt
    May 2, 2006
  2. Replies:
    5
    Views:
    506
    David Carlisle
    Mar 23, 2005
  3. Anonieko

    HttpHandlers - Learn Them. Use Them.

    Anonieko, Jun 15, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    516
    tdavisjr
    Jun 16, 2006
  4. Martin Gregorie

    Can I combine GUI & Applet?

    Martin Gregorie, Nov 30, 2006, in forum: Java
    Replies:
    6
    Views:
    412
    Martin Gregorie
    Dec 2, 2006
  5. why the lucky stiff
    Replies:
    5
    Views:
    144
    why the lucky stiff
    Sep 22, 2004
Loading...

Share This Page