¿Cómo puedo obtener todos los elementos tr sin el atributo id?
<tr id="name">...</tr>
<tr>...</tr>
<tr>...</tr>
Gracias
Muy claro:
//tr[not(@id) and not(@class)]
Eso le dará todos los trelementos que carecen de atributos idy class. Si desea que todos los trelementos carezcan de uno de los dos, utilice en orlugar de and:
//tr[not(@id) or not(@class)]
Cuando los atributos y elementos se usan de esta manera, si el atributo o elemento tiene un valor, se trata como si fuera verdadero. Si falta, se trata como si fuera falso.
Si está buscando un elemento que tenga clase apero no tenga clase b, puede hacer lo siguiente.
//*[contains(@class, 'a') and not(contains(@class, 'b'))]
O si quiere asegurarse de no coincidir parcial.
//*[contains(concat(' ', normalize-space(@class), ' '), ' some-class ') and
not(contains(concat(' ', normalize-space(@class), ' '), ' another-class '))]
Puedes intentar //tr[not(@id)]?
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 + ']');
}