Rewrite of Evaluation Context

So after two rewrites, I have a version that I am reasonably happy with.  
Please check this wording for errors or missing text. There is also one  
question about a sentence that I don't think is necessary.

Original text here:  
https://www.w3.org/community/xformsusers/wiki/XForms_2.0#Expressions

Steven

Expressions

Expressions appear in attributes throughout XForms. They can be split into  
two types: bindings, that identify locations whose content may or may not  
be changed by the attached element; and value expressions, that supply  
values for use by the attached element.

They can further be classified depending on when they are evaluated:
* on bind elements (where bindings are called model item bindings);  
evaluated during initialization and recalculate;
* on controls (where bindings are called UI bindings); evaluated during  
initialization and refresh;
* on Actions and the submission element, evaluated on activation by an  
event;
* in Attribute Value Templates (AVTs), evaluated whenever the containing  
element is processed.

Note: To allow for forward compatibility, this specification is written to  
permit the use of different expression languages. However only one is used  
in XForms 2.0, XPath 2.0 as defined in XForms 2.0: XPath Expressions  
Module.

Evaluation context

All expressions are evaluated in an evaluation context, which consists of  
a context item, a size, and a position. In general, the context item is  
some element of a sequence, the size is the size of that sequence, and the  
position is the position of the context item within the sequence.

An element inherits an evaluation context from its ancestor elements. If  
the element has a model attribute, and the inherited context item is not  
 from that model, then the default context from the referenced model is  
used instead. If the element has a context attribute, it is evaluated in  
the resulting context. The final context is called the in-scope evaluation  
context.

If an element has a ref attribute, it is evaluated in the in-scope  
context. If the element has a bind attribute, the bind element referenced  
has its own context. The result of the ref or bind evaluation gives the  
element evaluation context. If the ref or bind binding is declared as a  
Single Item Binding, the size of the context is set to 1; otherwise it is  
a Sequence Binding, and has a size of the size of the evaluated sequence  
and an occurrence of the original binding element is also generated for  
each of the items in the sequence, with a dynamic evaluation context that  
has a context item of the item of the sequence for which the occurrence  
was generated, a size of the size of the sequence, and a position of the  
position of the generated item in the sequence.

Unless otherwise stated, all expressions in attributes on an element are  
evaluated in the element evaluation context.

The element evaluation context is then inherited by any contained elements.

For top-level elements, that have no ancestors, the inherited evaluation  
context is the default context item of the element's default model, with a  
size and position of one.

The default model for an element is its containing model, if any, and  
otherwise the textually first model in the document.

The default context item of a model is the top-level document element node  
of the textually first instance of the model.

If a binding evaluates to an empty sequence, any contained bindings are  
not evaluated. [DO WE NEED THIS? What would stop working if we left this  
line out? Original wording: The binding of a non-outermost binding element  
is not evaluated if the in-scope evaluation context does not contain a  
context item. This can occur if the binding of the nearest ancestor bound  
element produces the empty sequence.]

At the time of evaluation, an expression must be syntactically correct,  
the namespaces it uses must be in scope, and the functions and variables  
it uses must be defined; otherwise one of the events xforms-binding-error,  
for a bind element, xforms-action-error for an Action, and  
xforms-expression-error otherwise, is dispatched.

Note: the context() function returns the context item of an element's  
in-scope evaluation context, while the position() and last() functions  
return the context position and size respectively of the element context.

So
   <instance>
      <data xmlns="">
         <a><b>1</b</a>
         <b>2</b>
      </data>
   </instance>
   ...
   <output ref="a" value="b"/>
   <output ref="a" value="context()/b"/>

would output 1 2.

Received on Friday, 16 December 2016 10:09:27 UTC