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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

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

    //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

    #2
    Re: "//form[...]//input | //form[...]//select" or can I combine them?

    On Aug 18, 12:48 pm, yawnmoth <terra1...@yaho o.comwrote:
    //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()='textare a']" work, but "//form//
    *[name()='input' or name()='select//option']" doesn't...

    Comment

    • Peter Flynn

      #3
      Re: &quot;//form[...]//input | //form[...]//select&quot; or can I combine them?

      yawnmoth wrote:
      On Aug 18, 12:48 pm, yawnmoth <terra1...@yaho o.comwrote:
      >//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()='textare a']" 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

      Comment

      • Martin Honnen

        #4
        Re: &quot;//form[...]//input | //form[...]//select&quot; or can I combine them?

        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?
        With XPath 2.0 you can use
        //form[@name='$id' or @id='$id']//(input | select//option)


        --

        Martin Honnen

        Comment

        Working...