NodeVector getMatchingAncestors ( XPathContext xctxt , int node , boolean stopAtFirstFound ) throws javax . xml . transform . TransformerException { NodeSetDTM ancestors = new NodeSetDTM ( xctxt . getDTMManager ( ) ) ; XPath countMatchPattern = getCountMatchPattern ( xctxt , node ) ; DTM dtm = xctxt . getDTM ( node ) ; while ( DTM . NULL != node ) { if ( ( null != m_fromMatchPattern ) && ( m_fromMatchPattern . getMatchScore ( xctxt , node ) != XPath . MATCH_SCORE_NONE ) ) { // The following if statement gives level="single" different // behavior from level="multiple", which seems incorrect according // to the XSLT spec. For now we are leaving this in to replicate // the same behavior in XT, but, for all intents and purposes we // think this is a bug, or there is something about level="single" // that we still don't understand. if ( ! stopAtFirstFound ) break ; } if ( null == countMatchPattern ) System . out . println ( "Programmers error! countMatchPattern should never be null!" ) ; if ( countMatchPattern . getMatchScore ( xctxt , node ) != XPath . MATCH_SCORE_NONE ) { ancestors . addElement ( node ) ; if ( stopAtFirstFound ) break ; } node = dtm . getParent ( node ) ; } return ancestors ; }
Get the ancestors up to the root that match the pattern .