2010-03-08 14 views

Odpowiedz

88

prosta:

//tr[not(@id) and not(@class)] 

To daje wszystkie tr elementów brakuje zarówno id i class atrybuty. Jeśli chcesz, aby wszystkie tr elementów brakuje jednego z tych dwóch, użyj or zamiast and:

//tr[not(@id) or not(@class)] 

Kiedy atrybuty i elementy stosowane są w ten sposób, jeżeli atrybut lub element ma wartość jest traktowany tak, jakby to prawda . Jeśli go brakuje, traktowane jest tak, jakby było fałszywe.

+0

Czy przykład "lub" działa. Ponieważ jest ujemny? –

6

można spróbować //tr[not(@id)]?

-2
if (elm.hasAttribute('id')) { 
    //if id - implement here 
       } else if (elm.hasAttribute('class')) { 
        //if class - implement here 
       } else { 
        for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) { 
         if (sib.localName == elm.localName) i++; }; 
         segs.unshift(elm.localName.toLowerCase() + '[' + i + ']'); 
       } 
6

Jeśli szukasz elementu, który ma klasę a ale nie mieć klasę b, można wykonać następujące czynności.

//*[contains(@class, 'a') and not(contains(@class, 'b'))]

Albo jeśli chcesz być pewien, że nie pasuje do częściowego.

//*[contains(concat(' ', normalize-space(@class), ' '), ' some-class ') and not(contains(concat(' ', normalize-space(@class), ' '), ' another-class '))]

Powiązane problemy