public int getPreviousNode ( XPathContext xctxt , int pos ) throws TransformerException { XPath countMatchPattern = getCountMatchPattern ( xctxt , pos ) ; DTM dtm = xctxt . getDTM ( pos ) ; if ( Constants . NUMBERLEVEL_ANY == m_level ) { XPath fromMatchPattern = m_fromMatchPattern ; // Do a backwards document-order walk 'till a node is found that matches // the 'from' pattern, or a node is found that matches the 'count' pattern, // or the top of the tree is found. while ( DTM . NULL != pos ) { // Get the previous sibling, if there is no previous sibling, // then count the parent, but if there is a previous sibling, // dive down to the lowest right-hand (last) child of that sibling. int next = dtm . getPreviousSibling ( pos ) ; if ( DTM . NULL == next ) { next = dtm . getParent ( pos ) ; if ( ( DTM . NULL != next ) && ( ( ( ( null != fromMatchPattern ) && ( fromMatchPattern . getMatchScore ( xctxt , next ) != XPath . MATCH_SCORE_NONE ) ) ) || ( dtm . getNodeType ( next ) == DTM . DOCUMENT_NODE ) ) ) { pos = DTM . NULL ; // return null from function. break ; // from while loop } } else { // dive down to the lowest right child. int child = next ; while ( DTM . NULL != child ) { child = dtm . getLastChild ( next ) ; if ( DTM . NULL != child ) next = child ; } } pos = next ; if ( ( DTM . NULL != pos ) && ( ( null == countMatchPattern ) || ( countMatchPattern . getMatchScore ( xctxt , pos ) != XPath . MATCH_SCORE_NONE ) ) ) { break ; } } } else // NUMBERLEVEL_MULTI or NUMBERLEVEL_SINGLE { while ( DTM . NULL != pos ) { pos = dtm . getPreviousSibling ( pos ) ; if ( ( DTM . NULL != pos ) && ( ( null == countMatchPattern ) || ( countMatchPattern . getMatchScore ( xctxt , pos ) != XPath . MATCH_SCORE_NONE ) ) ) { break ; } } } return pos ; }
Get the previous node to be counted .