Re: [jxpath] using the last() function? (repost)

"Dmitri Plotnikov" <[email protected]>
Newsgroups gmane.comp.jakarta.commons.user,gmane.text.xml.commons.devel
Message-ID <00c401c3dcaa$5f975490$0500a8c0@plotnix2500>
Joern,

The last() function is now fixed.

- Dmitri

----- Original Message ----- 
From: "joern turner" <[email protected]>
To: "Jakarta Commons Users List" <[email protected]>
Sent: Sunday, January 04, 2004 7:02 PM
Subject: [jxpath] using the last() function? (repost)


> Hello,
>
> first of all, thanks for this great piece of code - its a vital part of
> our own open-source project.
>
> but i have a problem using the last() function in jxpath. i'm using the
> following xml:
>
> <instance>
>    <my:order my:money="4711">
>      <my:item my:money="50">
>        <my:amount>500</my:amount>
>        <my:discount>100</my:discount>
>      </my:item>
>      <my:item my:money="4711">
>        <my:amount>77</my:amount>
>        <my:discount>77</my:discount>
>      </my:item>
>    </my:order>
> </instance>
>
> i'm trying to get the last element of a nodeset like this:
>
> JXPathContext context = JXPathContext.newContext(doc);
>
> Pointer pointer1 = context.getPointer("//my:order/my:item[2]");
>
assertTrue(pointer1.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
>
> works ok.
>
> Pointer pointer2
>    =context.getPointer("//my:order/my:item[position()=count(../*)]");
>
assertTrue(pointer2.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
>
> works ok.
>
> Pointer pointer3 =
>    context.getPointer("//my:order/my:item[position()=2]");
>
assertTrue(pointer3.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
>
> works ok.
>
> Pointer pointer4 = context.getPointer("//my:order/my:item[last()]");
>
assertTrue(pointer4.asPath().equals("/instance[1]/my:order[1]/my:item[2]"));
>
> fails with stacktrace. what am i doing wrong? please help. i've
> investigated the problem but cannot find a way to get it working.
>
> any help appreaciated.
>
> Joern
>
>
testLast(org.chiba.xml.xforms.xpath.test.JXPathTest)java.lang.NullPointerExc
eption
>      at
>
org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.previous(DOMNodeItera
tor.java:131)
>      at
>
org.apache.commons.jxpath.ri.model.dom.DOMNodeIterator.setPosition(DOMNodeIt
erator.java:121)
>      at
>
org.apache.commons.jxpath.ri.axes.ChildContext.setPosition(ChildContext.java
:152)
>      at
>
org.apache.commons.jxpath.ri.compiler.CoreFunction.functionLast(CoreFunction
.java:335)
>      at
>
org.apache.commons.jxpath.ri.compiler.CoreFunction.computeValue(CoreFunction
.java:259)
>      at
>
org.apache.commons.jxpath.ri.axes.PredicateContext.nextNode(PredicateContext
.java:127)
>      at
>
org.apache.commons.jxpath.ri.EvalContext.getSingleNodePointer(EvalContext.ja
va:333)
>      at
> org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:211)
>      at
>
org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path
.java:192)
>      at
>
org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath
.java:128)
>      at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathCon
textReferenceImpl.java:366)
>      at
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer(JXPathCon
textReferenceImpl.java:362)
>      at
> org.chiba.xml.xforms.xpath.test.JXPathTest.testLast(JXPathTest.java:162)
>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>      at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
>      at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
>      at
>
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.