Re[2]: Nodeset bug and nested setvalue in a repeat. (2 of 2)

Hello All,

XPath context should follow the simple rules:

[*] When XPath inside of group, repeat, (any grouping element) - context is defined according to
  (7.4 Evaluation Context http://www.w3.org/TR/xforms11/#expr-eval)

I am totally _against_ the following, it is very cumbersome and different implementation will have different side effects.
(I refer to line 5)
1      <xf:repeat nodeset="instance('myInstance')/fruit" model="myModel" id="fruits-repeat">
2       <xf:trigger>
3         <xf:label>Pick</xf:label>
4         <xf:action ev:event="DOMActivate">
5           <xf:setvalue ref="instance('myInstance')/bad-fruit" value="context('fruits-repeat')[index('fruits-repeat')]"/>
6         </xf:action>
7       </xf:trigger>
8     </xf:repeat>

On the other hands, following the rule above, it can be written as:
1      <xf:repeat nodeset="instance('myInstance')/fruit" model="myModel" id="fruits-repeat">
2       <xf:output value="current()"/> = <xf:output value="."/>
3       <xf:trigger>
4         <xf:label>Pick</xf:label>
5         <xf:action ev:event="DOMActivate">
6           <xf:setvalue ref="instance('myInstance')/bad-fruit-1" value="current()"/>
7           <xf:setvalue ref="instance('myInstance')/bad-fruit-2" value="."/>
8         </xf:action>
9       </xf:trigger>
10    </xf:repeat>

Line 2 display current value using "current()" function and the same value using XPath "." proving that both XPath
expressions are obey <repeat/> context/scope.
Moving along the code, line 6 and 7 also obey <repeat/> context/scope.
This approach intuitive and understandable by many XML developers, so we will avoid "How to" questions, and reduce
adoption curve.

This approach will have minimum impact on impl. and can be done fast, please correct me if I am wrong.
For instance Orbeon guys will like it because it is follow XSLT rules, so their XSLT server-side preprocessor will
handle this situation with minimal changes.



[*] When XPath outside of any grouping element context is defined according to
  (7.4 Evaluation Context http://www.w3.org/TR/xforms11/#expr-eval)

An example:
1 <xf:output value="current()/fruits/fruit[1]"/> = <xf:output value="/fruits/fruit[1]"/>
2 <xf:output value="/fruits/fruit[1]"/> = <xf:output value="instance('myInstance')/fruits/fruit[1]"/>

3 <xf:setvalue ref="instance('myInstance')/bad-fruit" value="/fruits/fruit[1]"/>
4 <xf:setvalue ref="instance('myInstance')/bad-fruit" value="current()/fruits/fruit[1]"/>
5 <xf:setvalue ref="instance('myInstance')/bad-fruit" value="instance('myInstance')/fruits/fruit[1]"/>

Line 1 prove that current() function honor the default context defined in (7.4 Evaluation Context), assuming that
myInstance is the first instance of my first model.
Line 2 prove that I can choose my context using "instance()" function.
Line 3 prove that <setvalue/> honor the default context defined in (7.4 Evaluation Context) instead of the context
defined in "ref/bind" attributes.
Line 4 prove that function current() honor the default context defined in (7.4 Evaluation Context) instead of the context
defined in "ref/bind" attributes.
Line 5 prove that I can choose my context using "instance()" function.
  
Context rules should be as close as possible to XSLT rules, since we are dynamically processing XML.

As you can see with minimal spec and implementation changes we can achieve great consistency and low adoption curve.

P.S. I still digesting (http://www.w3.org/TR/xforms11/#expr-eval) in my attempt to understand if it need any changes to
achieve what I just explained.

-- 
Best regards,
 Ivan                            mailto:IvanLatysh@yahoo.ca

Received on Friday, 13 April 2007 18:59:59 UTC