Re: The semantics of position() -- trying to be very explicit

/ ht@inf.ed.ac.uk (Henry S. Thompson) was heard to say:
| Phew!  This works, but will _anyone_ understand it?  Can someone
| explain it in simpler terms, supposing you agree it's right in
| principle?

I think I agree with your analysis. As far as simplifying the
explanation, I think you draw an unnecessary distinction between those
expressions evaluated by the engine and those evaluated by the steps.
In my implementation, a p:for-each is just a step like p:xslt or
p:matching-documents.

I think it's sufficient to say something like this:

Each step that accepts a sequence is required to keep track of the
number of documents that it has processed on that sequence. For the
purpose of evaluating an XPath expression, the initial value of the
context position is set to that number. For steps that do not accept a
sequence, the context position is always 1.

The distinction about select vs value falls out of this naturally.
Consider:

  <p:for-each>
    <p:xslt>
      <p:parameter name="iteration" select="position()"/>
      <p:parameter name="unevaluatedxpath" value="position()"/>
      ...
    </p:xslt>
  </p:for-each>

In order to establish the value of the "iteration" parameter passed to
XSLT, the expression has to be evaluated. That evaluation occurs, must
occur, before the XSLT step begins and is therefore clearly done in
the context of the p:for-each (although we probably need to clarify
this a bit in the spec, it's true of all options and parameters
irrespective of whether they contain a call to position()).

In the context of the p:for-each, the context position is the
iteration count. So, that XSLT step sees iteration=1,2,3,... etc.

The value of the unevaluatedxpath parameter is simply the string
"position()". This is entirely equivalent to select="'position()'"
modulo any issues about single and double quotes in the value.

One thing that struck me in reading your message was that you said:

  I find it easiest to think of this in terms of position having a
  sort-of special slot in the environment.

In fact, the special slot is in the XPath context and we renamed the
bag of state that we're carring around from "context" to "environment"
precisely so that it wouldn't introduce confusion when we had to talk
about setting up the XPath context :-)

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@nwalsh.com> | Doubt is to certainty as neurosis is to
http://nwalsh.com/            | psychosis. The neurotic is in doubt and
                              | has fears about persons and things; the
                              | psychotic has convictions and makes
                              | claims about them. In short, the
                              | neurotic has problems, the psychotic
                              | has solutions.--Thomas Szasz

Received on Thursday, 7 June 2007 12:32:55 UTC