Return-Path: Delivered-To: apmail-xml-xalan-j-users-archive@www.apache.org Received: (qmail 73991 invoked from network); 27 May 2004 01:33:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 May 2004 01:33:16 -0000 Received: (qmail 16295 invoked by uid 500); 27 May 2004 01:33:52 -0000 Delivered-To: apmail-xml-xalan-j-users-archive@xml.apache.org Received: (qmail 16146 invoked by uid 500); 27 May 2004 01:33:51 -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 16131 invoked by uid 98); 27 May 2004 01:33:51 -0000 Received: from adrian.sutton@ephox.com by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(63.251.155.142):. Processed in 0.030921 secs); 27 May 2004 01:33:51 -0000 X-Qmail-Scanner-Mail-From: adrian.sutton@ephox.com via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(63.251.155.142):. Processed in 0.030921 secs) Received: from unknown (HELO ms06.mse1.mailstreet.com) (63.251.155.142) by hermes.apache.org with SMTP; 27 May 2004 01:33:51 -0000 X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Getting the context node list Date: Wed, 26 May 2004 21:34:05 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Getting the context node list Thread-Index: AcRDiFHyAmzj67GhQ92EumCJfTurmAAAlSMw From: "Adrian Sutton" To: 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 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 =3D new StringBuffer(); try { DTMIterator iter =3D context.getXPathContext().getContextNodes(); =09 int handle =3D iter.getCurrentNode(); if (handle !=3D DTM.NULL) { Node n =3D iter.getDTM(handle).getNode(handle); while (n !=3D null) { =09 buf.append(XMLFilter.getIDFor(n)); n =3D getNextNode(iter); if (n !=3D 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.