Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 362688

Summary: dynamic context and atomic values
Product: [WebTools] WTP Source Editing Reporter: Lukasz Wycisk <lukasz>
Component: wst.xpathAssignee: Project Inbox <wst.xsl-inbox>
Status: NEW --- QA Contact: Jesper Moller <jesper>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Patch
none
testcase none

Description Lukasz Wycisk CLA 2011-11-02 11:13:11 EDT
11. According to specification dynamic context contains:
[Definition: The context item is the item currently being processed. An item is either an atomic value or a node.]

[Definition: When the context item is a node, it can also be referred to as the context node.] 

The context item is returned by an expression consisting of a single dot (.). When an expression E1/E2 or E1[E2] is evaluated, each item in the sequence obtained by evaluating E1 becomes the context item in the inner focus for an evaluation of E2.


In current implementation it is not possible to pass atomic values to evaluator since it is filtered for org.w3c.Node implementations. Older approach is even worst since it allows only DocType to be context node.

Test: DynamicContextValueTest.testDynamicContextValue() shows this problem.
Comment 1 Lukasz Wycisk CLA 2011-11-02 11:14:10 EDT
Created attachment 206342 [details]
Patch
Comment 2 Lukasz Wycisk CLA 2011-11-02 11:14:27 EDT
Created attachment 206343 [details]
testcase
Comment 3 Lukasz Wycisk CLA 2011-11-02 11:18:32 EDT
Fix is simple since evaluator accepts every Object it can be additionally filtered for Item objects. It will work with current tests however we think Object[] parameter will probably cause many problems. 

Do you think the evaluation method can be changed to accept only Item[]? It is easy to create one since NodeType.dom_to_xpath is public. There can also be another method with Node[] parms for current use.
Comment 4 Jesper Moller CLA 2012-09-21 20:42:17 EDT
I'd go further, by allowing "standard" Java values as the context item, supporting string, misc. numeric types, QNames, etc. For that, we'd need an ItemFactory, replacing NodeType.dom_to_xpath, and allow advanced users to override it, e.g. by putting it into the DynamicContext, or perhaps even passed in to the EvaluationContext.

Such an ItemFactory would also help out when adding variables to the DynamicContextBuilder.

Is that too far out?