-1

I was looking into HTML:Element documentation and came across attr_get_i method which according to documentation states that:

In list context, returns a list consisting of the values of the given attribute for $h and for all its ancestors starting from $h and working its way up.

Now, according to the example given there:

<html lang='i-klingon'>
     <head><title>Pati Pata</title></head>
     <body>
       <h1 lang='la'>Stuff</h1>
       <p lang='es-MX' align='center'>
         Foo bar baz <cite>Quux</cite>.
       </p>
       <p>Hooboy.</p>
     </body>
   </html>

If $h is the <cite> element, $h->attr_get_i("lang") in list context will return the list ('es-MX', 'i-klingon').

Now, according to my unuderstanding the returned list should be ('es-MX', 'la', 'i-klingon') that is it should also consider <h1 lang='la'>Stuff</h1> but according to the documentation it doesn't.

Now, why am I wrong here.

RanRag
  • 48,359
  • 38
  • 114
  • 167
  • What exactly is the question? Why you are wrong? We cannot tell, it is up to you. `

    ` in your example is not an ancestor of ``, therefore it is not considered when searching for attributes via inheritance.

    – choroba Sep 12 '12 at 17:24
  • 2
    @choroba : The question is why `'la'` is not returned by `attr_get_i` – Zaid Sep 12 '12 at 17:27

2 Answers2

2

The 'lang' attributes here are:

+-------------+------------------+
|    lang     |       path       |
+-------------+------------------+
| i-klingon   | /html            |
| la          | /html/body/h1    |
| es-MX       | /html/body/p     |
+-------------+------------------+

The <cite> node does not have <h1> as its parent (path is /html/body/p/cite), so <h1> is not its ancestor. This is why the method does not return it.

Zaid
  • 36,680
  • 16
  • 86
  • 155
  • Thanks. I always have trouble understanding the DOM/Tree structure can you suggest me a nice detailed/descriptive intro for the same. – RanRag Sep 12 '12 at 17:31
1

<h1 lang='la'>Stuff</h1> is not an ancestor of <cite>, it is a sibling.

perreal
  • 94,503
  • 21
  • 155
  • 181