From: firstname.lastname@example.org [mailto:email@example.com] On Behalf Of Johannes Lichtenberger
Sent: 19 December 2007 12:39
To: Michael Kay
Cc: 'Mailing list for SAXON XSLT queries'
Subject: Re: [saxon] NodeInfo implementation
Am 11.12.2007 um 22:05 schrieb Michael Kay:
When Saxon is evaluating //a, it doesn't know that there is only onea-element and that the a-element doesn't have any further a-elements in itssubtree - it has to keep looking!I'm afraid I don't know why there aren't more calls on getStringValue() -that will depend on the context in which the path expression appears.Remember that an expression like //a/text() isn't naturally sorted, so ingeneral I would expect the text nodes to be retrieved first, and then sortedinto document order before being atomized. In your example the sort will bea no-op, but that wouldn't be the case for example with<a>ppp<a>qqq</a>rrr</a>where the parent of rrr is in the result of //a ahead of the parent of qqq.It might be that you have used the path expression in a context where orderdoesn't matter, for example as an operand of "=", in which case Saxon willbe quite happy to retrieve the results in the "wrong" order.I have to tell you that when I walk through the evaluation of suchexpressions in the debugger, I often get surprises myself - sometimes itseems the optimizer has a mind of its own.my testfile:<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a attribute="foobar">foo1<b><c/>blabla</b>foo2<b>blubb</b>foo3</a>
Uhm it's a simple JUnit TestCase:final XPathExpression findLine =xpe.compile("//a/text()");...final ArrayList result =(ArrayList) findLine.evaluate(doc, XPathConstants.NODESET);TestCase.assertNotNull(result);TestCase.assertEquals("foo1", ((NodeInfoImpl)result.get(0)).getStringValue());TestCase.assertEquals("foo2", ((NodeInfoImpl)result.get(1)).getStringValue());TestCase.assertEquals("foo3", ((NodeInfoImpl)result.get(2)).getStringValue());I'm also not sure why it returns a NodeInfo object instead of a text string directly. The first ((NodeInfoImpl)result.get(0)).getStringValue()) returns "foo3"... and it returns only this "foo3", so foo1 and foo2 is never returned (I get an IndexOutOfBound exception with result.get(1) and result.get(2)), but it might be my testcase, I'm really not sure why it returns a NodeInfo object... :-/best regards,Johannes