By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

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

P: n/a
//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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.