W3C home > Mailing lists > Public > public-xformsusers@w3.org > January 2017

Re: Evaluation context

From: Erik Bruchez <ebruchez@orbeon.com>
Date: Tue, 17 Jan 2017 16:50:00 -0800
Message-ID: <CAAc0PEW6b1zBuuSWvUzQd6jZbjMWTbt-7AnRZ6uJdJixO3Q3jg@mail.gmail.com>
To: Steven Pemberton <steven.pemberton@cwi.nl>
Cc: XForms <public-xformsusers@w3.org>
All,

I gave this a little bit of thought.

In XPath, there are precedents for how the focus evolves in subexpressions:
[1]

> Certain language constructs, notably the path operator E1/E2, the simple
map operator E1!E2 , and the predicate E1[E2], create a new focus for the
evaluation of a sub-expression. In these constructs, E2 is evaluated once
for each item in the sequence that results from evaluating E1. Each time E2
is evaluated, it is evaluated with a different focus. The focus for
evaluating E2 is referred to below as the inner focus, while the focus for
evaluating E1 is referred to as the outer focus. The inner focus is used
only for the evaluation of E2. Evaluation of E1 continues with its original
focus unchanged.

We have something similar in XSLT: [2]

    <xsl:for-each select="E1">
      ... evaluation of E2 has size determined by size of E1 and position
incrementing over items returned by E1  ...

where:

> - The context item is the item being processed. If this is a node, it
will also be the context node. If it is not a node, there will be no
context node: that is, any attempt to reference the context node will
result in a non-recoverable dynamic error.
> - The context position is the position of this item in the sorted
sequence.
> - The context size is the size of the sorted sequence (which is the same
as the size of the input sequence)."

It would be nice in XForms if we had the same:

    <xf:repeat ref="E1">
      ... evaluation of E2 using `size(), `position()`, and `last()` works
...

However, the question is: what should happen with:

    <xf:repeat ref="E1">
      <xf:group ref="E2">
        ... evaluation of E3 ...

My understanding would be that E2 works like a subexpression. This means
that it would reset the focus to a single item, size 1, and position 1.

Doing otherwise is a bit weird. Say you have:

    <xf:repeat ref="a">
      <xf:group ref="instance()">
        ... evaluation of E3 with context item and size/position out of
sync ...

The same would go for:

    <xf:group context="E2">

Now for the implicit group of `xf:repeat`, we could have language as in
XSLT, where we are explicit that because there is repetition, the implicit
group sets a new context item for each iteration, but also preserves the
size/position of the repeat.

Something similar would happen with `xf:bind`.

This is how we implemented it, by the way.

-Erik

[1] https://www.w3.org/TR/xpath-31/#eval_context
[2] https://www.w3.org/TR/xslt20/#element-for-each

On Thu, Dec 22, 2016 at 1:09 AM, Steven Pemberton <steven.pemberton@cwi.nl>
wrote:

> On Wed, 21 Dec 2016 20:31:03 +0100, Erik Bruchez <ebruchez@orbeon.com>
> wrote:
>
> When there is a single-node binding, the context item always has a size of
>> 1 (or may be missing). This is a bit tricky. What does this do:
>>
>> <xf:repeat ref="1 to 10">
>>   <xf:output value="position"/>
>> </xf:repeat>
>>
>> vs.
>>
>> <xf:repeat ref="1 to 10">
>>   <xf:group ref=".">
>>     <xf:output value="position"/>
>>   </group>
>> </xf:repeat>
>>
>>
>> They both do the same thing, since a repeat object is a single item
>> binding:
>>
>> "a repeat object consisting of an implicitly generated group element that
>> binds to the item, and containing a copy of the template."
>>
>> I thought about this, and I can think of no place except for bind where a
>> sequence binding is nested directly within a sequence binding.
>>
>
> They do the same thing as far as the binding item proper, but what about
> the XPath context position and size? For sequence bindings, we now say:
>
>     "a size of the size of the sequence, and a position of the position of
> the generated item in the sequence"
>
> So should I expect `position()` to work (as in showing "1", "2", etc.)
> here:
>
> <xf:repeat ref="1 to 10">
>   <xf:output value="position()"/>
> </xf:repeat>
>
> And in the second case, does the single-item binding (in addition to the
> implicit group of the repeat) reset the position() and last()?
>
> <xf:repeat ref="1 to 10">
>   <xf:group ref=".">
>     <xf:output value="position()"/>
>   </group>
> </xf:repeat>
>
> In other words, are position() and last() inherited when there is no
> sequence-binding?
>
> In our implementation, I think that single-item bindings reset to position
> = 1 and size = 1.
>
>
> I would say that only the size should be reset, not the position, in both
> cases, but I am happy to hear a counter-argument.
>
> Steven
>
>
> -Erik
>
>
>
>
>
Received on Wednesday, 18 January 2017 00:50:53 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 18 January 2017 00:50:54 UTC