private int getElementIndex ( Node node ) { final String nodeName = node . getNodeName ( ) ; int count = 1 ; for ( Node previousSibling = node . getPreviousSibling ( ) ; previousSibling != null ; previousSibling = previousSibling . getPreviousSibling ( ) ) { if ( previousSibling . getNodeType ( ) == Node . ELEMENT_NODE && previousSibling . getNodeName ( ) . equals ( nodeName ) ) { count ++ ; } } return count ; }
Gets the index of this element relative to other siblings with the same node name