Matching attributes between elements

Discussion in 'XML' started by Dylan Nicholson, Aug 31, 2007.

  1. 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
    Dylan Nicholson, Aug 31, 2007
    #1
    1. Advertising

  2. Dylan Nicholson

    Ayush Guest

    [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.
    Ayush, Aug 31, 2007
    #2
    1. Advertising

  3. 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.
    Dylan Nicholson, Aug 31, 2007
    #3
  4. In article <>,
    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.


    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, Aug 31, 2007
    #4
  5. In article <>,
    Peter Flynn <> 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.
    Richard Tobin, Aug 31, 2007
    #5
  6. Dylan Nicholson

    Peter Flynn Guest

    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/
    Peter Flynn, Aug 31, 2007
    #6
  7. On Sep 1, 8:22 am, (Richard Tobin) wrote:
    > In article <>,
    > 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.

    >
    > 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
    Dylan Nicholson, Sep 1, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcel Akkerman
    Replies:
    5
    Views:
    868
    Marcel Akkerman
    Feb 22, 2004
  2. Hugh Sparks
    Replies:
    8
    Views:
    554
    Hugh Sparks
    Jul 30, 2004
  3. DrewM

    Regexp: Matching unquoted attributes

    DrewM, Oct 13, 2003, in forum: ASP General
    Replies:
    1
    Views:
    133
    Chris Hohmann
    Oct 13, 2003
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    233
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    226
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page