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

Y

yawnmoth

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

yawnmoth

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

Peter Flynn

yawnmoth said:
//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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top