sboag       00/10/17 12:50:38

  Modified:    java/src/org/apache/xpath/patterns StepPattern.java
  Log:
  Don't match on the Document node for show_all.
  
  Revision  Changes    Path
  1.9       +42 -10    
xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StepPattern.java  2000/10/16 22:56:04     1.8
  +++ StepPattern.java  2000/10/17 19:50:37     1.9
  @@ -68,6 +68,7 @@
     public void setRelativePathPattern(StepPattern expr)
     {
       m_relativePathPattern = expr;
  +    calcScore();
     }
     
     Expression[] m_predicates;
  @@ -91,13 +92,14 @@
     /**
      * Static calc of match score.
      */
  -  protected final void calcScore()
  +  protected void calcScore()
     {
  -    if((getPredicateCount() > 0) || (null != m_relativePathPattern))
  +    if((getPredicateCount() > 0)  || (null != m_relativePathPattern))
         m_score = SCORE_OTHER;
       else
         super.calcScore();
  -    calcTargetString();
  +    if(null == m_targetString)
  +      calcTargetString();
     }
   
     
  @@ -105,12 +107,17 @@
       throws org.xml.sax.SAXException
     {
       XObject score;
  -    Node context = xctxt.getCurrentNode();
  -    int nodeType = context.getNodeType();
  -    int whatToShow = getWhatToShow();
  +    int nodeType = xctxt.getCurrentNode().getNodeType();
       if(nodeType == Node.ATTRIBUTE_NODE &&
  -       whatToShow != NodeFilter.SHOW_ATTRIBUTE)
  +         m_whatToShow != NodeFilter.SHOW_ATTRIBUTE)
  +    {
         score = NodeTest.SCORE_NONE;
  +    }
  +    else if(nodeType == Node.DOCUMENT_NODE &&
  +         m_whatToShow != NodeFilter.SHOW_DOCUMENT)
  +    {
  +      score = NodeTest.SCORE_NONE;
  +    }
       else
         score = super.execute(xctxt);
       
  @@ -122,10 +129,7 @@
       
       int n = getPredicateCount();
       if(n == 0)
  -    {
  -      // System.out.println("executeStep: "+this.m_name+" = "+score);
         return score;
  -    }
   
       // 
xctxt.getVarStack().setCurrentStackFrameIndex(m_lpi.getStackFrameIndex());
       // xctxt.setNamespaceContext(m_lpi.getPrefixResolver());
  @@ -285,6 +289,34 @@
       }
       return score;
     }
  +  
  +  private static final boolean DEBUG_MATCHES = false;
  +  
  +  /**
  +   * Get the match score of the given node.
  +   * @param context The current source tree context node.
  +   * @returns score, one of MATCH_SCORE_NODETEST, 
  +   * MATCH_SCORE_NONE, MATCH_SCORE_OTHER, MATCH_SCORE_QNAME.
  +   */
  +  public double getMatchScore(XPathContext xctxt, Node context) 
  +    throws org.xml.sax.SAXException
  +  {
  +    xctxt.pushCurrentNode(context);
  +    xctxt.pushCurrentExpressionNode(context);
  +    try
  +    {
  +      XObject score = execute(xctxt);
  +
  +      return score.num();
  +    }
  +    finally
  +    {
  +      xctxt.popCurrentNode();
  +      xctxt.popCurrentExpressionNode();
  +    }
  +    // return XPath.MATCH_SCORE_NONE;
  +  }
  +
     
   
   }
  
  
  

Reply via email to