Hi all, 

I just commited the fix to CVS. 
There is a test case added at the end of xml/test/tests.xml , 
the one that uses xml/simple.xml . 

Jan


----------  Original message  ----------
Subject: [Jaxen] AbsoluteLocationPath misbehaviour
Date: Mon, 25 Mar 2002 10:30:23 +0100
From: Jan Dvorak <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]


Hi,

This is a bug report and a fix.

I had trouble with expressions like concat( /root/b, . ) in context /root/a .
The second argument seemed to evaluate to a wrong value.
A couple of debugging println()'s in org.jaxen.expr.DefaultFunctionCallExpr
showed that different contexts were used to evaluate the parameters.
As there is no action intervening between the parameter evaluations,
it must have been the evaluations themselves that changed the context.

To the extent I understand XPath,
evaluating an expression in a context should not change that context.
(A separate node-set is the result of an expression evaluation,
and that node-set may become a basis of a different context,
but the original context shall not change.)

On a closer look it became clear that absolute location paths
were at the source of the trouble.
Indeed, org.jaxen.expr.DefaultAbsoluteLocationPath constructs
an absContext, but makes no use of it.
It used the context argument instead to do the work.
That is where the context was modified.

Here is a cvs diff that corrects it:

Index: src/java/main/org/jaxen/expr/DefaultAbsoluteLocationPath.java
===================================================================
RCS file:
/cvsroot/jaxen/jaxen/src/java/main/org/jaxen/expr/DefaultAbsoluteLocationPath
.java,v retrieving revision 1.6
diff -r1.6 DefaultAbsoluteLocationPath.java
63c63
<         context.setNodeSet( list );
---

>         absContext.setNodeSet( list );

65c65
<         return super.evaluate( context );
---

>         return super.evaluate( absContext );

I tested it using the following test cases:

  <document url="xml/simple.xml">
   <context select="/root/a">
    <valueOf select="concat( ., /root/b )">ab</valueOf>
    <valueOf select="concat( ../b, . )">ba</valueOf>
    <valueOf select="concat( /root/b, . )">ba</valueOf>
   </context>
  </document>

where document 'xml/simple.xml' is a really simple one:

<?xml version="1.0" ?>
<root>
 <a>a</a>
 <b>b</b>
</root>



Jan Dvorak

P.S. Jaxen is really great!

_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

-------------------------------------------------------

_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to