467,178 Members | 1,304 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,178 developers. It's quick & easy.

"//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!
Aug 18 '08 #1
  • viewed: 3744
Share:
3 Replies
On Aug 18, 12:48*pm, yawnmoth <terra1...@yahoo.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()='textarea']" work, but "//form//
*[name()='input' or name()='select//option']" doesn't...
Aug 18 '08 #2
yawnmoth wrote:
On Aug 18, 12:48 pm, yawnmoth <terra1...@yahoo.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()='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
Aug 18 '08 #3
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
http://JavaScript.FAQTs.com/
Aug 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by ian justice | last post: by
3 posts views Thread by Bush is a Fascist | last post: by
13 posts views Thread by dhughey@gmail.com | last post: by
3 posts views Thread by aljosa.mohorovic@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.