Return-Path: Delivered-To: apmail-xml-xalan-j-users-archive@www.apache.org Received: (qmail 85832 invoked from network); 28 May 2004 18:57:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 28 May 2004 18:57:45 -0000 Received: (qmail 37606 invoked by uid 500); 28 May 2004 18:53:38 -0000 Delivered-To: apmail-xml-xalan-j-users-archive@xml.apache.org Received: (qmail 37537 invoked by uid 500); 28 May 2004 18:53:38 -0000 Mailing-List: contact xalan-j-users-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list xalan-j-users@xml.apache.org Received: (qmail 37426 invoked by uid 98); 28 May 2004 18:53:37 -0000 Received: from gentijo@eyecatching.com by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(63.192.148.66):. Processed in 0.187348 secs); 28 May 2004 18:53:37 -0000 X-Qmail-Scanner-Mail-From: gentijo@eyecatching.com via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(63.192.148.66):. Processed in 0.187348 secs) Received: from unknown (HELO webdns.eyecatching.com) (63.192.148.66) by hermes.apache.org with SMTP; 28 May 2004 18:53:35 -0000 Received: from eyecatching.com (c-24-4-189-206.client.comcast.net [24.4.189.206]) by webdns.eyecatching.com (8.12.11/8.12.8) with ESMTP id i4SJZw5H026555; Fri, 28 May 2004 12:36:01 -0700 Message-ID: <40B78A6E.6040307@eyecatching.com> Date: Fri, 28 May 2004 11:52:30 -0700 From: John Gentilin User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7b) Gecko/20040316 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Adrian Sutton CC: xalan-j-users@xml.apache.org Subject: Re: Getting the context node list References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: hermes.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Adrian, Back in Jan. I was into this very same problem. Scott Boag pointed me to a paper on Incremental XSLT which may be a help to you. http://www.research.ibm.com/people/v/villard/Papiers/incXSLT.pdf Now I don't know the answer to your problem but I wanted to point out what may be another problem. If you change the DOM in the background, the DTM will NOT update so the representation of you document to any of the XPath expressions may not make sense. There is a method call called getDOMBackPointer which will give you a the real Element from the source document which also may be a help. You may also want top make your Extension Function into an Extension Element since the XSLProcessorContext will give you more access than the ExpressionContext. Hope that helps. John G Adrian Sutton wrote: > Hi all, > (Sorry for the previous email, Outlook decided to send when I tried to > paste. Go figure) > > I'm looking for a way to get the complete context node list and am > generally not getting far. I need the full context node list instead of > just the actual context node because I need to rerun XPath expressions > dynamically as the user changes the DOM, but can't run the entire XSLT > again because of performance issues. I can get the XPath expression, > find the context node itself, find all the namespaces in effect, and > identify all the nodes which are used in the expression, I just can't > get the full context node list. Without the full context node list, > functions like position() don't work correctly. > > For the record, my current test expression is: > my:quantityOrdered * my:unitPrice > > but the aim is to support any valid XPath expression. > > My first approach was to look for an XPath function or XSLT element I > could use to get the full context node list but I haven't found > anything. > > My second approach was to use a custom function and I've had some > success with that. My currrent function is: > > public String getContext(ExpressionContext context) { > StringBuffer buf = new StringBuffer(); > try { > DTMIterator iter = > context.getXPathContext().getContextNodes(); > > int handle = iter.getCurrentNode(); > if (handle != DTM.NULL) { > Node n = > iter.getDTM(handle).getNode(handle); > while (n != null) { > > buf.append(XMLFilter.getIDFor(n)); > n = getNextNode(iter); > if (n != null) { > buf.append(","); > } > } > } > } catch (Exception e) { > log.error("Failed to create context for xpath > expression.", e); > } > return buf.toString(); > } > > XMLFilter.getIDFor(n) gives a String that can be used to retrieve the > node from the DOM later on (though various magic incantations we've > discovered). For the first node in the context list this works > perfectly, unfortunately it appears that the DTMIterator I'm using is > the same one that Xalan is using and so the method causes Xalan to skip > over all but the first element (because getContext() has already > iterated through the nodes). When I try to reset the position of the > iterator I get the exception: > > This NodeSetDTM can not iterate to a previous > node!>java.lang.RuntimeException: This NodeSetDTM can not iterate to a > previous node! > at > com.ephox.org.apache.xpath.axes.LocPathIterator.previousNode(LocPathIter > ator.java:627) > at > com.ephox.org.apache.xpath.axes.NodeSequence.previousNode(NodeSequence.j > ava:364) > at > com.ephox.org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:485 > ) > at > com.ephox.org.apache.xpath.axes.NodeSequence.setCurrentPos(NodeSequence. > java:499) > at > com.ephox.editlive.java2.editor.xml.xpath.XPathExtensions.getContext(XPa > thExtensions.java:51) > > I notice that there is a DTMIterator.setShouldCacheNodes(boolean) method > which enables random access to the iterator but calling it seems to > reset the iterator such that it no longer contains any nodes. Is there > any property to set to make all iterators random access enabled? I've > tried setting: > > http://xml.apache.org/xalan/features/incremental > TransformerFactoryImpl.FEATURE_OPTIMIZE > and > http://xml.apache.org/xalan/features/optimize > > to false with no success. > > Alternately, is there some other approach I'm missing? > > Regards, > > Adrian Sutton. -- -------------------------------------- John Gentilin Eye Catching Solutions Inc. 18314 Carlwyn Drive Castro Valley CA 94546 Contact Info gentijo@eyecatching.com Ca Office 1-510-881-4821 NJ Office 1-732-422-4917