Using XPath to select TD elements in a table with visible data

Discussion in 'XML' started by Foxpointe, Jul 25, 2006.

  1. Foxpointe

    Foxpointe Guest

    I'm new to XPath so am sure my understanding is the issue here and could
    use some help....

    I've got some fairly messy (X)HTML which has TD elements sprinkled in
    solely for the purposes of formatting (i.e. <td height="2"></td>) and
    was thinking that I could use XPath to select only the TD nodes which
    actually display a value. I've verified the basic path to get all
    elements in the table (./html/body/table/tr), but when tried to extend
    this with various permutations such as
    ../html/body/table/tr/td[string-length(text()) > 0] without success.

    Thanks in advance,
    Phil
     
    Foxpointe, Jul 25, 2006
    #1
    1. Advertising

  2. In article <>,
    Foxpointe <> wrote:
    >./html/body/table/tr/td[string-length(text()) > 0] without success.


    That should work, but you could just use

    ./html/body/table/tr/td[text()]

    since empty ones won't have a text node at all.

    -- Richard
     
    Richard Tobin, Jul 26, 2006
    #2
    1. Advertising

  3. Foxpointe

    Foxpointe Guest

    Richard Tobin wrote:
    > That should work, but you could just use
    >
    > ./html/body/table/tr/td[text()]
    >
    > since empty ones won't have a text node at all.
    >
    > -- Richard


    It turns out it did work (user error ;-) but thanks for the tip as I
    didn't realize I didn't need to explicitly check the length.

    Thanks,
    Phil
     
    Foxpointe, Jul 27, 2006
    #3
    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. spamfurnace
    Replies:
    1
    Views:
    2,640
    Scott M.
    May 24, 2004
  2. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,457
    Brian Hoops
    Oct 28, 2004
  3. will
    Replies:
    1
    Views:
    1,152
    Pavel Lepin
    Aug 15, 2007
  4. Jurjen de Groot
    Replies:
    0
    Views:
    314
    Jurjen de Groot
    May 19, 2008
  5. Robert Oschler
    Replies:
    1
    Views:
    128
    Robert Oschler
    Sep 3, 2005
Loading...

Share This Page