Thanks Gary.  As usual, your analysis of the problem is revealing and
helpful.  I'll work on this today.

-scott




                                                                                       
                            
                    Gary L Peskin                                                      
                            
                    <garyp@firste        To:     [EMAIL PROTECTED]              
                            
                    ch.com>              cc:     (bcc: Scott Boag/CAM/Lotus)           
                            
                                         Subject:     DescendantIterator problems (was 
Re: xpath query no longer   
                    07/29/01             working....)                                  
                            
                    03:04 PM                                                           
                            
                    Please                                                             
                            
                    respond to                                                         
                            
                    xalan-dev                                                          
                            
                                                                                       
                            
                                                                                       
                            




Scott --

I've looked at this problem and it seems to me that the problem is that
DescendantIterator is being way "overprescribed" in
WalkerFactory.newDTMIterator.  I'm not sure what cases you want
DescendantIterator to handle so I haven't gone in and changed anything
and I think I'd have to think about all of this some more if I were to
do that.

DescendantIterator can handle up to three location steps.  One of the
location steps must include the descendant:: or descendant-or-self::
axes.  A single location step is already handled by a OneStepIterator so
that is not an issue.  I've classified the location steps like this:

A = root (ie /).  This must occur first.
B = self::  This must occur first.
C = descendant-or-self::  This may occur at any time
D = descendant:  This must always be step 1 or 2.
E = child::  This must come sometime after either
  (a) a descdendant-or-self:: step,  or
  (b) in the sequence self::?/descendant::?/child::?, or
  (c) in the sequence descendant::?/self::?/child::?

I use the ? to indicate anything that is valid there, including a
predicate.  Location steps which have proximity information (ie which
must know where they are in the current node list) disqualify the XPath
from being handled as a DescendantIterator.

Thus, the following 25 types of XPath expressions all qualify for
DescendantItererator:

2 Steps                3 Steps
-------                -------
1.  AC                 10.  ACC            19.  CDC
2.  AD                 11.  ACE            20.  CDE
3.  BC                 12.  ADC            21.  CEC
4.  BD                 13.  BCC            22.  CEE
5.  CC                 14.  BCE            23.  DCC
6.  CD                 15.  BDC            24.  DCE
7.  CE                 16.  BDE            25.  DDC
8.  DC                 17.  CCC
9.  DD                 18.  CCE

Unfortunately, DescendantIterator was not, I belive, designed to handle
most of these.  For example, type 21 would be:

  descendant-or-self::node()/child::node()/descendant-or-self::node()

I don't think that the third step is properly handled here.  Also, type
21 is:


descendant-or-self::foo[bar]/child::zorch[zilch]/descendent-or-self::asdf[qwerty]


which for sure is not handled.

In short (I realize it may too late for that :)), we have the following
problems:
1.  Patterns are used that DescendantIterator was not designed to handle
at all.  Some of these are fixable in the DescendantIterator code, like:
  /descendant-or-self::variable[foo]
(when the code sees root in the first position, it seems to assume a 3
step iterator) but others are not without a fair amount of work.
2.  Intermediate predicates seem to be ignored, even when they are not
"proximity-aware", like this:
  /descendant-or-self::node[foo]/bar
3.  The code currently seems to assume that the node-test will be node()
or something like that.  The following is handled correctly:
  //bar
but this is not:
  /descendant-or-self::foo/bar
4.  I haven't checked the actual iterator code but will it work if the
context node is an attribute, namespace, or text node?

In addition the test in WalkerFactor.getDTMIterator:
      else if (isOptimizableForDescendantIterator(compiler,
firstStepPos, 0)
             && getStepCount(analysis) <= 3
             && walksDescendants(analysis)
             && walksSubtreeOnlyFromRootOrContext(analysis))
is duplicative because the latter three conditions are already checked
for by the isOptimizableForDescendantIterator() method.

I hope this helps you pinpoint what's going on so that it can be
repaired.  If you're too busy to focus on this, please let me know what
you'd like DescendantIterator to handle and I'll fit the repairs into my
schedule.

Thanks,
Gary

Gary L Peskin wrote:
>
> Pete --
>
> Please enter this into bugzilla at
> http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=XalanJ2
>
> Thank you for identifying this problem.
>
> Gary
>
> Pete Clark wrote:
> >
> > >This statement used to work under xalan 1, but no longer does in the
> > >current developer release of xalan.
> > >
> > >NodeList boboList = xPath.selectNodeList(someNode,
> > >"/descendant::variable[contains(text(), \".\")]");
> > >
> > >java.lang.RuntimeException: Programmer's assertion in getNextStepPos:
> > >unknown stepType: -2
> > >         at
> > >
org.apache.xpath.compiler.OpMap.getFirstPredicateOpPos(OpMap.java:325)
> > >         at
> > >
org.apache.xpath.axes.PredicatedNodeTest.initPredicateInfo(PredicatedNodeTest.java:140)

> > >         at
> > >
org.apache.xpath.axes.DescendantIterator.<init>(DescendantIterator.java:139)

> > >         at
> > >
org.apache.xpath.axes.WalkerFactory.newDTMIterator(WalkerFactory.java:294)
> > >         at
org.apache.xpath.compiler.Compiler.locationPath(Compiler.java:677)
> > >         at
org.apache.xpath.compiler.Compiler.compile(Compiler.java:217)
> > >         at
org.apache.xpath.compiler.Compiler.compile(Compiler.java:163)
> > >         at org.apache.xpath.XPath.<init>(XPath.java:223)
> > >         at org.apache.xpath.XPathAPI.eval(XPathAPI.java:270)
> > >         at
org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:202)
> > >         at
org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:182)
> > >...
> > >Exception in thread "main"
> > >
> > >Any idea why?
> > >
> > >Thanks-
> > >Pete




Reply via email to