Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 28442 invoked by uid 500); 24 Sep 2001 15:43:26 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 28424 invoked from network); 24 Sep 2001 15:43:26 -0000 Date: 24 Sep 2001 15:43:15 -0000 Message-ID: <20010924154315.53837.qmail@icarus.apache.org> From: morten@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom DOMImpl.java NthIterator.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N morten 01/09/24 08:43:15 Modified: java/src/org/apache/xalan/xsltc/dom DOMImpl.java NthIterator.java Log: Another fix for the preceding-sibling iterator. It appeared that this iterator returned its nodes in the wrong order, and this was the reason why the position iterator (used to implement preceding-siblling::*[n]) did not return the correct node. It is quite amazing that this iterator has been returning nodes in the wrong order for so long without any of us notising, and hopefully this fix will help eliminate a few of our open bugs. PR: bugzilla 2954 Obtained from: n/a Submitted by: morten@xml.apache.org Reviewed by: morten@xml.apache.org Revision Changes Path 1.33 +43 -14 xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java Index: DOMImpl.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- DOMImpl.java 2001/09/24 09:54:11 1.32 +++ DOMImpl.java 2001/09/24 15:43:14 1.33 @@ -1,5 +1,5 @@ /* - * @(#)$Id: DOMImpl.java,v 1.32 2001/09/24 09:54:11 morten Exp $ + * @(#)$Id: DOMImpl.java,v 1.33 2001/09/24 15:43:14 morten Exp $ * * The Apache Software License, Version 1.1 * @@ -941,8 +941,9 @@ * Iterator that returns preceding siblings of a given node */ private class PrecedingSiblingIterator extends NodeIteratorBase { - private int _start; + private int _node; + private int _mom; public boolean isReverse() { return true; @@ -950,21 +951,35 @@ public NodeIterator setStartNode(int node) { if (_isRestartable) { - _node = _offsetOrChild[_parent[_startNode = _start = node]]; + int tmp = NULL; + _startNode = node; + _mom = _parent[node]; + _node = _offsetOrChild[_mom]; + while ((_node != node) && (_node != NULL)) { + tmp = _node; + _node = _nextSibling[_node]; + } + _node = tmp; return resetPosition(); } return this; } - + public int next() { - if (_node == _start) { - return NULL; - } - else { - final int node = _node; - _node = _nextSibling[node]; - return returnNode(node); - } + // Return NULL if end already reached + if (_node == NULL) return NULL; + + int current = _offsetOrChild[_mom]; + + // Otherwise find the next preceeding sibling + int last = NULL; + while ((current != _node) && (current != NULL)) { + last = current; + current = _nextSibling[current]; + } + current = _node; + _node = last; + return returnNode(current); } public void setMark() { @@ -1790,8 +1805,14 @@ return getNodeValue(_offsetOrChild[node]); case TEXT: case COMMENT: - case PROCESSING_INSTRUCTION: return makeStringValue(node); + case PROCESSING_INSTRUCTION: + final String pistr = makeStringValue(node); + final int col = pistr.indexOf(' '); + if (col > 0) + return pistr.substring(col+1); + else + return pistr; default: if (node < _firstAttributeNode) return getElementValue(node); // element string value @@ -2046,7 +2067,12 @@ case DOM.COMMENT: return EMPTYSTRING; case DOM.PROCESSING_INSTRUCTION: - return "a-pi"; + final String pistr = makeStringValue(node); + final int col = pistr.indexOf(' '); + if (col > -1) + return(pistr.substring(0,col)); + else + return pistr; default: // Construct the local part (omit '@' for attributes) String name = getLocalName(node); @@ -2523,6 +2549,9 @@ _lengthOrAttr[child]); break; case PROCESSING_INSTRUCTION: + buffer.append(_text, + _offsetOrChild[child], + _lengthOrAttr[child]); break; // !!! at the moment default can only be an element??? default: 1.5 +3 -13 xml-xalan/java/src/org/apache/xalan/xsltc/dom/NthIterator.java Index: NthIterator.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NthIterator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- NthIterator.java 2001/09/24 08:59:21 1.4 +++ NthIterator.java 2001/09/24 15:43:15 1.5 @@ -1,5 +1,5 @@ /* - * @(#)$Id: NthIterator.java,v 1.4 2001/09/24 08:59:21 morten Exp $ + * @(#)$Id: NthIterator.java,v 1.5 2001/09/24 15:43:15 morten Exp $ * * The Apache Software License, Version 1.1 * @@ -69,13 +69,12 @@ public final class NthIterator extends NodeIteratorBase { // ...[N] private final NodeIterator _source; - private int _position = 1; - private int _n = 0; + private final int _position; private boolean _ready; public NthIterator(NodeIterator source, int n) { _source = source; - _n = n; + _position = n; } public int next() { @@ -94,15 +93,6 @@ public NodeIterator setStartNode(final int node) { _source.setStartNode(node); - // Make sure we count backwards if the iterator is reverse - if ((_source instanceof FilterIterator) && (_source.isReverse())) { - int last = _source.getLast(); - _position = (last - _n) + 1; - if (_position < 1) _position = 1; - } - else { - _position = _n; - } _ready = true; return this; } --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: xalan-cvs-help@xml.apache.org