Both position() and last() are working for me. What version of Xalan are you using?
Here are the relevant imports I'm doing for the code below: import javax.xml.transform.*; import javax.xml.transform.dom.*; import org.apache.xpath.*; import org.apache.xpath.objects.*; last() gives me "333", while position() gives me "123". -----Original Message----- From: Hrvoje Simic [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 18, 2005 10:08 AM To: Robert Houben; [EMAIL PROTECTED] Subject: RE: using position() in an XPath expression within a current node list > Here is what you do... Thanks for all the effort. Unfortunately, this doesn't work for me. position() returns "111". Interestingly, last() now returns "012". Does it work on your machine? And what about output from "last()"? I've tried with Xalan 2.6.0 and JRE 1.4.2. Here's the version I used (I've tried also variations on theme), just to be sure the code got transported ok: String es1 = "/a/b"; String es2 = "position()"; XPathContext context = new XPathContext(); XPath xp1 = new XPath( es1, null, null, XPath.SELECT ); XPath xp2 = new XPath( es2, null, null, XPath.SELECT ); XObject xo1 = xp1.execute( context, doc, null ); NodeList nodelist = xo1.nodelist(); int contextSize = nodelist.getLength(); context.pushContextNodeList( (org.apache.xml.dtm.DTMIterator) xo1 ); for ( int i = 0; i < contextSize; i ++ ) { Node n = nodelist.item( i ); context.getContextNodeList().nextNode(); XObject xo2 = xp2.execute( context, n, null ); System.out.print( xo2 ); }
