Matching attributes between elements

D

Dylan Nicholson

Hi,

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element, whereby the label's "for" attribute value must match
the input's "id" attribute value. i.e.: something like

//input[//label[@for=???@id]]

whereby the ??? specifies the input element's attribute axis.

Currently I'm doing it with a custom function, which is fine, but it
seems like it should possible without it.

Thanks

Dylan
 
A

Ayush

[Dylan Nicholson] wrote-:
Hi,

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element

Try:
//input[//label/@for=@id or ancestor::label]



Good Luck,
Ayush.
 
D

Dylan Nicholson

[Dylan Nicholson] wrote-:
Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element

Try:
//input[//label/@for=@id or ancestor::label]
Nope, that only detects label elements that have a "for" and an "id"
attribute with the same value.

The only notation I've seen that's supposed to work is:

//input[let $id:=@id return count(//label/@for=$id) > 0]

but .NET's XSLT implementation doesn't support this.
 
R

Richard Tobin

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element
Try:
//input[//label/@for=@id or ancestor::label]
[/QUOTE]
Nope, that only detects label elements that have a "for" and an "id"
attribute with the same value.

No it doesn't. Ignoring the ancestor::label bit, it returns <input>
elements whose id attribute is equal to some <label> element's for
attribute. Both //label/@for and @id are evaluated with the <input>
element as the context node.

There are cases that have the difficulty you refer to, but this isn't
one of them.

-- Richard
 
R

Richard Tobin

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element, whereby the label's "for" attribute value must match
the input's "id" attribute value. i.e.: something like

//input[//label[@for=???@id]]
[/QUOTE]
//input[//label[@for=current()/@id]] may work, depending on your context
node.

You don't need this, because you can test //label/@for against @id
directly rather than having a nested predicate.

-- Richard
 
P

Peter Flynn

Dylan said:
Hi,

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element, whereby the label's "for" attribute value must match
the input's "id" attribute value. i.e.: something like

//input[//label[@for=???@id]]

whereby the ??? specifies the input element's attribute axis.

//input[//label[@for=current()/@id]] may work, depending on your context
node.

///Peter
 
D

Dylan Nicholson

Just wondering if anyone knew if it was possible to select <input>
elements in an XHTML document for which there exists a corresponding
<label> element
Try:
//input[//label/@for=@id or ancestor::label]
Nope, that only detects label elements that have a "for" and an "id"
attribute with the same value.

No it doesn't. Ignoring the ancestor::label bit, it returns <input>
elements whose id attribute is equal to some <label> element's for
attribute. Both //label/@for and @id are evaluated with the <input>
element as the context node.

There are cases that have the difficulty you refer to, but this isn't
one of them.

-- Richard[/QUOTE]

Right you are...my apologies to the original poster!

Thanks,

Dylan
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top