You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Tomas Studva <ts...@gmail.com> on 2007/12/19 22:22:03 UTC

XPath expression evaluation

Hi,
I need to implement in Xalan(I am directly woring with Xalan sources) such
method:

input: source doc, XPath expression
output: list or set of nodes used to compute value of expression. The nodes
aren't nodes accessed during expression evaluation, but nodes directly
contributing to result value. In case value of expression is node-set, than
it is what I want. For example /root/child[a=3]/substring(child::text()) , I
want all nodes matched by /root/child[a=3]/child::text() .

I need your advice how to implement it. One clever(I think :)) way is to
construct another expression to original expression, which when is evaluated
returns desired result. Maybe I am wrong. Is there any clever way to
implement it, also when I have source code modification access?

Thank in advance, Tomas Studva





-- 
View this message in context: http://www.nabble.com/XPath-expression-evaluation-tp14425470p14425470.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XPath expression evaluation

Posted by Tomas Studva <ts...@gmail.com>.
Hi Dave,
I cite w3c XPath spec: 

>The primary syntactic construct in XPath is the expression. An expression
matches the production Expr. An >expression is evaluated to yield an object,
which has one of the following four basic types:
>
>    * node-set (an unordered collection of nodes without duplicates)
>    * boolean (true or false)
>    * number (a floating-point number)
>    * string (a sequence of UCS characters)
If the object is for example string, I want to have in desired node set
nodes, which contributed to that string by at least one character. It means
every node which is not used in condition.

Probably the set would be constructed by removing arithmetics and functions
from expr. and making over nodes union. Doing so, is hard if I don't have
parse tree of expr, but if I have parse tree it is ... not easy :)(many
cases, traversing tree, ... uff).

Second way I mind, is to construct node set programatically when original
expr is evaluated. It is principially the same, but I am directly
constructing node set instead of another expr. The hard part is, that I
don't know XPath part of Xalan at all.

Hmm the expr should be, but I am not sure
substring(/root/child[a=3]/child::text(), start, length)

Tomas
-- 
View this message in context: http://www.nabble.com/XPath-expression-evaluation-tp14425470p14426971.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XPath expression evaluation

Posted by David Bertoni <db...@apache.org>.
Tomas Studva wrote:
> Hi,
> I need to implement in Xalan(I am directly woring with Xalan sources) such
> method:
> 
> input: source doc, XPath expression
> output: list or set of nodes used to compute value of expression. The nodes
> aren't nodes accessed during expression evaluation, but nodes directly
> contributing to result value. In case value of expression is node-set, than
> it is what I want. For example /root/child[a=3]/substring(child::text()) , I
> want all nodes matched by /root/child[a=3]/child::text() .
/root/child[a=3]/substring(child::text()) is not a legal XPath expression, 
because substring() cannot occur as a step.

> 
> I need your advice how to implement it. One clever(I think :)) way is to
> construct another expression to original expression, which when is evaluated
> returns desired result. Maybe I am wrong. Is there any clever way to
> implement it, also when I have source code modification access?

I don't think you've fully stated your requirements, so it's hard to say, 
but I don't think it will be easy.  You certainly should be able to analyze 
the expression for all of the location paths, but how you'll decide which 
is the result you're interested depends on the requirements.

Dave