2010-03-08 11 views

उत्तर

88

सुंदर सरल:

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

है कि आप दोनों id और class गुण की कमी सभी tr तत्वों दे देंगे। आप दोनों में से एक की कमी सभी tr तत्वों चाहते हैं, orand के बजाय का उपयोग करें:

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

जब गुण और तत्वों को इस तरह से इस्तेमाल कर रहे हैं, अगर विशेषता या तत्व एक मूल्य है यह व्यवहार किया जाता है के रूप में अगर यह सच है । यदि यह गायब है तो यह माना जाता है कि यह गलत है।

+0

क्या 'या' उदाहरण काम करेगा। इसके खिलाफ नकारात्मक है? –

-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

प्रयास कर सकते हैं आप एक तत्व है कि वर्ग a है की तलाश में हैं, लेकिन नहीं, वर्ग b है आप निम्नलिखित कर सकते हैं करता है।

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

या नहीं आंशिक मिलान करने के लिए यदि आप सुनिश्चित होना चाहते हैं।

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

संबंधित मुद्दे

 संबंधित मुद्दे