Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Matching attributes between elements (http://www.velocityreviews.com/forums/t533882-matching-attributes-between-elements.html)

Dylan Nicholson 08-31-2007 01:18 AM

Matching attributes between elements
 
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


Ayush 08-31-2007 01:49 AM

Re: Matching attributes between elements
 
[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.

Dylan Nicholson 08-31-2007 10:01 PM

Re: Matching attributes between elements
 
On Aug 31, 11:49 am, Ayush <"ayushmaan.j[aatt]gmail.com"> wrote:
> [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]
>

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.


Richard Tobin 08-31-2007 10:22 PM

Re: Matching attributes between elements
 
In article <1188597678.852587.226910@x40g2000prg.googlegroups .com>,
Dylan Nicholson <wizofaus@hotmail.com> 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.


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

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

Richard Tobin 08-31-2007 10:24 PM

Re: Matching attributes between elements
 
In article <5jriu1F10abrU1@mid.individual.net>,
Peter Flynn <remove.nosp@m.from.address> 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, whereby the label's "for" attribute value must match
>> the input's "id" attribute value. i.e.: something like
>>
>> //input[//label[@for=???@id]]


>//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
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

Peter Flynn 08-31-2007 10:27 PM

Re: Matching attributes between elements
 
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, 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
--
XML FAQ: http://xml.silmaril.ie/

Dylan Nicholson 09-01-2007 09:51 AM

Re: Matching attributes between elements
 
On Sep 1, 8:22 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
> In article <1188597678.852587.226...@x40g2000prg.googlegroups .com>,
> Dylan Nicholson <wizof...@hotmail.com> 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.

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


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

Thanks,

Dylan



All times are GMT. The time now is 11:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.